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 0678ab0..815e5bc 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 bb99bb1..be2866c 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 c7c5b15..f76b659 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 07a681d..05d2faa 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 70621dc..9e6c3a0 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 bf4f76f..1f66ea3 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 da0c9d2..b2ab105 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 e04fe29..179e9e7 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 b503cc6..e331dfc 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 421be19..4e83510 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 8310bc5..8363d49 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 868d15c..4d82ad9 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 505af6f..6b53322 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 9ca0e97..8c1b79b 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 957392f..af4ce23 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 f892150..623ced6 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 28f516d..48d783a 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 6030d07..6f8b6a6 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");