From 90906ba7fb95490abefa9bcbea812b4e2ff8dbdc Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 30 Jul 2022 16:09:50 +0300 Subject: test: yaml-parser: Test YamlObject::get(const T &defaultValue) When the YamlObject::get() function override that returns a std::optional got introduced, all tests were moved to it, leaving no tests for the override that takes a default value. Reintroduce those tests. Reported-by: Florian Sylvestre Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Kieran Bingham --- test/yaml-parser.cpp | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp index 9fd27866..93ba88b8 100644 --- a/test/yaml-parser.cpp +++ b/test/yaml-parser.cpp @@ -160,7 +160,8 @@ protected: return TestFail; } - if (strObj.get().value_or("") != "libcamera") { + if (strObj.get().value_or("") != "libcamera" || + strObj.get("") != "libcamera") { cerr << "String object parse as wrong content" << std::endl; return TestFail; } @@ -198,17 +199,20 @@ protected: return TestFail; } - if (int32Obj.get().value_or(0) != -100) { + if (int32Obj.get().value_or(0) != -100 || + int32Obj.get(0) != -100) { cerr << "Integer object parse as wrong value" << std::endl; return TestFail; } - if (int32Obj.get().value_or("") != "-100") { + if (int32Obj.get().value_or("") != "-100" || + int32Obj.get("") != "-100") { cerr << "Integer object fail to parse as string" << std::endl; return TestFail; } - if (int32Obj.get().value_or(0.0) != -100.0) { + if (int32Obj.get().value_or(0.0) != -100.0 || + int32Obj.get(0.0) != -100.0) { cerr << "Integer object fail to parse as double" << std::endl; return TestFail; } @@ -236,22 +240,26 @@ protected: return TestFail; } - if (uint32Obj.get().value_or(0) != 100) { + if (uint32Obj.get().value_or(0) != 100 || + uint32Obj.get(0) != 100) { cerr << "Unsigned integer object fail to parse as integer" << std::endl; return TestFail; } - if (uint32Obj.get().value_or("") != "100") { + if (uint32Obj.get().value_or("") != "100" || + uint32Obj.get("") != "100") { cerr << "Unsigned integer object fail to parse as string" << std::endl; return TestFail; } - if (uint32Obj.get().value_or(0.0) != 100.0) { + if (uint32Obj.get().value_or(0.0) != 100.0 || + uint32Obj.get(0.0) != 100.0) { cerr << "Unsigned integer object fail to parse as double" << std::endl; return TestFail; } - if (uint32Obj.get().value_or(0) != 100) { + if (uint32Obj.get().value_or(0) != 100 || + uint32Obj.get(0) != 100) { cerr << "Unsigned integer object parsed as wrong value" << std::endl; return TestFail; } @@ -274,12 +282,14 @@ protected: return TestFail; } - if (doubleObj.get().value_or("") != "3.14159") { + if (doubleObj.get().value_or("") != "3.14159" || + doubleObj.get("") != "3.14159") { cerr << "Double object fail to parse as string" << std::endl; return TestFail; } - if (doubleObj.get().value_or(0.0) != 3.14159) { + if (doubleObj.get().value_or(0.0) != 3.14159 || + doubleObj.get(0.0) != 3.14159) { cerr << "Double object parse as wrong value" << std::endl; return TestFail; } @@ -332,7 +342,8 @@ protected: return TestFail; } - if (sizeObj.get().value_or(Size(0, 0)) != Size(1920, 1080)) { + if (sizeObj.get().value_or(Size(0, 0)) != Size(1920, 1080) || + sizeObj.get(Size(0, 0)) != Size(1920, 1080)) { cerr << "Size object parse as wrong value" << std::endl; return TestFail; } -- cgit v1.2.1