app/layers: move embedded test run to layers
authorMarcus Fritzsch <marcus_fritzsch@mentor.com>
Fri, 28 Jul 2017 07:57:24 +0000 (09:57 +0200)
committerMarcus Fritzsch <marcus_fritzsch@mentor.com>
Tue, 8 Aug 2017 15:24:00 +0000 (17:24 +0200)
Signed-off-by: Marcus Fritzsch <marcus_fritzsch@mentor.com>
src/app.cpp
src/layers.cpp

index 871222f..29f84f7 100644 (file)
@@ -79,28 +79,7 @@ struct result<surface_id_to_layer_map>
    std::ifstream i(filename);
    i >> jids;
 
-   auto m = to_surface_id_to_layer_map(jids["mappings"]);
-
-   if (m.is_ok()) {
-      auto i = m.unwrap();
-
-      auto jtests = jids.value("tests", json());
-
-      std::vector<std::pair<int, int>> tests;
-      std::transform(std::cbegin(jtests), std::cend(jtests),
-                     std::back_inserter(tests), [](json const &j) {
-                        return std::make_pair(get<int>(j["surface_id"]),
-                                              get<int>(j["expect_layer_id"]));
-                     });
-
-      for (auto sid : tests) {
-         if (i.get_layer_for_surface(sid.first).value_or(-1) != sid.second) {
-            return Err<surface_id_to_layer_map>("ID Map embedded test failed!");
-         }
-      }
-   }
-
-   return m;
+   return to_surface_id_to_layer_map(jids);
 }
 
 }  // namespace
index d3ec7cf..f475556 100644 (file)
@@ -10,6 +10,8 @@
 
 namespace wm {
 
+using json = nlohmann::json;
+
 surface_id_to_layer::surface_id_to_layer(nlohmann::json const &j) {
    // DB(j);
    if (j["type"] == "range") {
@@ -27,8 +29,9 @@ struct result<struct surface_id_to_layer_map> to_surface_id_to_layer_map(
    DB(j);
    try {
       surface_id_to_layer_map stl{};
+      auto m = j["mappings"];
       std::transform(
-         std::cbegin(j), std::cend(j),
+         std::cbegin(m), std::cend(m),
          std::inserter(stl.mapping, stl.mapping.end()),
          [](nlohmann::json const &j) { return surface_id_to_layer(j); });
       for (auto i : stl.mapping) {
@@ -41,6 +44,31 @@ struct result<struct surface_id_to_layer_map> to_surface_id_to_layer_map(
                "Found invalid/unset IDs in mapping");
          }
       }
+
+      // Check lookup
+      auto jtests = j.value("tests", json());
+
+      if (! jtests.empty()) {
+         DB("Embedded tests...");
+         std::vector<std::pair<int, int>> tests;
+         tests.reserve(jtests.size());
+         std::transform(std::cbegin(jtests), std::cend(jtests),
+                        std::back_inserter(tests), [](json const &j) {
+                    return std::make_pair(get<int>(j["surface_id"]),
+                                          get<int>(j["expect_layer_id"]));
+                 });
+
+         for (auto sid : tests) {
+            int lid = stl.get_layer_for_surface(sid.first).value_or(-1);
+            DB("this=" << sid.first << ", that=" << lid
+                       << ", expect=" << sid.second);
+            if (lid != sid.second) {
+               return Err<surface_id_to_layer_map>(
+                       "ID Map embedded test failed!");
+            }
+         }
+      }
+
       return Ok(stl);
    } catch (std::exception &e) {
       return Err<struct surface_id_to_layer_map>(e.what());