INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR})
INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION include/appfw FILES_MATCHING PATTERN "*.h")
INSTALL(DIRECTORY ./ DESTINATION ${LIB_INSTALL_DIR} FILES_MATCHING PATTERN "*.so*")
+
+IF(NOT DEFINED MINIMUM_BUILD)
+ADD_SUBDIRECTORY(tests)
+ENABLE_TESTING()
+SET(DATA_CONTROL_UNIT_TESTS data_control_unittests)
+ADD_TEST(NAME ${DATA_CONTROL_UNIT_TESTS} COMMAND ${DATA_CONTROL_UNIT_TESTS})
+
+ADD_DEPENDENCIES(${DATA_CONTROL_UNIT_TESTS} data-control)
+ENDIF(NOT DEFINED MINIMUM_BUILD)
BuildRequires: pkgconfig(capi-base-common)
BuildRequires: pkgconfig(cynara-client)
BuildRequires: pkgconfig(sqlite3)
+BuildRequires: pkgconfig(gmock)
+
+%if 0%{?gcov:1}
+BuildRequires: lcov
+BuildRequires: zip
+%endif
# runtime requires
Requires(post): /sbin/ldconfig
%description devel
Data Control library (DEV)
+#################################################
+# data_control_unittests
+#################################################
+%package -n data_control_unittests
+Summary: GTest for Data Control API
+Group: Development/Libraries
+Requires: %{name}
+
+%description -n data_control_unittests
+GTest for data-control API
+
+#################################################
+# gcov
+#################################################
%if 0%{?gcov:1}
%package gcov
Summary: Data Control API(gcov)
find . -name '*.gcno' -exec cp '{}' gcov-obj ';'
%endif
+%check
+ctest -V
+%if 0%{?gcov:1}
+lcov -c --ignore-errors graph --no-external -q -d . -o data_control.info
+genhtml data_control.info -o data_control.out
+zip -r data_control.zip data_control.out
+install -m 0644 data_control.zip %{buildroot}%{_datadir}/gcov/data_control.zip
+%endif
+
%install
rm -rf %{buildroot}
%{_libdir}/pkgconfig/*.pc
%{_libdir}/lib%{name}.so
+#################################################
+# data_control_unittests
+#################################################
+%files -n data_control_unittests
+%{_bindir}/data_control_unittests
+
+#################################################
+# data-control-gcov
+#################################################
%if 0%{?gcov:1}
%files gcov
-%{_datadir}/gcov/obj/*
+%{_datadir}/gcov/*
%endif
--- /dev/null
+ADD_SUBDIRECTORY(unit_tests)
--- /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_MOCK_HOOK_H_
+#define MOCK_MOCK_HOOK_H_
+
+#define MOCK_HOOK_P0(MOCK_CLASS, f) \
+ TestFixture::GetMock<MOCK_CLASS>().f()
+#define MOCK_HOOK_P1(MOCK_CLASS, f, p1) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1)
+#define MOCK_HOOK_P2(MOCK_CLASS, f, p1, p2) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2)
+#define MOCK_HOOK_P3(MOCK_CLASS, f, p1, p2, p3) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3)
+#define MOCK_HOOK_P4(MOCK_CLASS, f, p1, p2, p3, p4) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4)
+#define MOCK_HOOK_P5(MOCK_CLASS, f, p1, p2, p3, p4, p5) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5)
+#define MOCK_HOOK_P6(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5, p6)
+#define MOCK_HOOK_P7(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5, p6, p7)
+#define MOCK_HOOK_P8(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7, p8) \
+ TestFixture::GetMock<MOCK_CLASS>().f(p1, p2, p3, p4, p5, p6, p7, p8)
+#define MOCK_HOOK_P10(MOCK_CLASS, f, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10) \
+ TestFixture::GetMock<MOCK_CLASS>().f( \
+ p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)
+
+#endif // MOCK_MOCK_HOOK_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.
+ */
+
+#ifndef MOCK_MODULE_MOCK_H_
+#define MOCK_MODULE_MOCK_H_
+
+class ModuleMock {
+ public:
+ virtual ~ModuleMock() {}
+};
+
+#endif // MOCK_MODULE_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 "test_fixture.h"
+
+#include <memory>
+
+std::unique_ptr<ModuleMock> TestFixture::mock_;
--- /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_TEST_FIXTURE_H_
+#define MOCK_TEST_FIXTURE_H_
+
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <stdexcept>
+#include <string>
+#include <utility>
+
+#include "module_mock.h"
+
+class TestFixture : public ::testing::Test {
+ public:
+ explicit TestFixture(std::unique_ptr<ModuleMock>&& mock) {
+ mock_ = std::move(mock);
+ }
+ virtual ~TestFixture() {
+ mock_.reset();
+ }
+
+ virtual void SetUp() {}
+ virtual void TearDown() {}
+
+ template <typename T>
+ static T& GetMock() {
+ auto ptr = dynamic_cast<T*>(mock_.get());
+ if (!ptr)
+ throw std::invalid_argument("The test does not provide mock of \"" +
+ std::string(typeid(T).name()) + "\"");
+ return *ptr;
+ }
+
+ static std::unique_ptr<ModuleMock> mock_;
+};
+
+#endif // MOCK_TEST_FIXTURE_H_
--- /dev/null
+CMAKE_MINIMUM_REQUIRED(VERSION 2.8)\r
+PROJECT(data_control_unittests C CXX)\r
+\r
+INCLUDE(FindPkgConfig)\r
+PKG_CHECK_MODULES(data_control_unittests REQUIRED\r
+ gmock\r
+ dlog\r
+ bundle\r
+ glib-2.0\r
+ gio-2.0\r
+ sqlite3\r
+ aul\r
+)\r
+\r
+FOREACH(flag ${data_control_unittests_CFLAGS})\r
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")\r
+ENDFOREACH(flag)\r
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror")\r
+\r
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS} -std=c++14")\r
+SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")\r
+SET(CMAKE_CXX_FLAGS_RELEASE "-O2")\r
+\r
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../include)\r
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../src)\r
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../mock)\r
+\r
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src TEST_SOURCES)\r
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../mock MOCK_SOURCES)\r
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../src LIB_SOURCES)\r
+\r
+ADD_EXECUTABLE(${PROJECT_NAME}\r
+ ${TEST_SOURCES}\r
+ ${LIB_SOURCES}\r
+ ${MOCK_SOURCES}\r
+)\r
+\r
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "${EXTRA_CFLAGS}")\r
+TARGET_LINK_LIBRARIES(${PROJECT_NAME}\r
+ ${data_control_unittests_LDFLAGS}\r
+ data-control\r
+)\r
+\r
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/)\r
--- /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 <memory>
+
+#include "data_control.h"
+#include "test_fixture.h"
+
+using namespace tizen_base;
+
+class Mocks : public virtual ModuleMock {};
+
+class DataControlBulkTest : public TestFixture {
+ public:
+ DataControlBulkTest() : TestFixture(std::make_unique<Mocks>()) {}
+ virtual ~DataControlBulkTest() {}
+
+ virtual void SetUp() {
+ }
+
+ virtual void TearDown() {
+ }
+};
+
+TEST_F(DataControlBulkTest, bulk_data_test) {
+ int ret;
+ bundle* ret_b;
+ Bundle b;
+ int count;
+ char* ret_val;
+ data_control_bulk_data_h bulk_data_h;
+
+ 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_bulk_data_get_count(bulk_data_h, &count);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+ EXPECT_EQ(count, 1);
+
+ ret = data_control_bulk_data_get_data(bulk_data_h, 0, &ret_b);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+
+ bundle_get_str(ret_b, "testkey", &ret_val);
+ EXPECT_STREQ(ret_val, "testvalue");
+
+ ret = data_control_bulk_data_destroy(bulk_data_h);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+}
+
+TEST_F(DataControlBulkTest, buld_result_data_test) {
+ int ret;
+ Bundle b;
+ bundle* ret_b;
+ int count;
+ char* ret_val;
+ int ret_result;
+ 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_bulk_result_data_get_count(result_data_h, &count);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+ EXPECT_EQ(count, 1);
+
+ ret = data_control_bulk_result_data_get_result_data(result_data_h, 0, &ret_b, &ret_result);
+ EXPECT_EQ(ret, DATA_CONTROL_ERROR_NONE);
+ EXPECT_EQ(ret_result, DATA_CONTROL_ERROR_NONE);
+
+ bundle_get_str(ret_b, "testkey", &ret_val);
+ EXPECT_STREQ(ret_val, "testvalue");
+
+ ret = data_control_bulk_result_data_destroy(result_data_h);
+ 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 <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+int main(int argc, char** argv) {
+ int ret = -1;
+
+ try {
+ testing::InitGoogleTest(&argc, argv);
+ } catch(...) {
+ std::cout << "Exception occurred" << std::endl;
+ }
+
+ try {
+ ret = RUN_ALL_TESTS();
+ } catch (const ::testing::internal::GoogleTestFailureException& e) {
+ ret = -1;
+ std::cout << "GoogleTestFailureException was thrown:" << e.what() << std::endl;
+ }
+
+ return ret;
+}