diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/camera-sensor.cpp | 3 | ||||
-rw-r--r-- | test/meson.build | 1 | ||||
-rw-r--r-- | test/utils.cpp | 53 |
3 files changed, 56 insertions, 1 deletions
diff --git a/test/camera-sensor.cpp b/test/camera-sensor.cpp index 9fe59cc9..27c190fe 100644 --- a/test/camera-sensor.cpp +++ b/test/camera-sensor.cpp @@ -13,6 +13,7 @@ #include "camera_sensor.h" #include "device_enumerator.h" #include "media_device.h" +#include "utils.h" #include "v4l2_subdevice.h" #include "test.h" @@ -91,7 +92,7 @@ protected: if (format.mbus_code != MEDIA_BUS_FMT_SBGGR10_1X10 || format.size != Size(4096, 2160)) { cerr << "Failed to get a suitable format, expected 4096x2160-0x" - << std::hex << MEDIA_BUS_FMT_SBGGR10_1X10 + << utils::hex(MEDIA_BUS_FMT_SBGGR10_1X10) << ", got " << format.toString() << endl; return TestFail; } diff --git a/test/meson.build b/test/meson.build index 84722cce..cf5eb84d 100644 --- a/test/meson.build +++ b/test/meson.build @@ -30,6 +30,7 @@ internal_tests = [ ['threads', 'threads.cpp'], ['timer', 'timer.cpp'], ['timer-thread', 'timer-thread.cpp'], + ['utils', 'utils.cpp'], ] foreach t : public_tests diff --git a/test/utils.cpp b/test/utils.cpp new file mode 100644 index 00000000..9fe0d477 --- /dev/null +++ b/test/utils.cpp @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2018, Google Inc. + * + * utils.cpp - Miscellaneous utility tests + */ + +#include <iostream> +#include <sstream> + +#include "test.h" +#include "utils.h" + +using namespace std; +using namespace libcamera; + +class UtilsTest : public Test +{ +protected: + int run() + { + std::ostringstream os; + std::string ref; + + os << utils::hex(static_cast<int32_t>(0x42)) << " "; + ref += "0x00000042 "; + os << utils::hex(static_cast<uint32_t>(0x42)) << " "; + ref += "0x00000042 "; + os << utils::hex(static_cast<int64_t>(0x42)) << " "; + ref += "0x0000000000000042 "; + os << utils::hex(static_cast<uint64_t>(0x42)) << " "; + ref += "0x0000000000000042 "; + os << utils::hex(static_cast<int32_t>(0x42), 4) << " "; + ref += "0x0042 "; + os << utils::hex(static_cast<uint32_t>(0x42), 1) << " "; + ref += "0x42 "; + os << utils::hex(static_cast<int64_t>(0x42), 4) << " "; + ref += "0x0042 "; + os << utils::hex(static_cast<uint64_t>(0x42), 1) << " "; + ref += "0x42 "; + + std::string s = os.str(); + if (s != ref) { + cerr << "utils::hex() test failed, expected '" << ref + << "', got '" << s << "'"; + return TestFail; + } + + return TestPass; + } +}; + +TEST_REGISTER(UtilsTest) |