[libcamera-devel,v7,02/14] test: yaml-parser: Test dictionary items ordering
diff mbox series

Message ID 20220727023816.30008-3-laurent.pinchart@ideasonboard.com
State Accepted
Headers show
Series
  • Replace boost JSON parser with libyaml in Raspberry Pi IPA
Related show

Commit Message

Laurent Pinchart July 27, 2022, 2:38 a.m. UTC
While YAML specifies that mappings are unordered, the Raspberry Pi IPA
relies on elements being ordered as in the YAML data. To replace the
dependency on boost with the YamlParser class, we thus need to guarantee
that the order is preserved. Update the corresponding unit test to
ensure this. The test currently fails at the YamlParser doesn't
correctly preserve the order, this will be fixed by the next commit.

This commit should be reverted when the Raspberry Pi IPA updates to a
new tuning data format and drops support for the old format.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
Tested-by: Naushir Patuck <naush@raspberrypi.com>
---
 test/yaml-parser.cpp | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

Patch
diff mbox series

diff --git a/test/yaml-parser.cpp b/test/yaml-parser.cpp
index ebb654f2ef9c..782331764346 100644
--- a/test/yaml-parser.cpp
+++ b/test/yaml-parser.cpp
@@ -32,8 +32,8 @@  static const string testYaml =
 	"  - Mary\n"
 	"dictionary:\n"
 	"  a: 1\n"
-	"  b: 2\n"
 	"  c: 3\n"
+	"  b: 2\n"
 	"level1:\n"
 	"  level2:\n"
 	"    - [1, 2]\n"
@@ -448,10 +448,10 @@  protected:
 			return TestFail;
 		}
 
-		std::map<std::string, int> dictValues{ {
+		static constexpr std::array<std::pair<const char *, int>, 3> dictValues{ {
 			{ "a", 1 },
-			{ "b", 2 },
 			{ "c", 3 },
+			{ "b", 2 },
 		} };
 
 		size_t dictSize = dictValues.size();
@@ -469,8 +469,8 @@  protected:
 				return TestFail;
 			}
 
-			const auto item = dictValues.find(key);
-			if (item == dictValues.end()) {
+			const auto &item = dictValues[i];
+			if (item.first != key) {
 				std::cerr << "Dictionary key " << i << " has wrong value"
 					  << std::endl;
 				return TestFail;
@@ -482,17 +482,12 @@  protected:
 				return TestFail;
 			}
 
-			if (elem.get<int32_t>(0) != item->second) {
+			if (elem.get<int32_t>(0) != item.second) {
 				std::cerr << "Dictionary element " << i << " has wrong value"
 					  << std::endl;
 				return TestFail;
 			}
 
-			/*
-			 * Erase the item to make sure that each iteration
-			 * produces a different value.
-			 */
-			dictValues.erase(item);
 			i++;
 		}