summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/utils.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/utils.cpp b/test/utils.cpp
index 7e24c71e..f170ae4c 100644
--- a/test/utils.cpp
+++ b/test/utils.cpp
@@ -20,6 +20,7 @@
using namespace std;
using namespace libcamera;
+using namespace std::literals::chrono_literals;
class UtilsTest : public Test
{
@@ -128,6 +129,46 @@ protected:
return TestPass;
}
+ int testDuration()
+ {
+ std::ostringstream os;
+ utils::Duration exposure;
+ double ratio;
+
+ exposure = 25ms + 25ms;
+ if (exposure.get<std::micro>() != 50000.0) {
+ cerr << "utils::Duration failed to return microsecond count";
+ return TestFail;
+ }
+
+ exposure = 1.0s / 4;
+ if (exposure != 250ms) {
+ cerr << "utils::Duration failed scalar divide test";
+ return TestFail;
+ }
+
+ exposure = 5000.5us;
+ if (!exposure) {
+ cerr << "utils::Duration failed boolean test";
+ return TestFail;
+ }
+
+ os << exposure;
+ if (os.str() != "5000.50us") {
+ cerr << "utils::Duration operator << failed";
+ return TestFail;
+ }
+
+ exposure = 100ms;
+ ratio = exposure / 25ms;
+ if (ratio != 4.0) {
+ cerr << "utils::Duration failed ratio test";
+ return TestFail;
+ }
+
+ return TestPass;
+ }
+
int run()
{
/* utils::hex() test. */
@@ -236,6 +277,10 @@ protected:
if (testEnumerate() != TestPass)
return TestFail;
+ /* utils::Duration test. */
+ if (testDuration() != TestPass)
+ return TestFail;
+
return TestPass;
}
};