Add negative unit test 27/243827/7
authorIlho Kim <ilho159.kim@samsung.com>
Thu, 10 Sep 2020 10:00:49 +0000 (19:00 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Fri, 11 Sep 2020 06:28:33 +0000 (15:28 +0900)
Change-Id: I1440ee5773b2872365c9d4a934e1c6344a1b941a
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
test/unit_tests/mock/gio_mock.cc
test/unit_tests/mock/gio_mock.h
test/unit_tests/test_request_broker.cc
test/unit_tests/test_request_handlers.cc
test/unit_tests/test_samples/test_missed_mandatory_key.json [new file with mode: 0644]
test/unit_tests/test_theme.cc
test/unit_tests/test_theme_loader.cc
test/unit_tests/test_theme_parser.cc

index e242d4f..0879f4b 100644 (file)
@@ -102,3 +102,7 @@ extern "C" GDBusMessageType g_dbus_message_get_message_type(
     GDBusMessage* arg1) {
   return MOCK_HOOK_P1(GioMock, g_dbus_message_get_message_type, arg1);
 }
+
+extern "C" int g_dbus_message_to_gerror(GDBusMessage* arg0, GError** arg1) {
+  return MOCK_HOOK_P2(GioMock, g_dbus_message_to_gerror, arg0, arg1);
+}
index 4175e06..42b490e 100755 (executable)
@@ -65,6 +65,9 @@ class GioMock : public virtual ModuleMock {
 
   MOCK_METHOD1(g_dbus_message_get_message_type,
       GDBusMessageType(GDBusMessage*));
+
+  MOCK_METHOD2(g_dbus_message_to_gerror,
+      gboolean(GDBusMessage*, GError**));
 };
 
 #endif  // TEST_UNIT_TESTS_MOCK_GIO_MOCK_H_
index 5e58780..8dd154e 100644 (file)
@@ -35,9 +35,9 @@ using ::testing::SetArgPointee;
 using ::testing::Invoke;
 
 static guint __g_dbus_connection_register_object_fake(
-    GDBusConnection *connection, const gchar *object_path,
-    GDBusInterfaceInfo *interface_info, const GDBusInterfaceVTable *vtable,
-    gpointer user_data, GDestroyNotify user_data_free_func, GError **error) {
+    GDBusConnection* connection, const gchar* object_path,
+    GDBusInterfaceInfo* interface_info, const GDBusInterfaceVTable* vtable,
+    gpointer user_data, GDestroyNotify user_data_free_func, GError** error) {
   tizen_base::Bundle b;
   GVariant* param = g_variant_new("(is)",
       static_cast<int>(ttm::dbus::Command::ADD),
@@ -47,8 +47,21 @@ static guint __g_dbus_connection_register_object_fake(
   return 1;
 }
 
+static guint __g_dbus_connection_register_object_fake2(
+    GDBusConnection* connection, const gchar* object_path,
+    GDBusInterfaceInfo* interface_info, const GDBusInterfaceVTable* vtable,
+    gpointer user_data, GDestroyNotify user_data_free_func, GError** error) {
+  tizen_base::Bundle b;
+  GVariant* param = g_variant_new("(is)",
+      static_cast<int>(ttm::dbus::Command::RESULT),
+      reinterpret_cast<char*>(b.ToRaw().first.get()));
+  vtable->method_call(nullptr, nullptr, nullptr, nullptr,
+      nullptr, param, nullptr, user_data);
+  return 0;
+}
+
 static guint __g_dbus_connection_signal_subscribe_fake(
-    GDBusConnection *con, const gchar* sender, const gchar* interface,
+    GDBusConnectioncon, const gchar* sender, const gchar* interface,
     const gchar* member, const gchar* object, const gchar* arg,
     GDBusSignalFlags flags, GDBusSignalCallback callback,
     gpointer user_data, GDestroyNotify noti) {
@@ -61,9 +74,9 @@ static guint __g_dbus_connection_signal_subscribe_fake(
 }
 
 static void __g_dbus_connection_send_message_with_reply_fake(
-    GDBusConnection *connection, GDBusMessage *message,
+    GDBusConnection* connection, GDBusMessage* message,
     GDBusSendMessageFlags flags, gint timeout_msec,
-    volatile guint32 *out_serial, GCancellable *cancellable,
+    volatile guint32* out_serial, GCancellable* cancellable,
     GAsyncReadyCallback callback, gpointer user_data) {
   callback(nullptr, nullptr, user_data);
 }
@@ -114,7 +127,7 @@ TEST_F(RequestBrokerTest, EmitSignal) {
 
 TEST_F(RequestBrokerTest, EmitSignal_N) {
   GQuark quark = g_quark_from_static_string("test");
-  GError *error = g_error_new(quark, G_DBUS_ERROR_FAILED, "Error");
+  GErrorerror = g_error_new(quark, G_DBUS_ERROR_FAILED, "Error");
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_connection_emit_signal(_, _, _, _, _, _, _)).
           WillOnce(DoAll(SetArgPointee<6>(error), Return(false)));
@@ -124,14 +137,14 @@ TEST_F(RequestBrokerTest, EmitSignal_N) {
 }
 
 TEST_F(RequestBrokerTest, Listen) {
-  GDBusNodeInfo *info = reinterpret_cast<GDBusNodeInfo*>(
+  GDBusNodeInfoinfo = reinterpret_cast<GDBusNodeInfo*>(
       malloc(sizeof(GDBusNodeInfo)));
   info->ref_count = 10;
-  info->path = NULL;
+  info->path = nullptr;
   info->interfaces = reinterpret_cast<GDBusInterfaceInfo**>(
       malloc(sizeof(GDBusInterfaceInfo*)));
-  info->nodes = NULL;
-  info->annotations = NULL;
+  info->nodes = nullptr;
+  info->annotations = nullptr;
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_node_info_new_for_xml(_, _)).WillOnce(Return(info));
   EXPECT_CALL(GetMock<GioMock>(),
@@ -144,21 +157,21 @@ TEST_F(RequestBrokerTest, Listen) {
 
 TEST_F(RequestBrokerTest, Listen_N1) {
   GQuark quark = g_quark_from_static_string("test");
-  GError *error = g_error_new(quark, G_DBUS_ERROR_FAILED, "Error");
+  GErrorerror = g_error_new(quark, G_DBUS_ERROR_FAILED, "Error");
   EXPECT_CALL(GetMock<GioMock>(), g_dbus_node_info_new_for_xml(_, _)).
       WillOnce(DoAll(SetArgPointee<1>(error), Return(nullptr)));
   EXPECT_EQ(broker_.Listen(), false);
 }
 
 TEST_F(RequestBrokerTest, Listen_N2) {
-  GDBusNodeInfo *info = reinterpret_cast<GDBusNodeInfo*>(
+  GDBusNodeInfoinfo = reinterpret_cast<GDBusNodeInfo*>(
       malloc(sizeof(GDBusNodeInfo)));
   info->ref_count = 10;
-  info->path = NULL;
+  info->path = nullptr;
   info->interfaces = reinterpret_cast<GDBusInterfaceInfo**>(
       malloc(sizeof(GDBusInterfaceInfo*)));
-  info->nodes = NULL;
-  info->annotations = NULL;
+  info->nodes = nullptr;
+  info->annotations = nullptr;
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_node_info_new_for_xml(_, _)).WillOnce(Return(info));
   EXPECT_CALL(GetMock<GioMock>(),
@@ -168,14 +181,14 @@ TEST_F(RequestBrokerTest, Listen_N2) {
 }
 
 TEST_F(RequestBrokerTest, Listen_N3) {
-  GDBusNodeInfo *info = reinterpret_cast<GDBusNodeInfo*>(
+  GDBusNodeInfoinfo = reinterpret_cast<GDBusNodeInfo*>(
       malloc(sizeof(GDBusNodeInfo)));
   info->ref_count = 10;
-  info->path = NULL;
+  info->path = nullptr;
   info->interfaces = reinterpret_cast<GDBusInterfaceInfo**>(
       malloc(sizeof(GDBusInterfaceInfo*)));
-  info->nodes = NULL;
-  info->annotations = NULL;
+  info->nodes = nullptr;
+  info->annotations = nullptr;
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_node_info_new_for_xml(_, _)).WillOnce(Return(info));
   EXPECT_CALL(GetMock<GioMock>(),
@@ -186,6 +199,23 @@ TEST_F(RequestBrokerTest, Listen_N3) {
   EXPECT_EQ(broker_.Listen(), false);
 }
 
+TEST_F(RequestBrokerTest, Listen_N4) {
+  GDBusNodeInfo* info = reinterpret_cast<GDBusNodeInfo*>(
+      malloc(sizeof(GDBusNodeInfo)));
+  info->ref_count = 10;
+  info->path = nullptr;
+  info->interfaces = reinterpret_cast<GDBusInterfaceInfo**>(
+      malloc(sizeof(GDBusInterfaceInfo*)));
+  info->nodes = nullptr;
+  info->annotations = nullptr;
+  EXPECT_CALL(GetMock<GioMock>(),
+      g_dbus_node_info_new_for_xml(_, _)).WillOnce(Return(info));
+  EXPECT_CALL(GetMock<GioMock>(),
+      g_dbus_connection_register_object(_, _, _, _, _, _, _)).
+          WillOnce(Invoke(__g_dbus_connection_register_object_fake2));
+  EXPECT_EQ(broker_.Listen(), false);
+}
+
 TEST_F(RequestBrokerTest, Subscribe) {
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_connection_signal_subscribe(_, _, _, _, _, _, _, _, _, _)).
@@ -205,11 +235,11 @@ TEST_F(RequestBrokerTest, SendData_N1) {
 
 TEST_F(RequestBrokerTest, SendData_N2) {
   GDBusMessage* msg =
-      reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL));
+      reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, nullptr));
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_message_new_method_call(_, _, _, _)).WillOnce(Return(msg));
   GQuark quark = g_quark_from_static_string("test");
-  GError *error = g_error_new(quark, G_DBUS_ERROR_FAILED, "Error");
+  GErrorerror = g_error_new(quark, G_DBUS_ERROR_FAILED, "Error");
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_connection_send_message_with_reply_sync(_, _, _, _, _, _, _)).
           WillOnce(DoAll(SetArgPointee<6>(error), Return(nullptr)));
@@ -221,18 +251,41 @@ TEST_F(RequestBrokerTest, SendData_N2) {
 
 TEST_F(RequestBrokerTest, SendData_N3) {
   GDBusMessage* msg =
-      reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL));
+      reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, nullptr));
+  GQuark quark = g_quark_from_static_string("test");
+  GError* error = g_error_new(quark, G_DBUS_ERROR_FAILED, "Error");
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_message_new_method_call(_, _, _, _)).WillOnce(Return(msg));
-  msg = reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL));
+  msg = reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, nullptr));
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_connection_send_message_with_reply_sync(_, _, _, _, _, _, _)).
           WillOnce(Return(msg));
   EXPECT_CALL(GetMock<GioMock>(),
-      g_dbus_message_get_body(_)).WillOnce(Return(nullptr));
+      g_dbus_message_get_message_type(_)).
+          WillOnce(Return(G_DBUS_MESSAGE_TYPE_ERROR));
+  EXPECT_CALL(GetMock<GioMock>(),
+      g_dbus_message_to_gerror(_, _)).
+          WillOnce(DoAll(SetArgPointee<1>(error), Return(true)));
+  tizen_base::Bundle b;
+  b = broker_.SendData(ttm::dbus::Command::ADD, b);
+  std::string result = b.GetString(ttm::dbus::kCmdResultKey);
+  EXPECT_EQ(result, "error");
+}
+
+TEST_F(RequestBrokerTest, SendData_N4) {
+  GDBusMessage* msg =
+      reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, nullptr));
+  EXPECT_CALL(GetMock<GioMock>(),
+      g_dbus_message_new_method_call(_, _, _, _)).WillOnce(Return(msg));
+  msg = reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, nullptr));
+  EXPECT_CALL(GetMock<GioMock>(),
+      g_dbus_connection_send_message_with_reply_sync(_, _, _, _, _, _, _)).
+          WillOnce(Return(msg));
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_message_get_message_type(_)).
           WillOnce(Return(G_DBUS_MESSAGE_TYPE_METHOD_RETURN));
