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),
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,
+ GDBusConnection* con, const gchar* sender, const gchar* interface,
const gchar* member, const gchar* object, const gchar* arg,
GDBusSignalFlags flags, GDBusSignalCallback callback,
gpointer user_data, GDestroyNotify noti) {
}
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);
}
TEST_F(RequestBrokerTest, EmitSignal_N) {
GQuark quark = g_quark_from_static_string("test");
- GError *error = g_error_new(quark, G_DBUS_ERROR_FAILED, "Error");
+ GError* error = 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)));
}
TEST_F(RequestBrokerTest, Listen) {
- GDBusNodeInfo *info = reinterpret_cast<GDBusNodeInfo*>(
+ GDBusNodeInfo* info = 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>(),
TEST_F(RequestBrokerTest, Listen_N1) {
GQuark quark = g_quark_from_static_string("test");
- GError *error = g_error_new(quark, G_DBUS_ERROR_FAILED, "Error");
+ GError* error = 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*>(
+ GDBusNodeInfo* info = 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>(),
}
TEST_F(RequestBrokerTest, Listen_N3) {
- GDBusNodeInfo *info = reinterpret_cast<GDBusNodeInfo*>(
+ GDBusNodeInfo* info = 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>(),
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(_, _, _, _, _, _, _, _, _, _)).
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");
+ GError* error = 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)));
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);
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));
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());
+ GVariant* gv = 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);
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");
+ GError* error = 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)));
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*,
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");
+}
std::shared_ptr<ThemeInfo> info(
new ThemeInfo(b_));
theme_h handle = static_cast<void*>(&info);
- char *id;
+ char* id;
int ret = theme_get_id(handle, &id);
EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
}
TEST_F(ThemeTest, Theme_GetId_N) {
- char *id;
+ char* id;
int ret = theme_get_id(nullptr, &id);
EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
std::shared_ptr<ThemeInfo> info(
new ThemeInfo(b_));
theme_h handle = static_cast<void*>(&info);
- char *version;
+ char* version;
int ret = theme_get_version(handle, &version);
EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
}
TEST_F(ThemeTest, Theme_GetVersion_N) {
- char *version;
+ char* version;
int ret = theme_get_version(nullptr, &version);
EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
new ThemeInfo(b_));
theme_h handle = static_cast<void*>(&info);
- char *version;
+ char* version;
int ret = theme_get_tool_version(handle, &version);
EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
}
TEST_F(ThemeTest, Theme_GetToolVersion_N) {
- char *version;
+ char* version;
int ret = theme_get_tool_version(nullptr, &version);
EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
new ThemeInfo(b_));
theme_h handle = static_cast<void*>(&info);
- char *title;
+ char* title;
int ret = theme_get_title(handle, &title);
EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
TEST_F(ThemeTest, Theme_GetTitle_N) {
- char *title;
+ char* title;
int ret = theme_get_title(nullptr, &title);
EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
new ThemeInfo(b_));
theme_h handle = static_cast<void*>(&info);
- char *resolution;
+ char* resolution;
int ret = theme_get_resolution(handle, &resolution);
EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
}
TEST_F(ThemeTest, Theme_GetResolution_N) {
- char *resolution;
+ char* resolution;
int ret = theme_get_resolution(nullptr, &resolution);
EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
new ThemeInfo(b_));
theme_h handle = static_cast<void*>(&info);
- char *preview;
+ char* preview;
int ret = theme_get_preview(handle, &preview);
EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
}
TEST_F(ThemeTest, Theme_GetPreview_N) {
- char *preview;
+ char* preview;
int ret = theme_get_preview(nullptr, &preview);
EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
new ThemeInfo(b_));
theme_h handle = static_cast<void*>(&info);
- char *description;
+ char* description;
int ret = theme_get_description(handle, &description);
EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
}
TEST_F(ThemeTest, Theme_GetDescription_N) {
- char *description;
+ char* description;
int ret = theme_get_description(nullptr, &description);
EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
new ThemeInfo(b_));
theme_h handle = static_cast<void*>(&info);
- char *str;
+ char* str;
int ret = theme_get_string(handle, "/stringkey", &str);
EXPECT_EQ(ret, THEME_MANAGER_ERROR_NONE);
}
TEST_F(ThemeTest, Theme_GetString_N) {
- char *str;
+ char* str;
int ret = theme_get_string(nullptr, "/stringkey", &str);
EXPECT_EQ(ret, THEME_MANAGER_ERROR_INVALID_PARAMETER);
new ThemeInfo());
theme_h handle = static_cast<void*>(&info);
- char *str;
+ char* str;
int ret = theme_get_string(handle, "/stringkey", &str);
EXPECT_EQ(ret, THEME_MANAGER_ERROR_IO_ERROR);
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);
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);
}
TEST_F(ThemeTest, Theme_GetStringArray_N) {
- char **strarr;
+ char** strarr;
int count;
int ret = theme_get_string_array(nullptr, "/arraykey", &strarr, &count);
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);
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);
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);
+}