--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "appsvc_mock.h"
+
+#include "mock_hook.h"
+#include "test_fixture.h"
+
+extern "C" int appsvc_run_service(bundle* b, int request_code,
+ appsvc_res_fn cbfunc, void* data) {
+ return MOCK_HOOK_P4(AppSvcMock, appsvc_run_service,
+ b, request_code, cbfunc, data);
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef MOCK_APP_SVC_MOCK_H_
+#define MOCK_APP_SVC_MOCK_H_
+
+#include <gmock/gmock.h>
+#include <appsvc.h>
+
+#include "module_mock.h"
+
+class AppSvcMock : public virtual ModuleMock {
+ public:
+ virtual ~AppSvcMock() {}
+
+ MOCK_METHOD4(appsvc_run_service, int (bundle* , int, appsvc_res_fn, void*));
+};
+
+#endif // MOCK_APP_SVC_MOCK_H_
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include "cynara_mock.h"
+
+#include "mock_hook.h"
+#include "test_fixture.h"
+
+extern "C" int cynara_initialize(cynara** pp_cynara,
+ const cynara_configuration* p_conf) {
+ return MOCK_HOOK_P2(CynaraMock, cynara_initialize, pp_cynara, p_conf);
+}
+
+extern "C" int cynara_check(cynara* p_cynara, const char* client,
+ const char* client_session, const char* user, const char* privilege) {
+ return MOCK_HOOK_P5(CynaraMock, cynara_check, p_cynara,
+ client, client_session, user, privilege);
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef MOCK_CYNARA_MOCK_H_
+#define MOCK_CYNARA_MOCK_H_
+
+#include <gmock/gmock.h>
+#include <cynara-client.h>
+
+#include "module_mock.h"
+
+class CynaraMock : public virtual ModuleMock {
+ public:
+ virtual ~CynaraMock() {}
+
+ MOCK_METHOD2(cynara_initialize, int(cynara**, const cynara_configuration*));
+ MOCK_METHOD5(cynara_check,
+ int(cynara*, const char*, const char*, const char*, const char*));
+};
+
+#endif // MOCK_CYNARA_MOCK_H_
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gio/gio.h>
+
+#include "gio_mock.h"
+#include "mock_hook.h"
+#include "test_fixture.h"
+
+extern "C" GDBusConnection* g_bus_get_sync(GBusType type,
+ GCancellable* cancellable, GError** error) {
+ return MOCK_HOOK_P3(GioMock, g_bus_get_sync, type, cancellable, error);
+}
+
+extern "C" GDBusMessage* g_dbus_connection_send_message_with_reply_sync(
+ GDBusConnection* conn, GDBusMessage* msg, GDBusSendMessageFlags flags,
+ gint timeout, volatile guint32* out_serial, GCancellable* cancellable,
+ GError** error) {
+ return MOCK_HOOK_P7(GioMock, g_dbus_connection_send_message_with_reply_sync,
+ conn, msg, flags, timeout, out_serial, cancellable, error);
+}
+
+extern "C" GDBusMessage* g_dbus_message_new_method_call(const gchar* arg0,
+ const gchar* arg1, const gchar* arg2, const gchar* arg3) {
+ return MOCK_HOOK_P4(GioMock, g_dbus_message_new_method_call, arg0, arg1, arg2,
+ arg3);
+}
+
+extern "C" void g_dbus_message_set_body(GDBusMessage* arg0, GVariant* arg1) {
+ return MOCK_HOOK_P2(GioMock, g_dbus_message_set_body, arg0, arg1);
+}
+
+extern "C" GVariant* g_dbus_message_get_body(GDBusMessage* arg0) {
+ return MOCK_HOOK_P1(GioMock, g_dbus_message_get_body, arg0);
+}
+
+extern "C" guint g_dbus_connection_signal_subscribe(GDBusConnection* arg0,
+ const gchar* arg1, const gchar* arg2, const gchar* arg3, const gchar* arg4,
+ const gchar* arg5, GDBusSignalFlags arg6, GDBusSignalCallback arg7,
+ gpointer arg8, GDestroyNotify arg9) {
+ return MOCK_HOOK_P10(GioMock, g_dbus_connection_signal_subscribe,
+ arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
+}
+
+extern "C" void g_dbus_connection_send_message_with_reply(GDBusConnection* arg0,
+ GDBusMessage* arg1, GDBusSendMessageFlags arg2, gint arg3,
+ volatile guint32* arg4, GCancellable* arg5, GAsyncReadyCallback arg6,
+ gpointer arg7) {
+ return MOCK_HOOK_P8(GioMock, g_dbus_connection_send_message_with_reply,
+ arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
+}
+
+extern "C" guint g_bus_watch_name_on_connection(
+ GDBusConnection* arg0, const gchar* arg1, GBusNameWatcherFlags arg2,
+ GBusNameAppearedCallback arg3, GBusNameVanishedCallback arg4,
+ gpointer arg5, GDestroyNotify arg6) {
+ return MOCK_HOOK_P7(GioMock, g_bus_watch_name_on_connection,
+ arg0, arg1, arg2, arg3, arg4, arg5, arg6);
+}
+
+extern "C" void g_bus_unwatch_name(guint arg0) {
+ return MOCK_HOOK_P1(GioMock, g_bus_unwatch_name, arg0);
+}
+
+extern "C" void g_dbus_connection_signal_unsubscribe(
+ GDBusConnection* arg0, guint arg1) {
+ return MOCK_HOOK_P2(GioMock, g_dbus_connection_signal_unsubscribe,
+ arg0, arg1);
+}
+
+extern "C" const gchar* g_dbus_connection_get_unique_name(GDBusConnection* connection) {
+ return MOCK_HOOK_P1(GioMock, g_dbus_connection_get_unique_name, connection);
+}
+
+extern "C" gboolean g_source_remove(guint tag) {
+ return MOCK_HOOK_P1(GioMock, g_source_remove, tag);
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef MOCK_GIO_MOCK_H_
+#define MOCK_GIO_MOCK_H_
+
+#include <gio/gio.h>
+#include <gmock/gmock.h>
+
+#include "module_mock.h"
+
+class GioMock : public virtual ModuleMock {
+ public:
+ virtual ~GioMock() {}
+
+ MOCK_METHOD3(g_bus_get_sync,
+ GDBusConnection*(GBusType, GCancellable*, GError**));
+ MOCK_METHOD4(g_dbus_message_new_method_call,
+ GDBusMessage*(const gchar*, const gchar*, const gchar*, const gchar*));
+ MOCK_METHOD2(g_dbus_message_set_body, void(GDBusMessage*, GVariant*));
+ MOCK_METHOD1(g_dbus_message_get_body, GVariant*(GDBusMessage*));
+ MOCK_METHOD7(g_dbus_connection_send_message_with_reply_sync,
+ GDBusMessage*(GDBusConnection*, GDBusMessage*, GDBusSendMessageFlags,
+ gint, volatile guint32*, GCancellable*, GError**));
+ MOCK_METHOD10(g_dbus_connection_signal_subscribe,
+ guint(GDBusConnection*, const gchar*, const gchar*, const gchar*,
+ const gchar*, const gchar*, GDBusSignalFlags, GDBusSignalCallback,
+ gpointer, GDestroyNotify));
+ MOCK_METHOD8(g_dbus_connection_send_message_with_reply,
+ void(GDBusConnection*, GDBusMessage*, GDBusSendMessageFlags, gint,
+ volatile guint32*, GCancellable*, GAsyncReadyCallback, gpointer));
+ MOCK_METHOD7(g_bus_watch_name_on_connection,
+ guint(GDBusConnection*, const gchar*, GBusNameWatcherFlags,
+ GBusNameAppearedCallback, GBusNameVanishedCallback, gpointer,
+ GDestroyNotify));
+ MOCK_METHOD1(g_bus_unwatch_name, void(guint));
+ MOCK_METHOD2(g_dbus_connection_signal_unsubscribe,
+ void(GDBusConnection*, guint));
+ MOCK_METHOD1(g_dbus_connection_get_unique_name, const gchar*(GDBusConnection*));
+ MOCK_METHOD1(g_source_remove, gboolean(guint));
+};
+
+#endif // MOCK_GIO_MOCK_H_
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include "pkgmgr_info_mock.h"
+
+#include "mock_hook.h"
+#include "test_fixture.h"
+
+extern "C" int pkgmgrinfo_appinfo_usr_get_datacontrol_info(
+ const char* providerid, const char* type, uid_t uid, char** appid, char** access) {
+ return MOCK_HOOK_P5(PkgmgrInfoMock, pkgmgrinfo_appinfo_usr_get_datacontrol_info,
+ providerid, type, uid, appid, access);
+}
+
+extern "C" int pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(
+ const char* providerid, const char* type, uid_t uid, char** appid, bool *is_trusted) {
+ return MOCK_HOOK_P5(PkgmgrInfoMock, pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info,
+ providerid, type, uid, appid, is_trusted);
+}
+
+extern "C" int pkgmgrinfo_pkginfo_compare_usr_app_cert_info(
+ const char* lhs_app_id, const char* rhs_app_id, uid_t uid,
+ pkgmgrinfo_cert_compare_result_type_e *compare_result) {
+ return MOCK_HOOK_P4(PkgmgrInfoMock, pkgmgrinfo_pkginfo_compare_usr_app_cert_info,
+ lhs_app_id, rhs_app_id, uid, compare_result);
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef MOCK_PKGMGR_INFO_MOCK_H_
+#define MOCK_PKGMGR_INFO_MOCK_H_
+
+#include <gmock/gmock.h>
+#include <pkgmgr-info.h>
+#include <sys/types.h>
+
+#include "module_mock.h"
+
+class PkgmgrInfoMock : public virtual ModuleMock {
+ public:
+ virtual ~PkgmgrInfoMock() {}
+
+ MOCK_METHOD5(pkgmgrinfo_appinfo_usr_get_datacontrol_info,
+ int(const char*, const char*, uid_t, char**, char**));
+ MOCK_METHOD5(pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info,
+ int(const char*, const char*, uid_t, char**, bool*));
+ MOCK_METHOD4(pkgmgrinfo_pkginfo_compare_usr_app_cert_info,
+ int(const char*, const char*, uid_t,
+ pkgmgrinfo_cert_compare_result_type_e*));
+};
+
+#endif // MOCK_PKGMGR_INFO_MOCK_H_
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+#include "unistd_mock.h"
+#include "mock_hook.h"
+#include "test_fixture.h"
+
+extern "C" off_t lseek(int fd, off_t offset, int whence) {
+ return MOCK_HOOK_P3(UnistdMock, lseek, fd, offset, whence);
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef MOCK_UNISTD_MOCK_H_
+#define MOCK_UNISTD_MOCK_H_
+
+#include <gmock/gmock.h>
+#include <unistd.h>
+#include <aul.h>
+
+#include "module_mock.h"
+
+class UnistdMock : public virtual ModuleMock {
+ public:
+ virtual ~UnistdMock() {}
+
+ MOCK_METHOD3(lseek, off_t(int, off_t, int));
+};
+
+#endif // MOCK_UNISTD_MOCK_H_
gio-2.0\r
sqlite3\r
aul\r
+ cynara-client\r
+ appsvc\r
)\r
\r
FOREACH(flag ${data_control_unittests_CFLAGS})\r
#include <memory>
#include "data_control.h"
+#include "unistd_mock.h"
+#include "pkgmgr_info_mock.h"
+#include "cynara_mock.h"
+#include "appsvc_mock.h"
+#include "gio_mock.h"
#include "test_fixture.h"
using namespace tizen_base;
-class Mocks : public virtual ModuleMock {};
+class Mocks : public ::testing::NiceMock<PkgmgrInfoMock>,
+ public ::testing::NiceMock<CynaraMock>,
+ public ::testing::NiceMock<AppSvcMock>,
+ public ::testing::NiceMock<GioMock>,
+ public ::testing::NiceMock<UnistdMock> {};
class DataControlBulkTest : public TestFixture {
public:
TEST_F(DataControlBulkTest, bulk_data_test) {
int ret;
- bundle* ret_b;
Bundle b;
+ bundle* ret_b;
int count;
char* ret_val;
data_control_bulk_data_h bulk_data_h;
EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
}
-TEST_F(DataControlBulkTest, buld_result_data_test) {
+TEST_F(DataControlBulkTest, bulk_result_data_test) {
int ret;
Bundle b;
bundle* ret_b;
b.Add(std::string("testkey"), std::string("testvalue"));
ret = data_control_bulk_result_data_add(result_data_h, b.GetHandle(),
- DATA_CONTROL_ERROR_NONE);
+ DATA_CONTROL_ERROR_NONE);
EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
ret = data_control_bulk_result_data_get_count(result_data_h, &count);
ret = data_control_bulk_result_data_destroy(result_data_h);
EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
}
+
+TEST_F(DataControlBulkTest, bulk_test_n) {
+ int ret;
+
+ ret = data_control_bulk_data_create(NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_INVALID_PARAMETER);
+
+ ret = data_control_bulk_data_add(NULL, NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_INVALID_PARAMETER);
+
+ ret = data_control_bulk_data_get_count(NULL, NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_INVALID_PARAMETER);
+
+ ret = data_control_bulk_data_get_data(NULL, 0, NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_INVALID_PARAMETER);
+
+ ret = data_control_bulk_data_destroy(NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_INVALID_PARAMETER);
+
+ ret = data_control_bulk_result_data_create(NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_INVALID_PARAMETER);
+
+ ret = data_control_bulk_result_data_add(NULL, NULL,
+ DATA_CONTROL_ERROR_NONE);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_INVALID_PARAMETER);
+
+ ret = data_control_bulk_result_data_get_count(NULL, NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_INVALID_PARAMETER);
+
+ ret = data_control_bulk_result_data_get_result_data(NULL, 0, NULL, NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_INVALID_PARAMETER);
+
+ ret = data_control_bulk_result_data_destroy(NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_INVALID_PARAMETER);
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+#include <aul.h>
+#include <sqlite3.h>
+#include <bundle_cpp.h>
+#include <glib.h>
+
+#include "data_control.h"
+#include "data_control_internal.h"
+#include "unistd_mock.h"
+#include "pkgmgr_info_mock.h"
+#include "cynara_mock.h"
+#include "appsvc_mock.h"
+#include "gio_mock.h"
+
+extern "C" int aul_request_data_control_socket_pair(bundle* b, int* fd) {
+ fd[0] = 77;
+ return 0;
+}
+
+extern "C" GIOChannel* g_io_channel_unix_new(int fd) {
+ return g_new(GIOChannel, 1);
+}
+
+extern "C" GIOStatus g_io_channel_shutdown(GIOChannel* channel,
+ gboolean flush, GError** err) {
+ return G_IO_STATUS_NORMAL;
+}
+
+extern "C" ssize_t write(int fd, const void* buf, size_t count) {
+ return count;
+}
+
+extern "C" ssize_t read(int fd, void* buf, size_t count) {
+ int val;
+
+ switch(fd / 1000) {
+ case DATA_CONTROL_SQL_COLUMN_TYPE_INT64 :
+ val = DATA_CONTROL_SQL_COLUMN_TYPE_INT64;
+ memcpy(buf, &val, count);
+ break;
+ case DATA_CONTROL_SQL_COLUMN_TYPE_DOUBLE :
+ val = DATA_CONTROL_SQL_COLUMN_TYPE_DOUBLE;
+ memcpy(buf, &val, count);
+ break;
+ case DATA_CONTROL_SQL_COLUMN_TYPE_TEXT :
+ val = DATA_CONTROL_SQL_COLUMN_TYPE_TEXT;
+ memcpy(buf, &val, count);
+ break;
+ case DATA_CONTROL_SQL_COLUMN_TYPE_BLOB :
+ val = DATA_CONTROL_SQL_COLUMN_TYPE_BLOB;
+ memcpy(buf, &val, count);
+ break;
+ default :
+ if (count == 4) {
+ val = count;
+ memcpy(buf, &val, count);
+ }
+ break;
+ }
+
+ return count;
+}
+
+extern "C" int aul_app_get_appid_bypid(int pid, char* appid, int len) {
+ int ret;
+
+ ret = snprintf(appid, 13, "%s", "caller_appid");
+ if (ret < 0)
+ return -1;
+
+ return 0;
+}
+
+extern "C" int sqlite3_prepare_v2(sqlite3* db, const char* zSql,
+ int nByte, sqlite3_stmt** ppStmt, const char** pzTail) {
+ return 0;
+}
+
+extern "C" int sqlite3_bind_text(sqlite3_stmt* stmt, int pos,
+ const char* text, int val, void(*)(void*)) {
+ return 0;
+}
+
+extern "C" int g_io_channel_unix_get_fd(GIOChannel* channel) {
+ return 9;
+}
+
+GIOFunc __io_func;
+gpointer __io_data;
+GDestroyNotify __io_notify;
+extern "C" guint g_io_add_watch(GIOChannel* channel, GIOCondition condition,
+ GIOFunc func, gpointer user_data) {
+ __io_func = func;
+ __io_data = user_data;
+ return 54;
+}
+
+data_control_provider_handler_fn __cb;
+
+extern "C" int aul_set_data_control_provider_cb(
+ data_control_provider_handler_fn handler) {
+ __cb = handler;
+ return 0;
+}
+
+extern "C" bundle* bundle_decode_raw(const bundle_raw* r, const int len) {
+ bundle* b;
+ const char *str_array[] = { "data_id", "bbb", "ccc" };
+
+ b = bundle_create();
+
+ bundle_add_str(b, OSP_K_REQUEST_ID, "99");
+ bundle_add_str(b, AUL_K_CALLER_APPID, "caller_appid");
+ bundle_add_str(b, OSP_K_DATACONTROL_REQUEST_TYPE, "2");
+ bundle_add_str(b, OSP_K_DATACONTROL_PROVIDER, "provider_id");
+ bundle_add_str(b, OSP_K_DATACONTROL_HANDLE_ID, "caller_handle_id");
+
+ bundle_add_str(b, "RESULT_PAGE_NUMBER", "1");
+ bundle_add_str(b, "MAX_COUNT_PER_PAGE", "1");
+ bundle_add_str(b, "RESULT_VALUE_COUNT", "1");
+ bundle_add_str_array(b, OSP_K_ARG, str_array, 3);
+
+ return b;
+}
+
+extern "C" int sqlite3_reset(sqlite3_stmt* pStmt) {
+ return SQLITE_OK;
+}
+
+extern "C" int sqlite3_step(sqlite3_stmt* pStmt) {
+ return SQLITE_OK;
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <gtest/gtest.h>
+#include <stdio.h>
+#include <bundle_cpp.h>
+
+#include <memory>
+
+#include "data_control.h"
+#include "unistd_mock.h"
+#include "pkgmgr_info_mock.h"
+#include "cynara_mock.h"
+#include "appsvc_mock.h"
+#include "gio_mock.h"
+#include "test_fixture.h"
+
+using namespace tizen_base;
+
+using ::testing::_;
+using ::testing::DoAll;
+using ::testing::Return;
+using ::testing::SetArgPointee;
+
+class Mocks : public ::testing::NiceMock<PkgmgrInfoMock>,
+ public ::testing::NiceMock<CynaraMock>,
+ public ::testing::NiceMock<AppSvcMock>,
+ public ::testing::NiceMock<GioMock>,
+ public ::testing::NiceMock<UnistdMock> {};
+
+class DataControlMapTest : public TestFixture {
+ public:
+ DataControlMapTest() : TestFixture(std::make_unique<Mocks>()) {}
+ virtual ~DataControlMapTest() {}
+
+ virtual void SetUp() {
+ }
+
+ virtual void TearDown() {
+ }
+};
+
+void _data_control_map_get_response_cb(int request_id, data_control_h provider,
+ char** result_value_list, int result_value_count,
+ bool provider_result, const char* error, void* user_data) {
+}
+
+void _data_control_map_set_response_cb(int request_id, data_control_h provider,
+ bool provider_result, const char* error, void* user_data) {
+}
+
+void _data_control_map_add_response_cb(int request_id, data_control_h provider,
+ bool provider_result, const char* error, void* user_data) {
+}
+
+void _data_control_map_remove_response_cb(int request_id, data_control_h provider,
+ bool provider_result, const char* error, void* user_data) {
+}
+
+void _data_control_bulk_cb(int request_id, data_control_h provider,
+ data_control_bulk_result_data_h bulk_results, bool provider_result,
+ const char* error, void* user_data) {
+}
+
+TEST_F(DataControlMapTest, map_test) {
+ int ret;
+ int req_id;
+ int handle_id = 0;
+ char* access;
+ char* app_id;
+ char* provider_appid;
+ char* provider_id = nullptr;
+ char* data_id = nullptr;
+ bool is_trusted = true;
+ Bundle b;
+ data_control_h provider;
+ data_control_map_response_cb* map_cb;
+ pkgmgrinfo_cert_compare_result_type_e res;
+ data_control_bulk_data_h bulk_data_h;
+
+ ret = data_control_map_create(&provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_set_provider_id(provider, "test_providerid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_get_provider_id(provider, &provider_id);
+ EXPECT_STREQ(provider_id, "test_providerid");
+
+ free(provider_id);
+
+ ret = data_control_map_set_data_id(provider, "test_dataid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_get_data_id(provider, &data_id);
+ EXPECT_STREQ(data_id, "test_dataid");
+
+ free(data_id);
+
+ ret = data_control_map_get_handle_id(provider, &handle_id);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+ EXPECT_NE(handle_id, 0);
+
+ map_cb = (data_control_map_response_cb*)malloc(sizeof(data_control_map_response_cb));
+ ASSERT_NE(map_cb, nullptr);
+
+ map_cb->get_cb = _data_control_map_get_response_cb;
+ map_cb->set_cb = _data_control_map_set_response_cb;
+ map_cb->add_cb = _data_control_map_add_response_cb;
+ map_cb->remove_cb = _data_control_map_remove_response_cb;
+
+ app_id = (char*)malloc(sizeof(char) * 11);
+
+ ret = snprintf(app_id, 11, "%s", "test_appid");
+ EXPECT_GT(ret, 0);
+
+ access = (char*)malloc(sizeof(char) * 10);
+
+ ret = snprintf(access, 10, "%s", "readwrite");
+ EXPECT_GT(ret, 0);
+
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_appinfo_usr_get_datacontrol_info(
+ _, _, _, _, _)).
+ WillOnce(DoAll(SetArgPointee<3>(app_id),
+ SetArgPointee<4>(access),
+ Return(PMINFO_R_OK)));
+
+ ret = data_control_map_register_response_cb(provider, map_cb, NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ EXPECT_CALL(GetMock<CynaraMock>(),
+ cynara_initialize(_, _)).
+ WillOnce(Return(CYNARA_API_SUCCESS));
+
+ EXPECT_CALL(GetMock<CynaraMock>(),
+ cynara_check(_, _, _, _, _)).
+ WillOnce(Return(CYNARA_API_ACCESS_ALLOWED)).
+ WillOnce(Return(CYNARA_API_ACCESS_ALLOWED));
+
+ provider_appid = (char*)malloc(sizeof(char) * 11);
+
+ ret = snprintf(provider_appid, 11, "%s", "test_appid");
+ EXPECT_GT(ret, 0);
+
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(
+ _, _, _, _, _)).
+ WillOnce(DoAll(SetArgPointee<3>(provider_appid),
+ SetArgPointee<4>(is_trusted),
+ Return(PMINFO_R_OK)));
+
+ res = PMINFO_CERT_COMPARE_MATCH;
+
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_pkginfo_compare_usr_app_cert_info(_, _, _, _)).
+ WillOnce(DoAll(SetArgPointee<3>(res),
+ Return(PMINFO_R_OK)));
+
+ ret = data_control_map_add(provider, "test_key", "test_value", &req_id);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_get(provider, "test_key", &req_id);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_get_with_page(provider, "test_key", &req_id, 1, 20);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_set(provider, "test_key",
+ "test_value", "new_value", &req_id);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_remove(provider, "test_key", "test_value", &req_id);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_bulk_data_create(&bulk_data_h);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ b.Add(std::string("testkey"), std::string("testvalue"));
+
+ ret = data_control_bulk_data_add(bulk_data_h, b.GetHandle());
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_add_bulk_data(provider, bulk_data_h, &req_id);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_bulk_data_destroy(bulk_data_h);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ app_id = (char*)malloc(sizeof(char) * 11);
+
+ ret = snprintf(app_id, 11, "%s", "test_appid");
+ EXPECT_GT(ret, 0);
+
+ access = (char*)malloc(sizeof(char) * 10);
+
+ ret = snprintf(access, 10, "%s", "readwrite");
+ EXPECT_GT(ret, 0);
+
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_appinfo_usr_get_datacontrol_info(
+ _, _, _, _, _)).
+ WillOnce(DoAll(SetArgPointee<3>(app_id),
+ SetArgPointee<4>(access),
+ Return(PMINFO_R_OK)));
+
+ ret = data_control_map_register_add_bulk_data_response_cb(
+ provider, _data_control_bulk_cb, NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_unregister_add_bulk_data_response_cb(provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_unregister_response_cb(provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_destroy(provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+TEST_F(DataControlMapTest, map_bind_unbind_test) {
+ int ret;
+ char* access;
+ char* app_id;
+ data_control_h provider;
+ data_control_map_response_cb* map_cb;
+
+ ret = data_control_map_create(&provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_set_provider_id(provider, "test_providerid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_set_data_id(provider, "test_dataid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ map_cb = (data_control_map_response_cb*)malloc(sizeof(data_control_map_response_cb));
+ ASSERT_NE(map_cb, nullptr);
+
+ map_cb->get_cb = _data_control_map_get_response_cb;
+ map_cb->set_cb = _data_control_map_set_response_cb;
+ map_cb->add_cb = _data_control_map_add_response_cb;
+ map_cb->remove_cb = _data_control_map_remove_response_cb;
+
+ app_id = (char*)malloc(sizeof(char) * 11);
+
+ ret = snprintf(app_id, 11, "%s", "test_appid");
+ EXPECT_GT(ret, 0);
+
+ access = (char*)malloc(sizeof(char) * 10);
+
+ ret = snprintf(access, 10, "%s", "readwrite");
+ EXPECT_GT(ret, 0);
+
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_appinfo_usr_get_datacontrol_info(
+ _, _, _, _, _)).
+ WillOnce(DoAll(SetArgPointee<3>(app_id),
+ SetArgPointee<4>(access),
+ Return(PMINFO_R_OK)));
+
+ ret = data_control_map_bind_response_cb(provider, map_cb, NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_unbind_response_cb(provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_destroy(provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+TEST_F(DataControlMapTest, map_bind_unbind_bulk_cb_test) {
+ int ret;
+ char* access;
+ char* app_id;
+ data_control_h provider;
+
+ ret = data_control_map_create(&provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_set_provider_id(provider, "test_providerid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_set_data_id(provider, "test_dataid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ app_id = (char*)malloc(sizeof(char) * 11);
+
+ ret = snprintf(app_id, 11, "%s", "test_appid");
+ EXPECT_GT(ret, 0);
+
+ access = (char*)malloc(sizeof(char) * 10);
+
+ ret = snprintf(access, 10, "%s", "readwrite");
+ EXPECT_GT(ret, 0);
+
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_appinfo_usr_get_datacontrol_info(
+ _, _, _, _, _)).
+ WillOnce(DoAll(SetArgPointee<3>(app_id),
+ SetArgPointee<4>(access),
+ Return(PMINFO_R_OK)));
+
+ ret = data_control_map_bind_add_bulk_data_response_cb(provider,
+ _data_control_bulk_cb, NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_unbind_add_bulk_data_response_cb(provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_destroy(provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <gtest/gtest.h>
+#include <stdio.h>
+#include <bundle.h>
+
+#include <memory>
+
+#include "data_control.h"
+#include "unistd_mock.h"
+#include "pkgmgr_info_mock.h"
+#include "cynara_mock.h"
+#include "appsvc_mock.h"
+#include "gio_mock.h"
+#include "test_fixture.h"
+
+using ::testing::_;
+using ::testing::DoAll;
+using ::testing::Return;
+using ::testing::SetArgPointee;
+
+class Mocks : public ::testing::NiceMock<PkgmgrInfoMock>,
+ public ::testing::NiceMock<CynaraMock>,
+ public ::testing::NiceMock<AppSvcMock>,
+ public ::testing::NiceMock<GioMock>,
+ public ::testing::NiceMock<UnistdMock> {};
+
+class DataControlNotiTest : public TestFixture {
+ public:
+ DataControlNotiTest() : TestFixture(std::make_unique<Mocks>()) {}
+ virtual ~DataControlNotiTest() {}
+
+ virtual void SetUp() {
+ }
+
+ virtual void TearDown() {
+ }
+};
+
+void _data_control_data_change_cb(data_control_h provider,
+ data_control_data_change_type_e type, bundle* data, void* user_data) {
+}
+
+void _data_control_add_callback_result_cb(data_control_h provider,
+ data_control_error_e result, int callback_id, void* user_data) {
+}
+
+TEST_F(DataControlNotiTest, noti_test) {
+ int ret;
+ int callback_id;
+ char* app_id;
+ data_control_h provider;
+
+ ret = data_control_map_create(&provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_set_provider_id(provider, "test_providerid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_set_data_id(provider, "test_dataid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ EXPECT_CALL(GetMock<GioMock>(),
+ g_dbus_connection_signal_subscribe(
+ _, _, _, _, _, _, _, _, _, _)).
+ WillOnce(Return(99));
+
+ app_id = (char*)malloc(sizeof(char) * 11);
+
+ ret = snprintf(app_id, 11, "%s", "test_appid");
+ EXPECT_GT(ret, 0);
+
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_appinfo_usr_get_datacontrol_info(
+ _, _, _, _, _)).
+ WillOnce(DoAll(SetArgPointee<3>(app_id),
+ Return(PMINFO_R_OK)));
+
+ ret = data_control_add_data_change_cb(provider, _data_control_data_change_cb, NULL,
+ _data_control_add_callback_result_cb, NULL, &callback_id);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_remove_data_change_cb(provider, callback_id);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_destroy(provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <gtest/gtest.h>
+#include <stdio.h>
+#include <bundle.h>
+#include <bundle_cpp.h>
+#include <glib.h>
+
+#include <memory>
+
+#include "data_control.h"
+#include "data_control_provider_internal.h"
+#include "unistd_mock.h"
+#include "pkgmgr_info_mock.h"
+#include "cynara_mock.h"
+#include "appsvc_mock.h"
+#include "gio_mock.h"
+#include "test_fixture.h"
+
+using namespace tizen_base;
+using ::testing::_;
+using ::testing::DoAll;
+using ::testing::Return;
+using ::testing::SetArgPointee;
+
+class Mocks : public ::testing::NiceMock<PkgmgrInfoMock>,
+ public ::testing::NiceMock<CynaraMock>,
+ public ::testing::NiceMock<AppSvcMock>,
+ public ::testing::NiceMock<GioMock>,
+ public ::testing::NiceMock<UnistdMock> {};
+
+class DataControlProviderTest : public TestFixture {
+ public:
+ DataControlProviderTest() : TestFixture(std::make_unique<Mocks>()) {}
+ virtual ~DataControlProviderTest() {}
+
+ virtual void SetUp() {
+ }
+
+ virtual void TearDown() {
+ }
+};
+
+void _data_control_provider_sql_insert_request_cb(int request_id,
+ data_control_h provider, bundle* insert_data, void* user_data) {
+}
+
+void _data_control_provider_sql_update_request_cb(int request_id,
+ data_control_h provider, bundle* update_data,
+ const char* where, void* user_data) {
+}
+
+void _data_control_provider_sql_delete_request_cb(int request_id,
+ data_control_h provider, const char* where, void* user_data) {
+}
+
+void _data_control_provider_sql_select_request_cb(int request_id,
+ data_control_h provider, const char** column_list, int column_count,
+ const char* where, const char* order, void* user_data) {
+}
+
+void _data_control_provider_map_get_value_request_cb(int request_id,
+ data_control_h provider, const char* key, void* user_data) {
+}
+
+void _data_control_provider_map_set_value_request_cb(int request_id,
+ data_control_h provider, const char* key, const char* old_value,
+ const char* new_value, void* user_data) {
+}
+
+void _data_control_provider_map_add_value_request_cb(int request_id,
+ data_control_h provider, const char* key,
+ const char* value, void* user_data) {
+}
+
+void _data_control_provider_map_remove_value_request_cb(int request_id,
+ data_control_h provider, const char* key,
+ const char* value, void* user_data) {
+}
+
+extern GIOFunc __io_func;
+extern gpointer __io_data;
+extern data_control_provider_handler_fn __cb;
+
+TEST_F(DataControlProviderTest, provider_register_map_cb_test) {
+ int ret;
+ data_control_provider_map_cb* map_cb;
+
+ map_cb = (data_control_provider_map_cb*) malloc(sizeof(data_control_provider_map_cb));
+ map_cb->get_cb = _data_control_provider_map_get_value_request_cb;
+ map_cb->set_cb = _data_control_provider_map_set_value_request_cb;
+ map_cb->add_cb = _data_control_provider_map_add_value_request_cb;
+ map_cb->remove_cb = _data_control_provider_map_remove_value_request_cb;
+
+ ret = data_control_provider_map_register_cb(map_cb, NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ free(map_cb);
+
+ ret = data_control_provider_map_unregister_cb();
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+TEST_F(DataControlProviderTest, provider_create_statement_test) {
+ int ret;
+ char *sql = nullptr;
+ Bundle b;
+ Bundle update_b;
+ data_control_h provider;
+
+ ret = data_control_sql_create(&provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_set_provider_id(provider, "test_providerid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_set_data_id(provider, "test_dataid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ b.Add(std::string("testkey"), std::string("testvalue"));
+
+ sql = data_control_provider_create_insert_statement(provider, b.GetHandle());
+ EXPECT_NE(sql, nullptr);
+ free(sql);
+ sql = nullptr;
+
+ sql = data_control_provider_create_delete_statement(provider, "test_location");
+ EXPECT_NE(sql, nullptr);
+ free(sql);
+ sql = nullptr;
+
+ update_b.Add(std::string("testkey"), std::string("testvalue"));
+
+ sql = data_control_provider_create_update_statement(provider,
+ update_b.GetHandle(), "test_location");
+ EXPECT_NE(sql, nullptr);
+ free(sql);
+ sql = nullptr;
+
+ sql = data_control_provider_create_select_statement(provider, NULL, 0,
+ "test_location", "test_order");
+ EXPECT_NE(sql, nullptr);
+ free(sql);
+
+ ret = data_control_sql_destroy(provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+TEST_F(DataControlProviderTest, provider_match_test) {
+ int ret;
+ bool is_match = false;
+ data_control_h provider;
+
+ ret = data_control_sql_create(&provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_set_provider_id(provider, "test_providerid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_set_data_id(provider, "test_dataid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ is_match = data_control_provider_match_provider_id(provider, "test_providerid");
+ EXPECT_TRUE(is_match);
+
+ is_match = false;
+
+ is_match = data_control_provider_match_data_id(provider, "test_dataid");
+ EXPECT_TRUE(is_match);
+
+ ret = data_control_sql_destroy(provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+bool _data_control_provider_data_change_consumer_filter_cb(data_control_h provider,
+ char *consumer_appid, void *user_data) {
+ return true;
+}
+
+TEST_F(DataControlProviderTest, provider_add_remove_cb_test) {
+ int ret;
+ int callback_id;
+
+ ret = data_control_provider_add_data_change_consumer_filter_cb(
+ _data_control_provider_data_change_consumer_filter_cb,
+ NULL, &callback_id);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_provider_remove_data_change_consumer_filter_cb(callback_id);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+TEST_F(DataControlProviderTest, provider_send_result_test_n) {
+ int ret;
+ Bundle b;
+ data_control_bulk_result_data_h result_data_h;
+
+ ret = data_control_bulk_result_data_create(&result_data_h);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ b.Add(std::string("testkey"), std::string("testvalue"));
+
+ ret = data_control_bulk_result_data_add(result_data_h, b.GetHandle(),
+ DATA_CONTROL_ERROR_NONE);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_provider_send_bulk_insert_result(99, result_data_h);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_INVALID_PARAMETER);
+
+ ret = data_control_provider_send_map_bulk_add_result(99, result_data_h);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_INVALID_PARAMETER);
+
+ ret = data_control_bulk_result_data_destroy(result_data_h);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+void _data_control_provider_bulk_cb(int request_id,
+ data_control_h provider, data_control_bulk_data_h bulk_data,
+ void *user_data) {
+}
+
+TEST_F(DataControlProviderTest, provider_sql_register_unregister_cb_test) {
+ int ret;
+
+ ret = data_control_provider_sql_register_insert_bulk_data_request_cb(
+ _data_control_provider_bulk_cb, NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_provider_sql_unregister_insert_bulk_data_request_cb();
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+TEST_F(DataControlProviderTest, provider_map_register_unregister_cb_test) {
+ int ret;
+
+ ret = data_control_provider_map_register_add_bulk_data_request_cb(
+ _data_control_provider_bulk_cb, NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_provider_map_unregister_add_bulk_data_request_cb();
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+TEST_F(DataControlProviderTest, provider_send_noti_test) {
+ int ret;
+ Bundle b;
+ data_control_h provider;
+
+ ret = data_control_map_create(&provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_set_provider_id(provider, "test_providerid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_set_data_id(provider, "test_dataid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ b.Add(std::string("testkey"), std::string("testvalue"));
+
+ ret = data_control_provider_send_data_change_noti(provider,
+ DATA_CONTROL_DATA_CHANGE_MAP_SET, b.GetHandle());
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_destroy(provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+bool _data_control_provider_data_change_consumer_cb(data_control_h provider,
+ char *consumer_appid, void *user_data) {
+ return true;
+}
+
+TEST_F(DataControlProviderTest, provider_data_change_test) {
+ int ret;
+ data_control_h provider;
+
+ ret = data_control_map_create(&provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_set_provider_id(provider, "test_providerid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_set_data_id(provider, "test_dataid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_provider_foreach_data_change_consumer(provider,
+ _data_control_provider_data_change_consumer_cb, NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_map_destroy(provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+void _register_sql_cb() {
+ int ret;
+ Bundle b;
+ data_control_provider_sql_cb* sql_cb;
+
+ sql_cb = (data_control_provider_sql_cb*) malloc(sizeof(data_control_provider_sql_cb));
+ sql_cb->select_cb = _data_control_provider_sql_select_request_cb;
+ sql_cb->insert_cb = _data_control_provider_sql_insert_request_cb;
+ sql_cb->delete_cb = _data_control_provider_sql_delete_request_cb;
+ sql_cb->update_cb = _data_control_provider_sql_update_request_cb;
+
+ ret = data_control_provider_sql_register_cb(sql_cb, NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ b.Add(std::string(AUL_K_CALLER_APPID), std::string("caller_appid"));
+ b.Add(std::string(AUL_K_CALLEE_APPID), std::string("callee_appid"));
+
+ __cb(b.GetHandle(), 1, NULL);
+
+ __io_func(nullptr, G_IO_IN, __io_data);
+
+ free(sql_cb);
+
+ ret = data_control_provider_sql_unregister_cb();
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+TEST_F(DataControlProviderTest, provider_send_select_result_test) {
+ int ret;
+ char* provider_appid;
+ char* appid;
+ bool is_trusted = true;
+ bundle* b;
+ pkgmgrinfo_cert_compare_result_type_e res;
+
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(
+ _, _, _, _, _)).
+ WillOnce(DoAll(SetArgPointee<3>(provider_appid),
+ SetArgPointee<4>(is_trusted),
+ Return(PMINFO_R_OK)));
+
+ res = PMINFO_CERT_COMPARE_MATCH;
+
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_pkginfo_compare_usr_app_cert_info(_, _, _, _)).
+ WillOnce(DoAll(SetArgPointee<3>(res),
+ Return(PMINFO_R_OK)));
+
+ _register_sql_cb();
+
+ ret = data_control_provider_get_client_appid(1, &appid);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+ EXPECT_STREQ(appid, "caller_appid");
+
+ b = bundle_create();
+
+ ret = data_control_provider_send_select_result(1, b);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ bundle_free(b);
+}
+
+TEST_F(DataControlProviderTest, provider_send_insert_result_test) {
+ int ret;
+
+ _register_sql_cb();
+
+ ret = data_control_provider_send_insert_result(2, 0);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+TEST_F(DataControlProviderTest, provider_send_update_result_test) {
+ int ret;
+
+ _register_sql_cb();
+
+ ret = data_control_provider_send_update_result(3);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+TEST_F(DataControlProviderTest, provider_send_delete_result_test) {
+ int ret;
+
+ _register_sql_cb();
+
+ ret = data_control_provider_send_delete_result(4);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+TEST_F(DataControlProviderTest, provider_send_error_result_test) {
+ int ret;
+
+ _register_sql_cb();
+
+ ret = data_control_provider_send_error(5, "test_errors");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+TEST_F(DataControlProviderTest, provider_send_map_result_test) {
+ int ret;
+ _register_sql_cb();
+
+ ret = data_control_provider_send_map_result(6);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+TEST_F(DataControlProviderTest, provider_send_map_get_value_result_test) {
+ int ret;
+ char* value_list[2];
+
+ value_list[0] = (char*)"val0";
+ value_list[0] = (char*)"val1";
+
+ _register_sql_cb();
+
+ ret = data_control_provider_send_map_get_value_result(7, value_list, 2);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+TEST_F(DataControlProviderTest, provider_send_select_result_without_data_test) {
+ int ret;
+ int fd;
+
+ _register_sql_cb();
+
+ ret = datacontrol_provider_send_select_result_without_data(8, &fd);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+TEST_F(DataControlProviderTest, provider_get_select_page_info_test) {
+ int ret;
+ int page_num;
+ int count_per_page;
+
+ _register_sql_cb();
+
+ ret = datacontrol_provider_get_select_page_info(9, &page_num, &count_per_page);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
--- /dev/null
+/*
+ * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <gtest/gtest.h>
+#include <stdio.h>
+#include <bundle.h>
+#include <bundle_cpp.h>
+#include <glib.h>
+
+#include <memory>
+
+#include "data_control.h"
+#include "data_control_internal.h"
+#include "unistd_mock.h"
+#include "pkgmgr_info_mock.h"
+#include "cynara_mock.h"
+#include "appsvc_mock.h"
+#include "gio_mock.h"
+#include "test_fixture.h"
+
+using namespace tizen_base;
+using ::testing::_;
+using ::testing::DoAll;
+using ::testing::Return;
+using ::testing::SetArgPointee;
+
+class Mocks : public ::testing::NiceMock<PkgmgrInfoMock>,
+ public ::testing::NiceMock<CynaraMock>,
+ public ::testing::NiceMock<AppSvcMock>,
+ public ::testing::NiceMock<GioMock>,
+ public ::testing::NiceMock<UnistdMock> {};
+
+class DataControlSqlTest : public TestFixture {
+ public:
+ DataControlSqlTest() : TestFixture(std::make_unique<Mocks>()) {}
+ virtual ~DataControlSqlTest() {}
+
+ virtual void SetUp() {
+ }
+
+ virtual void TearDown() {
+ }
+};
+
+void _data_control_sql_insert_response_cb(int request_id,
+ data_control_h provider, long long inserted_row_id,
+ bool provider_result, const char* error, void* user_data) {
+}
+
+void _data_control_sql_delete_response_cb(int request_id,
+ data_control_h provider, bool provider_result,
+ const char* error, void* user_data) {
+}
+
+void _data_control_sql_select_response_cb(int request_id,
+ data_control_h provider, result_set_cursor enumerator,
+ bool provider_result, const char* error, void* user_data) {
+}
+
+void _data_control_sql_update_response_cb(int request_id,
+ data_control_h provider, bool provider_result,
+ const char* error, void* user_data) {
+}
+
+void _data_control_sql_bulk_cb(int request_id, data_control_h provider,
+ data_control_bulk_result_data_h bulk_results, bool provider_result,
+ const char* error, void* user_data) {
+}
+
+TEST_F(DataControlSqlTest, sql_test) {
+ int ret;
+ int req_id;
+ int handle_id = 0;
+ char* provider_id = nullptr;
+ char* data_id = nullptr;
+ char* app_id;
+ char* access;
+ char* provider_appid;
+ char* column_list[5];
+ data_control_h provider;
+ Bundle b;
+ Bundle update_b;
+ Bundle bulk_b;
+ data_control_bulk_data_h bulk_data_h;
+ data_control_sql_response_cb* sql_cb;
+
+ bool is_trusted = true;
+ pkgmgrinfo_cert_compare_result_type_e res;
+
+ ret = data_control_sql_create(&provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_set_provider_id(provider, "test_providerid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_get_provider_id(provider, &provider_id);
+ EXPECT_STREQ(provider_id, "test_providerid");
+
+ free(provider_id);
+
+ ret = data_control_sql_set_data_id(provider, "test_dataid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_get_data_id(provider, &data_id);
+ EXPECT_STREQ(data_id, "test_dataid");
+
+ free(data_id);
+
+ sql_cb = (data_control_sql_response_cb*)malloc(sizeof(data_control_sql_response_cb));
+ ASSERT_NE(sql_cb, nullptr);
+
+ sql_cb->select_cb = _data_control_sql_select_response_cb;
+ sql_cb->insert_cb = _data_control_sql_insert_response_cb;
+ sql_cb->update_cb = _data_control_sql_update_response_cb;
+ sql_cb->delete_cb = _data_control_sql_delete_response_cb;
+
+ app_id = (char*)malloc(sizeof(char) * 11);
+
+ ret = snprintf(app_id, 11, "%s", "test_appid");
+ EXPECT_GT(ret, 0);
+
+ access = (char*)malloc(sizeof(char) * 10);
+
+ ret = snprintf(access, 10, "%s", "readwrite");
+ EXPECT_GT(ret, 0);
+
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_appinfo_usr_get_datacontrol_info(
+ _, _, _, _, _)).
+ WillOnce(DoAll(SetArgPointee<3>(app_id),
+ SetArgPointee<4>(access),
+ Return(PMINFO_R_OK)));
+
+ ret = data_control_sql_register_response_cb(provider, sql_cb, NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ free(sql_cb);
+
+ provider_appid = (char*)malloc(sizeof(char) * 11);
+
+ ret = snprintf(provider_appid, 11, "%s", "test_appid");
+ EXPECT_GT(ret, 0);
+
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_appinfo_usr_get_datacontrol_trusted_info(
+ _, _, _, _, _)).
+ WillOnce(DoAll(SetArgPointee<3>(provider_appid),
+ SetArgPointee<4>(is_trusted),
+ Return(PMINFO_R_OK)));
+
+ res = PMINFO_CERT_COMPARE_MATCH;
+
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_pkginfo_compare_usr_app_cert_info(_, _, _, _)).
+ WillOnce(DoAll(SetArgPointee<3>(res),
+ Return(PMINFO_R_OK)));
+
+ b.Add(std::string("testkey"), std::string("testvalue"));
+
+ ret = data_control_sql_insert(provider, b.GetHandle(), &req_id);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ column_list[0] = (char*)"col0";
+ column_list[1] = (char*)"col1";
+ column_list[2] = (char*)"col2";
+ column_list[3] = (char*)"col3";
+ column_list[4] = (char*)"col4";
+
+ ret = data_control_sql_select(provider, column_list, 1,
+ NULL, NULL, &req_id);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_select_with_page(provider, column_list, 1,
+ NULL, NULL, 1, 20, &req_id);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ update_b.Add(std::string("testkey"), std::string("newvalue"));
+
+ ret = data_control_sql_update(provider, update_b.GetHandle(), "testkey = newvalue", &req_id);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_delete(provider, NULL, &req_id);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_bulk_data_create(&bulk_data_h);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ bulk_b.Add(std::string("testkey"), std::string("testvalue"));
+
+ ret = data_control_bulk_data_add(bulk_data_h, b.GetHandle());
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_insert_bulk_data(provider, bulk_data_h, &req_id);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_bulk_data_destroy(bulk_data_h);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ app_id = (char*)malloc(sizeof(char) * 11);
+
+ ret = snprintf(app_id, 11, "%s", "test_appid");
+ EXPECT_GT(ret, 0);
+
+ access = (char*)malloc(sizeof(char) * 10);
+
+ ret = snprintf(access, 10, "%s", "readwrite");
+ EXPECT_GT(ret, 0);
+
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_appinfo_usr_get_datacontrol_info(
+ _, _, _, _, _)).
+ WillOnce(DoAll(SetArgPointee<3>(app_id),
+ SetArgPointee<4>(access),
+ Return(PMINFO_R_OK)));
+
+ ret = data_control_sql_register_insert_bulk_data_response_cb(provider,
+ _data_control_sql_bulk_cb, NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_unregister_insert_bulk_data_response_cb(provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_unregister_response_cb(provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_get_handle_id(provider, &handle_id);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+ EXPECT_NE(handle_id, 0);
+
+ ret = data_control_sql_destroy(provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+TEST_F(DataControlSqlTest, sql_bind_unbind_cb_test) {
+ int ret;
+ char* app_id;
+ char* access;
+ data_control_h provider;
+ data_control_sql_response_cb* sql_cb;
+
+ ret = data_control_sql_create(&provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_set_provider_id(provider, "test_providerid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_set_data_id(provider, "test_dataid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ sql_cb = (data_control_sql_response_cb*)malloc(sizeof(data_control_sql_response_cb));
+ ASSERT_NE(sql_cb, nullptr);
+
+ sql_cb->select_cb = _data_control_sql_select_response_cb;
+ sql_cb->insert_cb = _data_control_sql_insert_response_cb;
+ sql_cb->update_cb = _data_control_sql_update_response_cb;
+ sql_cb->delete_cb = _data_control_sql_delete_response_cb;
+
+ app_id = (char*)malloc(sizeof(char) * 11);
+
+ ret = snprintf(app_id, 11, "%s", "test_appid");
+ EXPECT_GT(ret, 0);
+
+ access = (char*)malloc(sizeof(char) * 10);
+
+ ret = snprintf(access, 10, "%s", "readwrite");
+ EXPECT_GT(ret, 0);
+
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_appinfo_usr_get_datacontrol_info(
+ _, _, _, _, _)).
+ WillOnce(DoAll(SetArgPointee<3>(app_id),
+ SetArgPointee<4>(access),
+ Return(PMINFO_R_OK)));
+
+ ret = data_control_sql_bind_response_cb(provider, sql_cb, NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_unbind_response_cb(provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_destroy(provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+TEST_F(DataControlSqlTest, sql_bind_unbind_bulk_cb_test) {
+ int ret;
+ char* app_id;
+ char* access;
+ data_control_h provider;
+
+ ret = data_control_sql_create(&provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_set_provider_id(provider, "test_providerid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_set_data_id(provider, "test_dataid");
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ app_id = (char*)malloc(sizeof(char) * 11);
+
+ ret = snprintf(app_id, 11, "%s", "test_appid");
+ EXPECT_GT(ret, 0);
+
+ access = (char*)malloc(sizeof(char) * 10);
+
+ ret = snprintf(access, 10, "%s", "readwrite");
+ EXPECT_GT(ret, 0);
+
+ EXPECT_CALL(GetMock<PkgmgrInfoMock>(),
+ pkgmgrinfo_appinfo_usr_get_datacontrol_info(
+ _, _, _, _, _)).
+ WillOnce(DoAll(SetArgPointee<3>(app_id),
+ SetArgPointee<4>(access),
+ Return(PMINFO_R_OK)));
+
+ ret = data_control_sql_bind_insert_bulk_data_response_cb(provider,
+ _data_control_sql_bulk_cb, NULL);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_unbind_insert_bulk_data_response_cb(provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_destroy(provider);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+TEST_F(DataControlSqlTest, sql_sql_step_test) {
+ int ret;
+ char name[32] = {0,};
+ result_set_cursor cursor;
+ data_control_sql_column_type_e type;
+ resultset_cursor* _cursor = NULL;
+
+ _cursor = (resultset_cursor*)malloc(sizeof(resultset_cursor));
+ _cursor->resultset_fd = 99;
+ _cursor->resultset_current_offset = 99;
+ _cursor->resultset_content_offset = 11;
+ _cursor->resultset_current_row_count = 0;
+ _cursor->resultset_row_count = 5;
+ _cursor->resultset_col_count = 1;
+
+ _cursor->row_offset_list = (off_t *)calloc(5, sizeof(off_t));
+ _cursor->row_offset_list[0] = 11;
+ _cursor->row_offset_list[1] = 22;
+ _cursor->row_offset_list[2] = 33;
+ _cursor->row_offset_list[3] = 44;
+ _cursor->row_offset_list[4] = 55;
+
+ cursor = (result_set_cursor)_cursor;
+
+ ret = data_control_sql_step_first(cursor);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_step_next(cursor);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_step_last(cursor);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_step_previous(cursor);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_get_column_count(cursor);
+ EXPECT_EQ(ret, 1);
+
+ ret = data_control_sql_get_column_name(cursor, 1, name);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ ret = data_control_sql_get_column_item_size(cursor, 1);
+ EXPECT_EQ(ret, 4);
+
+ ret = data_control_sql_get_column_item_type(cursor, 1, &type);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ free(_cursor->row_offset_list);
+ free(_cursor);
+}
+
+TEST_F(DataControlSqlTest, sql_sql_get_blob_data_test) {
+ int ret;
+ char buf[32] = {0,};
+ result_set_cursor cursor;
+ resultset_cursor* _cursor = NULL;
+
+ _cursor = (resultset_cursor*)malloc(sizeof(resultset_cursor));
+ _cursor->resultset_fd = DATA_CONTROL_SQL_COLUMN_TYPE_BLOB * 1000;
+
+ cursor = (result_set_cursor)_cursor;
+
+ ret = data_control_sql_get_blob_data(cursor, 1, buf, 10);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ free(_cursor);
+}
+
+TEST_F(DataControlSqlTest, sql_sql_get_int_data_test) {
+ int ret;
+ int data;
+ result_set_cursor cursor;
+ resultset_cursor* _cursor = NULL;
+
+ _cursor = (resultset_cursor*)malloc(sizeof(resultset_cursor));
+ _cursor->resultset_fd = DATA_CONTROL_SQL_COLUMN_TYPE_INT64 * 1000;
+
+ cursor = (result_set_cursor)_cursor;
+
+ ret = data_control_sql_get_int_data(cursor, 1, &data);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ free(_cursor);
+}
+
+TEST_F(DataControlSqlTest, sql_sql_get_int64_data_test) {
+ int ret;
+ long long int data;
+ result_set_cursor cursor;
+ resultset_cursor* _cursor = NULL;
+
+ _cursor = (resultset_cursor*)malloc(sizeof(resultset_cursor));
+ _cursor->resultset_fd = DATA_CONTROL_SQL_COLUMN_TYPE_INT64 * 1000;
+
+ cursor = (result_set_cursor)_cursor;
+
+ ret = data_control_sql_get_int64_data(cursor, 1, &data);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ free(_cursor);
+}
+
+TEST_F(DataControlSqlTest, sql_sql_get_double_data_test) {
+ int ret;
+ double data;
+ result_set_cursor cursor;
+ resultset_cursor* _cursor = NULL;
+
+ _cursor = (resultset_cursor*)malloc(sizeof(resultset_cursor));
+ _cursor->resultset_fd = DATA_CONTROL_SQL_COLUMN_TYPE_DOUBLE * 1000;
+
+ cursor = (result_set_cursor)_cursor;
+
+ ret = data_control_sql_get_double_data(cursor, 1, &data);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ free(_cursor);
+}
+
+TEST_F(DataControlSqlTest, sql_sql_get_text_data_test) {
+ int ret;
+ char buf[32] = {0,};
+ result_set_cursor cursor;
+ resultset_cursor* _cursor = NULL;
+
+ _cursor = (resultset_cursor*)malloc(sizeof(resultset_cursor));
+ _cursor->resultset_fd = DATA_CONTROL_SQL_COLUMN_TYPE_TEXT * 1000;
+
+ cursor = (result_set_cursor)_cursor;
+
+ ret = data_control_sql_get_text_data(cursor, 1, buf);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ free(_cursor);
+}