+  EXPECT_CALL(GetMock<GioMock>(),
+      g_dbus_message_get_body(_)).WillOnce(Return(nullptr));
   tizen_base::Bundle b;
   b = broker_.SendData(ttm::dbus::Command::ADD, b);
   std::string result = b.GetString(ttm::dbus::kCmdResultKey);
@@ -248,13 +301,13 @@ TEST_F(RequestBrokerTest, SendDataAsync_N1) {
 
 TEST_F(RequestBrokerTest, OnResultReceivedCb) {
   GDBusMessage* msg =
-      reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL));
+      reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, nullptr));
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_message_new_method_call(_, _, _, _)).WillOnce(Return(msg));
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_connection_send_message_with_reply(_, _, _, _, _, _, _, _)).
           WillOnce(Invoke(__g_dbus_connection_send_message_with_reply_fake));
-  msg = reinterpret_cast<GDBusMessage *>(g_object_new(G_TYPE_OBJECT, NULL));
+  msg = reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, nullptr));
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_connection_send_message_with_reply_finish(_, _, _)).
           WillOnce(Return(msg));
@@ -264,7 +317,7 @@ TEST_F(RequestBrokerTest, OnResultReceivedCb) {
   b.Add(ttm::dbus::kCmdDataKey,
       reinterpret_cast<char*>(ti.Serialize().ToRaw().first.get()));
   b.Add(ttm::dbus::kCmdDataKey, std::vector<std::string>());
-  GVariant *gv = g_variant_new("(s)", b.ToRaw().first.get());
+  GVariantgv = g_variant_new("(s)", b.ToRaw().first.get());
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_message_get_body(_)).WillOnce(Return(gv));
   broker_.SendDataAsync(ttm::dbus::Command::ADD, b);
