Check json has the mandatory keys 01/242201/3
authorIlho Kim <ilho159.kim@samsung.com>
Mon, 24 Aug 2020 05:42:30 +0000 (14:42 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Tue, 25 Aug 2020 03:10:28 +0000 (12:10 +0900)
- Mandatory keys : version,tool_version,title,description,resolution,preview

Change-Id: I1a2f9655150d74f8f172ade0ffc44588b45895ec

18 files changed:
src/theme_plugin/theme_info_builder.cc
src/theme_plugin/theme_info_builder.h
src/theme_plugin/theme_parser.cc
test/unit_tests/test_samples/test_deep_depth_array_N.json
test/unit_tests/test_samples/test_deep_depth_array_P.json
test/unit_tests/test_samples/test_deep_depth_key_N.json
test/unit_tests/test_samples/test_deep_depth_key_P.json
test/unit_tests/test_samples/test_different_array_element_type.json
test/unit_tests/test_samples/test_empty_array.json
test/unit_tests/test_samples/test_invalid_json.json
test/unit_tests/test_samples/test_long_length_key_N.json
test/unit_tests/test_samples/test_long_length_key_P.json
test/unit_tests/test_samples/test_long_length_value_N.json
test/unit_tests/test_samples/test_long_length_value_N2.json
test/unit_tests/test_samples/test_long_length_value_P.json
test/unit_tests/test_samples/test_multidimensional_array.json
test/unit_tests/test_samples/test_theme.json
test/unit_tests/test_theme_parser.cc

index 0678ab0403df9e173340c955ee6b36731add6935..815e5bc431eb6939135d6ce0622e13459faacab3 100644 (file)
@@ -55,5 +55,32 @@ void ThemeInfoBuilder::GenerateFileKey(const std::string& root) {
   }
 }
 
+bool ThemeInfoBuilder::KeysExist(const std::vector<std::string>& keys) {
+  for (const std::string& key : keys) {
+    switch (bundle_.GetType(key)) {
+      case bundle_type::BUNDLE_TYPE_NONE:
+        LOG(ERROR) << "Key [" << key << "] is not exists";
+        return false;
+      case bundle_type::BUNDLE_TYPE_STR:
+        if (bundle_.GetString(key).empty()) {
+          LOG(ERROR) << "The value of key [" << key << "] can not be empty";
+          return false;
+        }
+        break;
+      case bundle_type::BUNDLE_TYPE_STR_ARRAY:
+        if (bundle_.GetStringArray(key).empty()) {
+          LOG(ERROR) << "The value of key [" << key << "] can not be empty";
+          return false;
+        }
+        break;
+      default:
+        LOG(ERROR) << "This key [" << key << "] is invalid type";
+        return false;
+    }
+  }
+
+  return true;
+}
+
 }  // namespace plugin
 }  // namespace ttm
