summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/ui-app-ambient_unittests/CMakeLists.txt35
-rw-r--r--tests/ui-app-ambient_unittests/main.cc28
-rw-r--r--tests/ui-app-ambient_unittests/mock/aul_mock.cc34
-rw-r--r--tests/ui-app-ambient_unittests/mock/aul_mock.hh38
-rw-r--r--tests/ui-app-ambient_unittests/mock/mock_hook.hh42
-rw-r--r--tests/ui-app-ambient_unittests/mock/module_mock.hh25
-rw-r--r--tests/ui-app-ambient_unittests/mock/test_fixture.cc21
-rw-r--r--tests/ui-app-ambient_unittests/mock/test_fixture.hh53
-rw-r--r--tests/ui-app-ambient_unittests/ui_app_ambient_unittest.cc101
10 files changed, 378 insertions, 0 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
new file mode 100644
index 0000000..9ed63b3
--- /dev/null
+++ b/tests/CMakeLists.txt
@@ -0,0 +1 @@
+ADD_SUBDIRECTORY(ui-app-ambient_unittests)
diff --git a/tests/ui-app-ambient_unittests/CMakeLists.txt b/tests/ui-app-ambient_unittests/CMakeLists.txt
new file mode 100644
index 0000000..417c1be
--- /dev/null
+++ b/tests/ui-app-ambient_unittests/CMakeLists.txt
@@ -0,0 +1,35 @@
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} UNIT_TEST_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/mock MOCK_SRCS)
+
+ADD_EXECUTABLE(${TARGET_UI_APP_AMBIENT_UNITTESTS}
+ ${UNIT_TEST_SRCS}
+ ${MOCK_SRCS})
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_UI_APP_AMBIENT_UNITTESTS} PUBLIC
+ ${CMAKE_CURRENT_SOURCE_DIR}
+ ${CMAKE_CURRENT_SOURCE_DIR}/mock/
+ ${CMAKE_CURRENT_SOURCE_DIR}/../
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../appcore_ui_app_ambient/
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../appcore_ui_app_ambient/include/
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../appcore_ui_app_ambient/src/)
+
+APPLY_PKG_CONFIG(${TARGET_UI_APP_AMBIENT_UNITTESTS} PUBLIC
+ ALARM_SERVICE_DEPS
+ AUL_DEPS
+ BUNDLE_DEPS
+ CAPI_APPFW_APP_COMMON_DEPS
+ DLOG_DEPS
+ GLIB_DEPS
+ GMOCK_DEPS
+)
+
+TARGET_LINK_LIBRARIES(${TARGET_UI_APP_AMBIENT_UNITTESTS} PUBLIC
+ ${TARGET_APPCORE_UI_APP_AMBIENT})
+
+SET_TARGET_PROPERTIES(${TARGET_UI_APP_AMBIENT_UNITTESTS}
+ PROPERTIES COMPILE_FLAGS "-fPIE")
+SET_TARGET_PROPERTIES(${TARGET_UI_APP_AMBIENT_UNITTESTS}
+ PROPERTIES LINK_FLAGS "-pie")
+
+INSTALL(TARGETS ${TARGET_UI_APP_AMBIENT_UNITTESTS} DESTINATION bin)
diff --git a/tests/ui-app-ambient_unittests/main.cc b/tests/ui-app-ambient_unittests/main.cc
new file mode 100644
index 0000000..420cb6a
--- /dev/null
+++ b/tests/ui-app-ambient_unittests/main.cc
@@ -0,0 +1,28 @@
+/*
+ * Copyright (c) 2020 - 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 <gmock/gmock.h>
+#include <gtest/gtest.h>
+
+int main(int argc, char** argv) {
+ try {
+ testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+ } catch (std::exception const &e) {
+ std::cout << "test_main caught exception: " << e.what() << std::endl;
+ return -1;
+ }
+}
diff --git a/tests/ui-app-ambient_unittests/mock/aul_mock.cc b/tests/ui-app-ambient_unittests/mock/aul_mock.cc
new file mode 100644
index 0000000..abcfb71
--- /dev/null
+++ b/tests/ui-app-ambient_unittests/mock/aul_mock.cc
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2021 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 "ui-app-ambient_unittests/mock/aul_mock.hh"
+#include "ui-app-ambient_unittests/mock/mock_hook.hh"
+#include "ui-app-ambient_unittests/mock/test_fixture.hh"
+
+extern "C" int aul_app_get_appid_bypid(int pid, char* appid, int size) {
+ return MOCK_HOOK_P3(AulMock, aul_app_get_appid_bypid, pid, appid, size);
+}
+
+extern "C" int aul_app_com_create(const char* endpoint,
+ aul_app_com_permission_h permission, app_com_cb callback, void* user_data,
+ aul_app_com_connection_h* connection) {
+ return MOCK_HOOK_P5(AulMock, aul_app_com_create, endpoint, permission,
+ callback, user_data, connection);
+}
+
+extern "C" int aul_app_com_send(const char* endpoint, bundle* envelope) {
+ return MOCK_HOOK_P2(AulMock, aul_app_com_send, endpoint, envelope);
+}
diff --git a/tests/ui-app-ambient_unittests/mock/aul_mock.hh b/tests/ui-app-ambient_unittests/mock/aul_mock.hh
new file mode 100644
index 0000000..e7bdd73
--- /dev/null
+++ b/tests/ui-app-ambient_unittests/mock/aul_mock.hh
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2021 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 UI_APP_AMBIENT_UNITTESTS_MOCK_AUL_MOCK_HH_
+#define UI_APP_AMBIENT_UNITTESTS_MOCK_AUL_MOCK_HH_
+
+#include <aul.h>
+#include <aul_app_com.h>
+
+#include <gmock/gmock.h>
+
+#include "ui-app-ambient_unittests/mock/module_mock.hh"
+
+class AulMock : public virtual ModuleMock {
+ public:
+ virtual ~AulMock() {}
+
+ MOCK_METHOD3(aul_app_get_appid_bypid, int (int, char*, int));
+ MOCK_METHOD5(aul_app_com_create,
+ int (const char*, aul_app_com_permission_h, app_com_cb, void*,
+ aul_app_com_connection_h*));
+ MOCK_METHOD2(aul_app_com_send, int (const char*, bundle*));
+};
+
+#endif // UI_APP_AMBIENT_UNITTESTS_MOCK_AUL_MOCK_HH_
diff --git a/tests/ui-app-ambient_unittests/mock/mock_hook.hh b/tests/ui-app-ambient_unittests/mock/mock_hook.hh
new file mode 100644
index 0000000..9758c2c
--- /dev/null
+++ b/tests/ui-app-ambient_unittests/mock/mock_hook.hh
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2021 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 UI_APP_AMBIENT_UNITTESTS_MOCK_MOCK_HOOK_HH_
+#define UI_APP_AMBIENT_UNITTESTS_MOCK_MOCK_HOOK_HH_
+
+#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 // UI_APP_AMBIENT_UNITTESTS_MOCK_MOCK_HOOK_HH_
diff --git a/tests/ui-app-ambient_unittests/mock/module_mock.hh b/tests/ui-app-ambient_unittests/mock/module_mock.hh
new file mode 100644
index 0000000..496325f
--- /dev/null
+++ b/tests/ui-app-ambient_unittests/mock/module_mock.hh
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2021 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 UI_APP_AMBIENT_UNITTESTS_MOCK_MODULE_MOCK_HH_
+#define UI_APP_AMBIENT_UNITTESTS_MOCK_MODULE_MOCK_HH_
+
+class ModuleMock {
+ public:
+ virtual ~ModuleMock() {}
+};
+
+#endif // UI_APP_AMBIENT_UNITTESTS_MOCK_MODULE_MOCK_HH_
diff --git a/tests/ui-app-ambient_unittests/mock/test_fixture.cc b/tests/ui-app-ambient_unittests/mock/test_fixture.cc
new file mode 100644
index 0000000..a5eac53
--- /dev/null
+++ b/tests/ui-app-ambient_unittests/mock/test_fixture.cc
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2021 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 <memory>
+
+#include "ui-app-ambient_unittests/mock/test_fixture.hh"
+
+std::unique_ptr<ModuleMock> TestFixture::mock_;
diff --git a/tests/ui-app-ambient_unittests/mock/test_fixture.hh b/tests/ui-app-ambient_unittests/mock/test_fixture.hh
new file mode 100644
index 0000000..291afec
--- /dev/null
+++ b/tests/ui-app-ambient_unittests/mock/test_fixture.hh
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2021 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 UI_APP_AMBIENT_UNITTESTS_MOCK_TEST_FIXTURE_HH_
+#define UI_APP_AMBIENT_UNITTESTS_MOCK_TEST_FIXTURE_HH_
+
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <stdexcept>
+#include <string>
+#include <utility>
+
+#include "ui-app-ambient_unittests/mock/module_mock.hh"
+
+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 // UI_APP_AMBIENT_UNITTESTS_MOCK_TEST_FIXTURE_HH_
diff --git a/tests/ui-app-ambient_unittests/ui_app_ambient_unittest.cc b/tests/ui-app-ambient_unittests/ui_app_ambient_unittest.cc
new file mode 100644
index 0000000..23249fb
--- /dev/null
+++ b/tests/ui-app-ambient_unittests/ui_app_ambient_unittest.cc
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2020 - 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 <gmock/gmock.h>
+#include <gtest/gtest.h>
+#include <stdio.h>
+#include <ui_app_ambient.h>
+#include <unistd.h>
+
+#include "ui-app-ambient_unittests/mock/aul_mock.hh"
+#include "ui-app-ambient_unittests/mock/test_fixture.hh"
+
+using ::testing::_;
+using ::testing::DoAll;
+using ::testing::Return;
+using ::testing::SetArgPointee;
+using ::testing::Invoke;
+
+namespace {
+
+int fake_aul_app_get_appid_bypid(int pid, char* appid, int size) {
+ return 0;
+}
+
+int fake_aul_app_com_create(const char* endpoint,
+ aul_app_com_permission_h permission, app_com_cb callback, void* user_data,
+ aul_app_com_connection_h* connection) {
+ return 0;
+}
+
+int fake_aul_app_com_send(const char* endpoint, bundle* envelope) {
+ return 0;
+}
+
+} // namespace
+
+class Mocks : public ::testing::NiceMock<AulMock> {};
+
+class UIAppAmbientTest : public TestFixture {
+ public:
+ UIAppAmbientTest() : TestFixture(std::make_unique<Mocks>()) {}
+ virtual ~UIAppAmbientTest() {}
+
+ void SetUp() override {}
+ void TearDown() override {}
+};
+
+TEST_F(UIAppAmbientTest, ui_app_ambient_set_lifecycle_P) {
+ ui_app_ambient_lifecycle_callback_s callback;
+ callback.frame_updated = [](void* user_data) {};
+ callback.ambient_changed =
+ [](ui_app_ambient_state_e state, bundle* data, void* user_data) {
+ printf("state: %d\n", state);
+ };
+
+ EXPECT_CALL(GetMock<AulMock>(), aul_app_com_create(_, _, _, _, _)).
+ WillOnce(Invoke(fake_aul_app_com_create));
+
+ int ret = ui_app_ambient_set_lifecycle(&callback, nullptr);
+ EXPECT_EQ(ret, 0);
+ ui_app_ambient_unset_lifecycle();
+}
+
+TEST_F(UIAppAmbientTest, ui_app_ambient_set_update_period_P) {
+ int ret = ui_app_ambient_set_update_period(UI_APP_AMBIENT_UPDATE_MINUTE);
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(UIAppAmbientTest, ui_app_ambient_get_update_period_P) {
+ ui_app_ambient_update_period_e period;
+ int ret = ui_app_ambient_get_update_period(&period);
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(UIAppAmbientTest, ui_app_ambient_get_update_period_N) {
+ int ret = ui_app_ambient_get_update_period(nullptr);
+ EXPECT_NE(ret, 0);
+}
+
+TEST_F(UIAppAmbientTest, ui_app_ambient_notify_P) {
+ EXPECT_CALL(GetMock<AulMock>(), aul_app_get_appid_bypid(_, _, _)).
+ WillOnce(Invoke(fake_aul_app_get_appid_bypid));
+ EXPECT_CALL(GetMock<AulMock>(), aul_app_com_send(_, _)).
+ WillOnce(Invoke(fake_aul_app_com_send));
+
+ int ret = ui_app_ambient_notify_event(UI_APP_AMBIENT_EVENT_READY, nullptr);
+ EXPECT_EQ(ret, 0);
+}