@@ -272,14 +325,14 @@ TEST_F(RequestBrokerTest, OnResultReceivedCb) {
 
 TEST_F(RequestBrokerTest, OnResultReceivedCb_N) {
   GDBusMessage* msg =
-      reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL));
+      reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, nullptr));
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_message_new_method_call(_, _, _, _)).WillOnce(Return(msg));
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_connection_send_message_with_reply(_, _, _, _, _, _, _, _)).
           WillOnce(Invoke(__g_dbus_connection_send_message_with_reply_fake));
   GQuark quark = g_quark_from_static_string("test");
-  GError *error = g_error_new(quark, G_DBUS_ERROR_FAILED, "Error");
+  GErrorerror = g_error_new(quark, G_DBUS_ERROR_FAILED, "Error");
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_connection_send_message_with_reply_finish(_, _, _)).
           WillOnce(DoAll(SetArgPointee<2>(error), Return(nullptr)));
index 49e50f2..f6d525b 100644 (file)
@@ -114,6 +114,35 @@ class RequestHandlersTest : public TestFixture {
   tizen_base::Bundle b_;
 };
 
+class NegativeRequestHandlersTest : public TestFixture {
+ public:
+  NegativeRequestHandlersTest() : TestFixture(std::make_unique<Mocks>()) {}
+  virtual ~NegativeRequestHandlersTest() {}
+
+  virtual void SetUp() {
+    ttm::provider::DbManager db_manager(kTestDb);
+    proxy_ = std::make_shared<ThemeInfoProxy>(kTestDb);
+
+    b_.Add("id", "testid");
+    b_.Add("pkgid", "testpkgid");
+    b_.Add("uid", "5001");
+    b_.Add("/version", "1.0");
+    b_.Add("/tool_version", "1.1");
+    b_.Add("/title", "Test");
+    b_.Add("/resolution", "360X360");
+    b_.Add("/preview", "shared/res/preview.png");
+    b_.Add("/description", "test");
+  }
+
+  virtual void TearDown() {
+    if (std::remove(kTestDb))
+      std::cerr << "Removing test db failed" << std::endl;
+  }
+
+  std::shared_ptr<ThemeInfoProxy> proxy_;
+  tizen_base::Bundle b_;
+};
+
 class TestEventMock : public IThemeEvent {
  public:
   MOCK_METHOD2(OnThemeChanged, void(const ThemeInfo*,
@@ -247,3 +276,75 @@ TEST_F(RequestHandlersTest, SelectionRequestHandler_OnRequest) {
   std::vector<std::string> ids = rb.GetStringArray(ttm::dbus::kCmdDataKey);
   EXPECT_EQ(ids.size(), 3);
 }
+
+TEST_F(NegativeRequestHandlersTest,
+    PackageRequestHandler_OnRequestWithEmptyArgs) {
+  using ttm::provider::PackageEventRequestHandler;
+  PackageEventRequestHandler handler(proxy_);
+
+  tizen_base::Bundle b;
+  auto rb = handler.OnRequest(ttm::dbus::Command::ADD, b);
+
+  ASSERT_EQ(rb.GetString(ttm::dbus::kCmdResultKey), "error");
+}
+
+TEST_F(NegativeRequestHandlersTest,
+    PackageRequestHandler_OnRequestWithInvalidCommand) {
+  using ttm::provider::PackageEventRequestHandler;
+  PackageEventRequestHandler handler(proxy_);
+
+  ThemeInfo info(b_);
+  auto rb = handler.OnRequest(ttm::dbus::Command::GET, info.Serialize());
+
+  ASSERT_EQ(rb.GetString(ttm::dbus::kCmdResultKey), "error");
+}
+
+TEST_F(NegativeRequestHandlersTest,
+    SelectionRequestHandler_OnRequestWithEmptyId) {
+  using ttm::provider::SelectionRequestHandler;
+  SelectionRequestHandler handler(proxy_);
+
+  tizen_base::Bundle b;
+  b.Add(ttm::dbus::kCmdDataKey, "");
+
+  auto rb = handler.OnRequest(ttm::dbus::Command::GET, b);
+
+  ASSERT_EQ(rb.GetString(ttm::dbus::kCmdResultKey), "error");
+}
+
+TEST_F(NegativeRequestHandlersTest,
+    SelectionRequestHandler_OnRequestWithInvalidCommand) {
+  using ttm::provider::SelectionRequestHandler;
+  SelectionRequestHandler handler(proxy_);
+
+  tizen_base::Bundle b;
+  b.Add(ttm::dbus::kCmdDataKey, "testid");
+
+  auto rb = handler.OnRequest(ttm::dbus::Command::RESULT, b);
+
+  ASSERT_EQ(rb.GetString(ttm::dbus::kCmdResultKey), "error");
+}
+
+TEST_F(NegativeRequestHandlersTest,
+    ControlRequestHandler_OnRequestWithEmptyId) {
+  using ttm::provider::ControlRequestHandler;
+  ControlRequestHandler handler(proxy_);
+
+  tizen_base::Bundle b;
+  b.Add(ttm::dbus::kCmdDataKey, "");
+
+  auto rb = handler.OnRequest(ttm::dbus::Command::SET_ID, b);
+}
+
+TEST_F(NegativeRequestHandlersTest,
+    ControlRequestHandler_OnRequestWithInvalidCommand) {
+  using ttm::provider::ControlRequestHandler;
+  ControlRequestHandler handler(proxy_);
+
+  tizen_base::Bundle b;
+  b.Add(ttm::dbus::kCmdDataKey, "testid");
+
+  auto rb = handler.OnRequest(ttm::dbus::Command::RESULT, b);
+
+  ASSERT_EQ(rb.GetString(ttm::dbus::kCmdResultKey), "error");
+}
diff --git a/test/unit_tests/test_samples/test_missed_mandatory_key.json b/test/unit_tests/test_samples/test_missed_mandatory_key.json
new file mode 100644 (file)
index 0000000..fe86116
--- /dev/null
@@ -0,0 +1,7 @@
+{
+        "version" : "1.0.0",
+        "tool_version" : "1.0.0",
+        "title" : "test_title",
+        "description" : "test_description",
+        "resolution" : "720x1280"
+}
index b027cdd..8cdda46 100644 (file)
@@ -72,7 +72,7 @@ TEST_F(ThemeTest, Theme_GetId) {
   std::shared_ptr<ThemeInfo> info(
       new ThemeInfo(b_));
   theme_h handle = static_cast<void*>(&info);
-  char *id;
+  charid;
   int ret = theme_get_id(handle, &id);
 
   EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
@@ -82,7 +82,7 @@ TEST_F(ThemeTest, Theme_GetId) {
 }
 
 TEST_F(ThemeTest, Theme_GetId_N) {
-  char *id;
+  charid;
   int ret = theme_get_id(nullptr, &id);
 
   EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
@@ -92,7 +92,7 @@ TEST_F(ThemeTest, Theme_GetVersion) {
   std::shared_ptr<ThemeInfo> info(
       new ThemeInfo(b_));
   theme_h handle = static_cast<void*>(&info);
-  char *version;
+  charversion;
   int ret = theme_get_version(handle, &version);
 
   EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
@@ -102,7 +102,7 @@ TEST_F(ThemeTest, Theme_GetVersion) {
 }
 
 TEST_F(ThemeTest, Theme_GetVersion_N) {
-  char *version;
+  charversion;
   int ret = theme_get_version(nullptr, &version);
 
   EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
@@ -113,7 +113,7 @@ TEST_F(ThemeTest, Theme_GetToolVersion) {
       new ThemeInfo(b_));
 
   theme_h handle = static_cast<void*>(&info);
-  char *version;
+  charversion;
   int ret = theme_get_tool_version(handle, &version);
 
   EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
@@ -123,7 +123,7 @@ TEST_F(ThemeTest, Theme_GetToolVersion) {
 }
 
 TEST_F(ThemeTest, Theme_GetToolVersion_N) {
-  char *version;
+  charversion;
   int ret = theme_get_tool_version(nullptr, &version);
 
   EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
@@ -134,7 +134,7 @@ TEST_F(ThemeTest, Theme_GetTitle) {
       new ThemeInfo(b_));
 
   theme_h handle = static_cast<void*>(&info);
-  char *title;
+  chartitle;
   int ret = theme_get_title(handle, &title);
 
   EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
@@ -145,7 +145,7 @@ TEST_F(ThemeTest, Theme_GetTitle) {
 
 
 TEST_F(ThemeTest, Theme_GetTitle_N) {
-  char *title;
+  chartitle;
   int ret = theme_get_title(nullptr, &title);
 
   EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
@@ -156,7 +156,7 @@ TEST_F(ThemeTest, Theme_GetResolution) {
       new ThemeInfo(b_));
 
   theme_h handle = static_cast<void*>(&info);
-  char *resolution;
+  charresolution;
   int ret = theme_get_resolution(handle, &resolution);
 
   EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
@@ -166,7 +166,7 @@ TEST_F(ThemeTest, Theme_GetResolution) {
 }
 
 TEST_F(ThemeTest, Theme_GetResolution_N) {
-  char *resolution;
+  charresolution;
   int ret = theme_get_resolution(nullptr, &resolution);
 
   EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
@@ -177,7 +177,7 @@ TEST_F(ThemeTest, Theme_GetPreview) {
       new ThemeInfo(b_));
 
   theme_h handle = static_cast<void*>(&info);
-  char *preview;
+  charpreview;
   int ret = theme_get_preview(handle, &preview);
 
   EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
@@ -187,7 +187,7 @@ TEST_F(ThemeTest, Theme_GetPreview) {
 }
 
 TEST_F(ThemeTest, Theme_GetPreview_N) {
-  char *preview;
+  charpreview;
   int ret = theme_get_preview(nullptr, &preview);
 
   EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
@@ -198,7 +198,7 @@ TEST_F(ThemeTest, Theme_GetDescription) {
       new ThemeInfo(b_));
 
   theme_h handle = static_cast<void*>(&info);
-  char *description;
+  chardescription;
   int ret = theme_get_description(handle, &description);
 
   EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
@@ -208,7 +208,7 @@ TEST_F(ThemeTest, Theme_GetDescription) {
 }
 
 TEST_F(ThemeTest, Theme_GetDescription_N) {
-  char *description;
+  chardescription;
   int ret = theme_get_description(nullptr, &description);
 
   EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
@@ -219,7 +219,7 @@ TEST_F(ThemeTest, Theme_GetString) {
       new ThemeInfo(b_));
 
   theme_h handle = static_cast<void*>(&info);
-  char *str;
+  charstr;
   int ret = theme_get_string(handle, "/stringkey", &str);
 
   EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
@@ -229,7 +229,7 @@ TEST_F(ThemeTest, Theme_GetString) {
 }
 
 TEST_F(ThemeTest, Theme_GetString_N) {
-  char *str;
+  charstr;
   int ret = theme_get_string(nullptr, "/stringkey", &str);
 
   EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
@@ -240,7 +240,7 @@ TEST_F(ThemeTest, Theme_GetString_N2) {
       new ThemeInfo());
 
   theme_h handle = static_cast<void*>(&info);
-  char *str;
+  charstr;
   int ret = theme_get_string(handle, "/stringkey", &str);
 
   EXPECT_EQ(ret, THEME_MANAGER_ERROR_IO_ERROR);
@@ -251,7 +251,7 @@ TEST_F(ThemeTest, Theme_GetStringArray_P) {
       new ThemeInfo(b_));
 
   theme_h handle = static_cast<void*>(&info);
-  char **strarr;
+  char** strarr;
   int count;
   int ret = theme_get_string_array(handle, "/arraykey", &strarr, &count);
 
@@ -268,7 +268,7 @@ TEST_F(ThemeTest, Theme_GetStringArray_P2) {
       new ThemeInfo());
 
   theme_h handle = static_cast<void*>(&info);
-  char **strarr;
+  char** strarr;
   int count;
   int ret = theme_get_string_array(handle, "/arraykey", &strarr, &count);
 
@@ -277,7 +277,7 @@ TEST_F(ThemeTest, Theme_GetStringArray_P2) {
 }
 
 TEST_F(ThemeTest, Theme_GetStringArray_N) {
-  char **strarr;
+  char** strarr;
   int count;
   int ret = theme_get_string_array(nullptr, "/arraykey", &strarr, &count);
 
@@ -450,6 +450,12 @@ TEST_F(ThemeTest, Theme_GetPath) {
     free(path2);
 }
 
+TEST_F(ThemeTest, Theme_GetPath_N) {
+  char* path;
+  int ret = theme_get_path(nullptr, "/preview", &path);
+  EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
+}
+
 TEST_F(ThemeTest, Theme_GetPathArray) {
   std::shared_ptr<ThemeInfo> test_theme(new ThemeInfo(b_));
   theme_h handle = static_cast<void*>(&test_theme);
@@ -469,7 +475,7 @@ TEST_F(ThemeTest, Theme_GetPathArray) {
                   SetArgPointee<1>(const_cast<char*>(root_path1)),
                   Return(PMINFO_R_OK)));
 
-  char **strarr;
+  char** strarr;
   int count;
   int ret = theme_get_path_array(handle, "/arraykey", &strarr, &count);
 
@@ -483,3 +489,10 @@ TEST_F(ThemeTest, Theme_GetPathArray) {
       free(strarr[i]);
   free(strarr);
 }
+
+TEST_F(ThemeTest, Theme_GetPathArray_N) {
+  char** paths;
+  int count;
+  int ret = theme_get_path_array(nullptr, "/arraykey", &paths, &count);
+  EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
+}
index 3126a78..470972c 100644 (file)
@@ -90,7 +90,7 @@ TEST_F(ThemeLoaderTest, SetCurrent) {
       g_dbus_message_new_method_call(_, _, _, _)).
           WillOnce(Return(reinterpret_cast<GDBusMessage*>(1)));
   GDBusMessage* msg =
-      reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL));
+      reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, nullptr));
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_connection_send_message_with_reply_sync(_, _, _, _, _, _, _)).
           WillOnce(Return(msg));
@@ -126,7 +126,7 @@ TEST_F(ThemeLoaderTest, LoadCurrent) {
       g_dbus_message_new_method_call(_, _, _, _)).
           WillOnce(Return(reinterpret_cast<GDBusMessage*>(1)));
   GDBusMessage* msg =
-      reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL));
+      reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, nullptr));
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_connection_send_message_with_reply_sync(_, _, _, _, _, _, _)).
           WillOnce(Return(msg));
@@ -168,7 +168,7 @@ TEST_F(ThemeLoaderTest, Load) {
           StrEq("SendData"))).
               WillOnce(Return(reinterpret_cast<GDBusMessage*>(1)));
   GDBusMessage* msg =
-      reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL));
+      reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, nullptr));
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_connection_send_message_with_reply_sync(_, _, _, _, _, _, _)).
           WillOnce(Return(msg));
