CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(rua C)
+PROJECT(rua C CXX)
SET(PREFIX ${CMAKE_INSTALL_PREFIX})
SET(EXEC_PREFIX "\${prefix}")
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -std=c++14 -fPIE")
ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"")
ADD_DEFINITIONS("-DFACTORYFS=\"$ENV{FACTORYFS}\"")
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/rua_context.h DESTINATION include/${PROJECT_NAME})
INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/rua_manager.h DESTINATION include/${PROJECT_NAME})
-ADD_SUBDIRECTORY(test)
+ADD_SUBDIRECTORY(tests)
BuildRequires: pkgconfig(libtzplatform-config)
BuildRequires: pkgconfig(gio-2.0)
BuildRequires: pkgconfig(glib-2.0)
+BuildRequires: pkgconfig(gmock)
BuildRequires: pkgconfig(capi-appfw-app-control)
BuildRequires: pkgconfig(pkgmgr-info)
+%if 0%{?gcov:1}
+BuildRequires: lcov
+BuildRequires: zip
+%endif
+
%description
Recently used application library
cp %{SOURCE1001} .
%build
+%if 0%{?gcov:1}
+export CFLAGS+=" -fprofile-arcs -ftest-coverage"
+export CXXFLAGS+=" -fprofile-arcs -ftest-coverage"
+export FFLAGS+=" -fprofile-arcs -ftest-coverage"
+export LDFLAGS+=" -lgcov"
+%endif
+
MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'`
%cmake -DFULLVER=%{version} \
-DMAJORVER=${MAJORVER} \
make %{?_smp_mflags}
+%if 0%{?gcov:1}
+mkdir -p gcov-obj
+find . -name '*.gcno' -exec cp '{}' gcov-obj ';'
+%endif
+
+%check
+(cd tests && cd unittest && LD_LIBRARY_PATH=../../ ctest -V)
+%if 0%{?gcov:1}
+lcov -c --ignore-errors graph --no-external -q -d . -o rua.info
+genhtml rua.info -o rua.out
+zip -r rua.zip rua.out
+install -m 0644 rua.zip %{buildroot}%{_datadir}/gcov/
+%endif
+
%install
%make_install
+%if 0%{?gcov:1}
+mkdir -p %{buildroot}%{_datadir}/gcov/obj
+install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj
+%endif
+
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%manifest %{name}.manifest
%defattr(-,root,root,-)
%{_bindir}/rua-test
+
+#################################################
+# rua-gcov
+#################################################
+%if 0%{?gcov:1}
+%package gcov
+Summary: Simple string key-val dictionary ADT (gcov)
+Group: Application Framework/Testing
+
+%description gcov
+Simple string key-val dictionary ADT gcov objects
+%endif
+
+%if 0%{?gcov:1}
+%files gcov
+%defattr(-,root,root,-)
+%{_datadir}/gcov/*
+%endif
--- /dev/null
+ADD_SUBDIRECTORY(rua-test)
+ADD_SUBDIRECTORY(unittest)
\ No newline at end of file
--- /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 <aul.h>
+
+#include "mock_hook.h"
+#include "test_fixture.h"
+#include "aul_mock.h"
+
+
+extern "C" int aul_add_rua_history_for_uid(
+ bundle* arg0, uid_t arg1) {
+ return MOCK_HOOK_P2(AulMock, aul_add_rua_history_for_uid, 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 UNIT_TESTS_MOCK_AUL_MOCK_H_
+#define UNIT_TESTS_MOCK_AUL_MOCK_H_
+
+#include <gmock/gmock.h>
+#include <aul.h>
+#include <bundle.h>
+
+#include "module_mock.h"
+
+class AulMock : public virtual ModuleMock {
+ public:
+ virtual ~AulMock() {}
+
+ MOCK_METHOD2(aul_add_rua_history_for_uid, int(bundle*, uid_t));
+
+};
+
+#endif // UNIT_TESTS_MOCK_AUL_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.
+ */
+
+#ifndef UNIT_TESTS_MOCK_MOCK_HOOK_H_
+#define UNIT_TESTS_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 // UNIT_TESTS_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 UNIT_TESTS_MOCK_MODULE_MOCK_H_
+#define UNIT_TESTS_MOCK_MODULE_MOCK_H_
+
+class ModuleMock {
+ public:
+ virtual ~ModuleMock() {}
+};
+
+#endif // UNIT_TESTS_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 UNIT_TESTS_MOCK_TEST_FIXTURE_H_
+#define UNIT_TESTS_MOCK_TEST_FIXTURE_H_
+
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <stdexcept>
+#include <string>
+#include <utility>
+
+#include "module_mock.h"
+#include "test_fixture.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 // UNIT_TESTS_MOCK_TEST_FIXTURE_H_
TARGET_LINK_LIBRARIES(${RUATEST} ${PROJECT_NAME} ${RUATEST_PKGS_LDFLAGS})
INSTALL(TARGETS ${RUATEST} DESTINATION bin)
-
--- /dev/null
+ENABLE_TESTING()
+SET(TARGET_RUA_UNIT_TEST "rua-unit-test")
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/ UNIT_TESTS_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../mock/ UNIT_TESTS_SRCS)
+ADD_EXECUTABLE(${TARGET_RUA_UNIT_TEST}
+ ${UNIT_TESTS_SRCS}
+)
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_RUA_UNIT_TEST} PUBLIC
+ "${CMAKE_CURRENT_SOURCE_DIR}/../../include"
+ "${CMAKE_CURRENT_SOURCE_DIR}/../mock"
+)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(gtest_pkgs REQUIRED gmock)
+
+TARGET_LINK_LIBRARIES(${TARGET_RUA_UNIT_TEST} PUBLIC ${gtest_pkgs_LDFLAGS} ${PROJECT_NAME})
+SET_TARGET_PROPERTIES(${TARGET_RUA_UNIT_TEST} PROPERTIES COMPILE_FLAGS "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_RUA_UNIT_TEST} PROPERTIES LINK_FLAGS "-pie")
+
+ADD_TEST(
+ NAME ${TARGET_RUA_UNIT_TEST}
+ COMMAND ${TARGET_RUA_UNIT_TEST}
+)
--- /dev/null
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by a apache 2.0 license that can be
+// found in the LICENSE file.
+
+#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 <gtest/gtest.h>
+
+#include <rua.h>
+
+#include <string>
+#include <vector>
+
+#include "aul_mock.h"
+#include "test_fixture.h"
+
+using ::testing::_;
+using ::testing::Return;
+
+class Mocks : public ::testing::NiceMock<AulMock>{};
+
+class RuaTest : public TestFixture {
+ public:
+ RuaTest() : TestFixture(std::make_unique<Mocks>()) {}
+ virtual ~RuaTest() {}
+
+ virtual void SetUp() {
+ }
+
+ virtual void TearDown() {
+ }
+};
+
+TEST_F(RuaTest, rua_add_history_for_uid) {
+ EXPECT_CALL(GetMock<AulMock>(),
+ aul_add_rua_history_for_uid(_, _)).
+ WillOnce(Return(0));
+
+ int ret;
+ ret = rua_add_history_for_uid("test", "/app_path", "arg", 5001);
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(RuaTest, rua_delete_history_with_pkgname_N) {
+ int ret;
+ ret = rua_delete_history_with_pkgname("test");
+ EXPECT_NE(ret, 0);
+}
+