index bb99bb16adc4cbfab6a14960682a91731a3752a1..be2866cf62c26a5daf151664d0572d6a670c16b5 100644 (file)
@@ -25,6 +25,7 @@ class ThemeInfoBuilder {
   loader::ThemeInfo Build();
   void GenerateFileKey(const std::string& root);
   void GenerateFileKeyWithoutExtension();
+  bool KeysExist(const std::vector<std::string>& keys);
 
  private:
   tizen_base::Bundle bundle_;
index c7c5b15dfea906675087a65ef7caefd63c8be774..f76b6591184506d26870414a1e07fe0f84d7ed22 100644 (file)
@@ -22,6 +22,14 @@ namespace {
 const int kJsonDepthLimit = 50;
 const int kKeyLengthLimit = 128;
 const int kValueLengthLimit = 1024;
+const std::vector<std::string> kMandatoryKeys = {
+  "/version",
+  "/tool_version",
+  "/title",
+  "/description",
+  "/resolution",
+  "/preview"
+};
 
 std::string GetFileKeyRootPath(const char* pkgid) {
   pkgmgrinfo_pkginfo_h handle;
@@ -176,6 +184,11 @@ loader::ThemeInfo ThemeParser::Inflate(const std::string id,
     return {};
   }
 
+  if (!builder.KeysExist(kMandatoryKeys)) {
+    LOG(ERROR) << "Mandatory key is missed";
+    return {};
+  }
+
   if (auto_file_key_gen_)
     builder.GenerateFileKey(GetFileKeyRootPath(pkgid.c_str()));
 
index 07a681dfeb6552569c7c37bd41eeaf3f79919991..05d2faa2c86e9a594410c58bb920a1b282dafb5c 100644 (file)
@@ -1,4 +1,10 @@
 {
+        "version" : "1.0.0",
+        "tool_version" : "1.0.0",
+        "title" : "test_title",
+        "description" : "test_description",
+        "resolution" : "720x1280",
+        "preview" : "preview.png",
         "50D_array" :
         [
                 [
index 70621dc3d85ee88496ed1fcdd21e91feced7e8ef..9e6c3a049cc5274f0d8babe55b05d373c8e5b5cb 100644 (file)
@@ -1,4 +1,10 @@
 {
+        "version" : "1.0.0",
+        "tool_version" : "1.0.0",
+        "title" : "test_title",
+        "description" : "test_description",
+        "resolution" : "720x1280",
+        "preview" : "preview.png",
         "50D_array" :
         [
                 [
index bf4f76f04d0d5823c21ff632ca1aa7ba489c0792..1f66ea3a775de56ce2279faeacd55bd1bd08cafb 100644 (file)
@@ -1,4 +1,10 @@
 {
+        "version" : "1.0.0",
+        "tool_version" : "1.0.0",
+        "title" : "test_title",
+        "description" : "test_description",
+        "resolution" : "720x1280",
+        "preview" : "preview.png",
         "1st" : {
                 "2st" : {
                         "3st" : {
index da0c9d2621a7cfb8a0d1832aca0de4d2d2ff23cb..b2ab105c6360c4dc9575a186740a2ecfc8783193 100644 (file)
@@ -1,4 +1,10 @@
 {
+        "version" : "1.0.0",
+        "tool_version" : "1.0.0",
+        "title" : "test_title",
+        "description" : "test_description",
+        "resolution" : "720x1280",
+        "preview" : "preview.png",
         "1st" : {
                 "2st" : {
                         "3st" : {
index e04fe290128402e312c8ff3deeb566cd0d5583ee..179e9e7461fbb33fb6846e0629c553a7921e5f5a 100644 (file)
@@ -1,4 +1,10 @@
 {
+        "version" : "1.0.0",
+        "tool_version" : "1.0.0",
+        "title" : "test_title",
+        "description" : "test_description",
+        "resolution" : "720x1280",
+        "preview" : "preview.png",
         "array" : [
                 null,
                 "a",
index b503cc69309457ae9e29e0afb0e9a926c48cfd31..e331dfcc3adfe685627ab87e718085fbae88e2fe 100644 (file)
@@ -1,4 +1,10 @@
 {
+        "version" : "1.0.0",
+        "tool_version" : "1.0.0",
+        "title" : "test_title",
+        "description" : "test_description",
+        "resolution" : "720x1280",
+        "preview" : "preview.png",
         "array" : [
         ]
 }
index 421be1918d1d1d88ecaa845fcd99b0ce9dbea023..4e83510e0b7cd78f4a10db376671e21f741a292d 100644 (file)
@@ -1,3 +1,9 @@
 {
+        "version" : "1.0.0",
+        "tool_version" : "1.0.0",
+        "title" : "test_title",
+        "description" : "test_description",
+        "resolution" : "720x1280",
+        "preview" : "preview.png",
         "invalid"
 }
index 8310bc5c0390b2a88a93230cb84712cf01c85de9..8363d494f330c24ed5ade55c1d33a6b97a86628d 100644 (file)
@@ -1,3 +1,9 @@
 {
+        "version" : "1.0.0",
+        "tool_version" : "1.0.0",
+        "title" : "test_title",
+        "description" : "test_description",
+        "resolution" : "720x1280",
+        "preview" : "preview.png",
         "128_length_key__________________________________________________________________________________________________________________" : "invalid"
 }
index 868d15c5ecbb35a6fb85cd3ed69dcf5187cbe844..4d82ad9aabf01eac341da37112bb893460679d8e 100644 (file)
@@ -1,3 +1,9 @@
 {
+        "version" : "1.0.0",
+        "tool_version" : "1.0.0",
+        "title" : "test_title",
+        "description" : "test_description",
+        "resolution" : "720x1280",
+        "preview" : "preview.png",
         "127_length_key_________________________________________________________________________________________________________________" : "valid"
 }
index 505af6fe1e6c143680f35c51ffaf62af2e2224c6..6b533225dc7b8f10301f9fdb4a206f9d2a30a248 100644 (file)
@@ -1,3 +1,9 @@
 {
+        "version" : "1.0.0",
+        "tool_version" : "1.0.0",
+        "title" : "test_title",
+        "description" : "test_description",
+        "resolution" : "720x1280",
+        "preview" : "preview.png",
         "valid_length_value" : "................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................"
 }
index 9ca0e973df6f0c6c886f4132d3e777d253d316bd..8c1b79b1a2a0ca6f555b3a76fd5fd29c4628edc4 100644 (file)
@@ -1,4 +1,10 @@
 {
+        "version" : "1.0.0",
+        "tool_version" : "1.0.0",
+        "title" : "test_title",
+        "description" : "test_description",
+        "resolution" : "720x1280",
+        "preview" : "preview.png",
         "valid_length_value" : [
                 "................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................"
         ]
index 957392f5868124f222e0cc9f3cabd13b6d3a1753..af4ce2369fa2666bd2af53514a8988287c016091 100644 (file)
@@ -1,3 +1,9 @@
 {
+        "version" : "1.0.0",
+        "tool_version" : "1.0.0",
+        "title" : "test_title",
+        "description" : "test_description",
+        "resolution" : "720x1280",
+        "preview" : "preview.png",
         "valid_length_value" : "..............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................."
 }
index f892150d057c6fe2edc29e4a8d11e0c43c4e4dc7..623ced63c6cfb9a945ad790ef21b245ce8177ffb 100644 (file)
@@ -1,4 +1,10 @@
 {
+        "version" : "1.0.0",
+        "tool_version" : "1.0.0",
+        "title" : "test_title",
+        "description" : "test_description",
+        "resolution" : "720x1280",
+        "preview" : "preview.png",
         "1D_array" : ["1", "2", "3"],
         "2D_array" : [
                 ["1", "2", "3"],
index 28f516d9f0ae958b755afbcc72b6114e4e0658a2..48d783a45b151b9ebe23f82630756284ad3ff86b 100644 (file)
@@ -3,16 +3,12 @@
         "tool_version": "1.00.38.820793",
         "title": "GOGO Theme",
         "description": "Example for theme spec",
+        "resolution": "720x1280",
+        "preview": "GOGO_Preview.png",
         "header": {
-                "profile": "wearable",
-                "resolutions": [
-                        "720x1280"
-                ]
+                "profile": "wearable"
         },
         "theme": {
-                "preview": [
-                        "GOGO_Preview.png"
-                ],
                 "watchface": {
                         "id": "org.tizen.gogowatch",
                         "url": "https://www.download.gogowatch/get"
index 6030d07e13beaeb866cac3598bf09431cbd6c943..6f8b6a62f8c8d0bb2e973cb5b86d23778e6342cf 100644 (file)
@@ -59,6 +59,7 @@ TEST_F(ThemeParserTest, Inflate) {
   EXPECT_EQ(info.GetVersion(), "1.0.0");
   EXPECT_EQ(info.GetToolVersion(), "1.00.38.820793");
   EXPECT_EQ(info.GetTitle(), "GOGO Theme");
+  EXPECT_EQ(info.GetPreview(), "GOGO_Preview.png");
   EXPECT_EQ(info.GetDescription(), "Example for theme spec");
   EXPECT_EQ(info.GetString("/header/profile"), "wearable");
   EXPECT_EQ(info.GetString("/theme/home/app_tray"), "tray.png");
@@ -78,8 +79,6 @@ TEST_F(ThemeParserTest, Inflate) {
   EXPECT_EQ(info.GetString("/theme/watchface/id"), "org.tizen.gogowatch");
   EXPECT_EQ(info.GetString("/theme/watchface/url"),
       "https://www.download.gogowatch/get");
-  EXPECT_EQ(info.GetStringArray("/theme/preview"),
-      std::vector<std::string>({"GOGO_Preview.png"}));
   EXPECT_EQ(info.GetString("/theme/files/theme_resources"),
       "shared/res/theme_resources");
   EXPECT_EQ(info.GetString("/object_array/0/key_A"), "A");