@@ -214,7 +214,7 @@ TEST_F(ThemeLoaderTest, QueryID) {
   EXPECT_CALL(GetMock<GioMock>(), g_dbus_message_new_method_call(_, _, _, _)).
       WillOnce(Return(reinterpret_cast<GDBusMessage*>(1)));
   GDBusMessage* msg =
-      reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, NULL));
+      reinterpret_cast<GDBusMessage*>(g_object_new(G_TYPE_OBJECT, nullptr));
   EXPECT_CALL(GetMock<GioMock>(),
       g_dbus_connection_send_message_with_reply_sync(_, _, _, _, _, _, _)).
           WillOnce(Return(msg));
index 6f8b6a6..ee4f932 100644 (file)
@@ -184,3 +184,43 @@ TEST_F(ThemeParserTest, LongLengthValue_N2) {
   auto info = parser.Inflate("testid", "testpkgid", 5001, false);
   EXPECT_FALSE(info.IsValid());
 }
+
+TEST_F(ThemeParserTest, MandatoryKeyMiss) {
+  ttm::plugin::ThemeParser parser(
+      "test_samples/test_missed_mandatory_key.json", false);
+  auto info = parser.Inflate("testid", "testpkgid", 5001, false);
+  EXPECT_FALSE(info.IsValid());
+}
+
+TEST_F(ThemeParserTest, Commit_N1) {
+  ttm::plugin::ThemeParser parser("test_samples/test_theme.json", false);
+  auto info = parser.Inflate("testid", "testpkgid", 5001, false);
+  EXPECT_TRUE(info.IsValid());
+
+  EXPECT_CALL(GetMock<GioMock>(),
+      g_dbus_message_new_method_call(_, _, _, _)).WillOnce(Return(nullptr));
+  EXPECT_FALSE(
+      parser.Commit(ttm::plugin::ThemeParser::ThemeOperation::ADD, info));
+}
+
+TEST_F(ThemeParserTest, Commit_N2) {
+  ttm::plugin::ThemeParser parser("test_samples/test_theme.json", false);
+  auto info = parser.Inflate("testid", "testpkgid", 5001, false);
+  EXPECT_TRUE(info.IsValid());
+
+  EXPECT_CALL(GetMock<GioMock>(),
+      g_dbus_message_new_method_call(_, _, _, _)).WillOnce(Return(nullptr));
+  EXPECT_FALSE(
+      parser.Commit(ttm::plugin::ThemeParser::ThemeOperation::UPDATE, info));
+}
+
+TEST_F(ThemeParserTest, Commit_N3) {
+  ttm::plugin::ThemeParser parser("test_samples/test_theme.json", false);
+  auto info = parser.Inflate("testid", "testpkgid", 5001, false);
+  EXPECT_TRUE(info.IsValid());
+
+  EXPECT_CALL(GetMock<GioMock>(),
+      g_dbus_message_new_method_call(_, _, _, _)).WillOnce(Return(nullptr));
+  EXPECT_FALSE(
+      parser.Commit(ttm::plugin::ThemeParser::ThemeOperation::REMOVE, info));
+}