set(CMAKE_SKIP_BUILD_RPATH true)
-ADD_SUBDIRECTORY("pkgmgr_shortcut")
-ADD_SUBDIRECTORY("lib")
+ADD_SUBDIRECTORY(pkgmgr_shortcut)
+ADD_SUBDIRECTORY(lib)
+ADD_SUBDIRECTORY(tests)
BuildRequires: pkgconfig(aul)
BuildRequires: pkgconfig(libtzplatform-config)
BuildRequires: pkgconfig(capi-system-info)
+BuildRequires: pkgconfig(gmock)
+
+%if 0%{?gcov:1}
+BuildRequires: lcov
+BuildRequires: zip
+%endif
%description
[Shortcut] AddToHome feature supporting library for menu/home screen developers.
+%package devel
+Summary: AddToHome feature supporting library development files
+Group: Development/Libraries
+Requires: %{name} = %{version}-%{release}
+
+%description devel
+[Shortcut] AddToHome feature supporting library for menu/home screen developers(dev).
+
+#################################################
+# capi-appfw-app-common-unittests
+#################################################
+%package -n shortcut_unittests
+Summary: GTest for shortcut API
+Group: Development/Libraries
+Requires: %{name}
+
+%description -n shortcut_unittests
+GTest for shortcut API
+
+#################################################
+# gcov
+#################################################
%if 0%{?gcov:1}
%package gcov
Summary: Shortcut API(gcov)
gcov objects of an Shortcut library
%endif
-%package devel
-Summary: AddToHome feature supporting library development files
-Group: Development/Libraries
-Requires: %{name} = %{version}-%{release}
-
-%description devel
-[Shortcut] AddToHome feature supporting library for menu/home screen developers(dev).
-
%prep
%setup -q
cp %{SOURCE1001} .
find . -name '*.gcno' -exec cp '{}' gcov-obj ';'
%endif
+%check
+ctest --output-on-failure %{?_smp_mflags}
+%if 0%{?gcov:1}
+lcov -c --ignore-errors graph --no-external -q -d . -o shortcut.info
+genhtml shortcut.info -o shortcut.out
+zip -r shortcut.zip shortcut.out
+install -m 0644 shortcut.zip %{buildroot}%{_datadir}/gcov/badge.zip
+%endif
+
%install
rm -rf %{buildroot}
%{_libdir}/pkgconfig/shortcut.pc
%{_libdir}/libshortcut.so
+#################################################
+# shortcut_unittests
+#################################################
+%files -n shortcut_unittests
+%{_bindir}/shortcut_unittests
+#################################################
+# gcov
+#################################################
%if 0%{?gcov:1}
%files gcov
-%{_datadir}/gcov/obj/*
+%{_datadir}/gcov/*
%endif
-# End of a file
--- /dev/null
+IF(NOT DEFINED MINIMUM_BUILD)
+ENABLE_TESTING()
+SET(SHORTCUT_UNIT_TESTS shortcut_unittests)
+ADD_TEST(NAME ${SHORTCUT_UNIT_TESTS} COMMAND ${SHORTCUT_UNIT_TESTS})
+
+ADD_SUBDIRECTORY(unit_tests)
+ADD_DEPENDENCIES(${SHORTCUT_UNIT_TESTS} shortcut)
+ENDIF(NOT DEFINED MINIMUM_BUILD)
--- /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 "system_info_mock.h"
+#include "mock_hook.h"
+#include "test_fixture.h"
+
+extern "C" int system_info_get_platform_bool(const char* arg0, bool* arg1) {
+ return MOCK_HOOK_P2(SystemInfoMock, system_info_get_platform_bool, arg0, arg1);
+}
--- /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_SYSTEM_INFO_MOCK_H_
+#define MOCK_SYSTEM_INFO_MOCK_H_
+
+#include <tizen.h>
+#include <gmock/gmock.h>
+
+#include "module_mock.h"
+
+class SystemInfoMock : public virtual ModuleMock {
+ public:
+ virtual ~SystemInfoMock() {}
+
+ MOCK_METHOD2(system_info_get_platform_bool, int(const char*, bool*));
+};
+
+#endif // MOCK_SYSTEM_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 "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(shortcut_unittests C CXX)\r
+\r
+INCLUDE(FindPkgConfig)\r
+PKG_CHECK_MODULES(shortcut_unittests REQUIRED\r
+ gmock\r
+ dlog\r
+ sqlite3\r
+ libxml-2.0\r
+ glib-2.0\r
+ db-util\r
+ vconf\r
+ capi-base-common\r
+ aul\r
+ capi-system-info\r
+ libtzplatform-config\r
+)\r
+\r
+FOREACH(flag ${shortcut_unittests_CFLAGS})\r
+ SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")\r
+ENDFOREACH(flag)\r
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror -Winline")\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}/../../lib/include)\r
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../../lib/src)\r
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../mock)\r
+\r
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SOURCES)\r
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../../lib/src LIB_SOURCES)\r
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../mock MOCK_SOURCES)\r
+\r
+ADD_EXECUTABLE(${PROJECT_NAME}\r
+ ${SOURCES}\r
+ ${MOCK_SOURCES}\r
+ #${LIB_SOURCES}\r
+)\r
+\r
+TARGET_LINK_LIBRARIES(${PROJECT_NAME}\r
+ ${shortcut_unittests_LDFLAGS}\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 <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;
+}
--- /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 <shortcut_manager.h>
+
+#include <memory>
+
+#include "system_info_mock.h"
+#include "test_fixture.h"
+
+using ::testing::_;
+using ::testing::DoAll;
+using ::testing::Return;
+using ::testing::SetArgPointee;
+using ::testing::Invoke;
+
+class Mocks : public ::testing::NiceMock<SystemInfoMock> {};
+
+class ShortcutTest : public TestFixture {
+ public:
+ ShortcutTest() : TestFixture(std::make_unique<Mocks>()) {}
+ virtual ~ShortcutTest() {}
+
+ virtual void SetUp() {
+ }
+
+ virtual void TearDown() {
+ }
+};