INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../widget_viewer_evas/include)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../ambient-viewer/src)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../ambient-viewer/include)
+INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../watch-holder/src)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../unittest/mock)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../)
AUX_SOURCE_DIRECTORY(src SOURCES)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../widget_viewer_evas/src WIDGET_VIEWER_EVAS_SOURCES)
AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../ambient-viewer/src AMBIENT_VIEWER_SOURCES)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/../watch-holder/src WATCH_HOLDER_SOURCES)
ADD_EXECUTABLE(${PROJECT_NAME}
${SOURCES}
${WIDGET_VIEWER_EVAS_SOURCES}
${UNIT_TEST_SOURCES}
${AMBIENT_VIEWER_SOURCES}
+ ${WATCH_HOLDER_SOURCES}
)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${widget-viewer_unittests_LDFLAGS}
gmock
widget_viewer_evas
ambient-viewer
+ watch-holder
)
INSTALL(TARGETS ${PROJECT_NAME} DESTINATION /usr/bin/)
--- /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_APPSVC_H_
+#define MOCK_APPSVC_H_
+
+#include "mock.h"
+#include "appsvc.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+DECLARE_FAKE_VALUE_FUNC(int, appsvc_run_service, bundle*, int, appsvc_res_fn, void*);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* MOCK_APPSVC_H_ */
#include "cynara_mock.h"
#include "evas_mock.h"
#include "aul_mock.h"
+#include "appsvc_mock.h"
#include "widget_service_mock.h"
#include "screen_connector_mock.h"
#include "vconf_mock.h"
/* aul */
DEFINE_FAKE_VALUE_FUNC(int, aul_app_get_appid_bypid, int, char *, int);
DEFINE_FAKE_VALUE_FUNC_VARARG(int, aul_widget_write_log, const char *, const char *, ...);
+
DEFINE_FAKE_VALUE_FUNC(int, aul_app_com_create, const char *,
aul_app_com_permission_h, app_com_cb, void *, aul_app_com_connection_h *);
DEFINE_FAKE_VALUE_FUNC(int, aul_app_com_leave, aul_app_com_connection_h);
DEFINE_FAKE_VALUE_FUNC(int, aul_app_com_send, const char *, bundle *);
+/* appsvc */
+DEFINE_FAKE_VALUE_FUNC(int, appsvc_run_service, bundle*, int, appsvc_res_fn, void*);
+
/* widget_service */
DEFINE_FAKE_VALUE_FUNC(int, widget_service_get_widget_max_count, const char *);
DEFINE_FAKE_VALUE_FUNC(int, widget_instance_create, const char *, char **);
DEFINE_FAKE_VALUE_FUNC(int, vconf_notify_key_changed, const char *,
vconf_callback_fn, void *);
DEFINE_FAKE_VALUE_FUNC(int, vconf_ignore_key_changed,
- const char *, vconf_callback_fn);
+ const char *, vconf_callback_fn);
\ No newline at end of file
-
/*
* Copyright (c) 2020 Samsung Electronics Co., Ltd.
*
extern "C" {
#endif
+
DECLARE_FAKE_VALUE_FUNC(char *, vconf_get_str, const char *);
DECLARE_FAKE_VALUE_FUNC(int, vconf_notify_key_changed, const char *,
vconf_callback_fn, void *);
--- /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_APPSVC_H_
+#define MOCK_APPSVC_H_
+
+#include "mock.h"
+#include "appsvc.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+DECLARE_FAKE_VALUE_FUNC(int, appsvc_run_service, bundle*, int, appsvc_res_fn, void*);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* MOCK_APPSVC_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 <glib.h>
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+#include <watch_holder.hh>
+#include <watch.hh>
+#include <aul_mock.h>
+#include <appsvc_mock.h>
+#include <vconf_mock.h>
+
+using namespace std;
+using namespace tizen_base;
+using namespace watch_holder;
+
+class WatchHolderStub : public WatchHolder {
+ public:
+ WatchHolderStub(Evas_Object* win)
+ : WatchHolder(win) {
+ }
+
+ void OnAmbientChanged(bool enter, Bundle& extra) override {}
+ void OnAmbientEvent(EventType ev, string sender,
+ Bundle extra) override {}
+ void OnAdded(const Watch& watch) override {}
+ void OnUpdated(const Watch& watch) override {}
+ void OnRemoved(const Watch& watch) override {}
+ void OnLaunched(const Watch& watch) override {}
+ void OnDead(const Watch& watch) override {}
+ void OnBound(const Watch& watch) override {}
+};
+
+static int (*__app_com_cb)(const char *endpoint, aul_app_com_result_e result, bundle *envelope, void *user_data);
+static Bundle b;
+static string global_end;
+
+static int __aul_app_get_appid_bypid_fake(int pid, char* appid, int len) {
+ snprintf(appid, len, "%s", "org.tizen.test");
+ return 0;
+}
+
+static int __aul_app_com_create_fake(const char* end, aul_app_com_permission_h permission,
+ app_com_cb cb, void* user_data, aul_app_com_connection_h* conn) {
+ *conn = nullptr;
+ b = Bundle();
+ b.Add("__AUL_APPID__", "appid");
+ b.Add("__AUL_PID__", "111");
+ b.Add("__AUL_IS_FAULT__", "is_fault");
+ b.Add("__AUL_WIDGET_VIEWER__", "fake");
+ b.Add("__AMBIENT_MODE__", "100");
+ b.Add("__APP_AMBIENT_EVENT__", "0");
+ b.Add("__APP_AMBIENT_SENDER__", "sender");
+
+ if(strcmp(end, global_end.c_str()) == 0)
+ __app_com_cb = cb;
+ return 0;
+}
+
+static int __aul_app_com_leave_fake(aul_app_com_connection_h conn) {
+ return 0;
+}
+
+static int __appsvc_run_service_fake(bundle* b, int r, appsvc_res_fn cb, void* data) {
+ return 0;
+}
+
+class WatchHolderTest : public ::testing::Test {
+ public:
+ WatchHolderStub* stub;
+
+ virtual void SetUp() {
+ aul_app_com_create_fake.custom_fake = __aul_app_com_create_fake;
+ aul_app_com_leave_fake.custom_fake = __aul_app_com_leave_fake;
+ aul_app_get_appid_bypid_fake.custom_fake = __aul_app_get_appid_bypid_fake;
+
+ Evas_Object* win = elm_win_add(NULL, "Watch Holder", ELM_WIN_BASIC);
+ stub = new WatchHolderStub(win);
+ }
+ virtual void TearDown() {
+ delete stub;
+ }
+};
+
+TEST_F(WatchHolderTest, CreateInstance) {
+ EXPECT_NE(WatchHolderTest::stub, nullptr);
+}
+
+TEST_F(WatchHolderTest, LaunchWatch) {
+ appsvc_run_service_fake.custom_fake = __appsvc_run_service_fake;
+ string appid("org.tizen.watch");
+ int ret;
+
+ ret = WatchHolderTest::stub->Launch(appid, false, nullptr);
+ EXPECT_NE(ret, -1);
+}
+
+TEST_F(WatchHolderTest, GetStack) {
+ std::list<std::shared_ptr<Watch>> list;
+ list = WatchHolderTest::stub->GetStack();
+ EXPECT_EQ(list.size(), 0);
+}
+
+TEST_F(WatchHolderTest, GetCurrent_N) {
+ EXPECT_EQ(WatchHolderTest::stub->GetCurrent(), nullptr);
+ global_end = "watch.launch";
+}
+
+TEST_F(WatchHolderTest, OnLaunchSignal) {
+ EXPECT_NE(WatchHolderTest::stub, nullptr);
+ __app_com_cb("end", AUL_APP_COM_R_OK, b.GetHandle(), stub);
+ global_end = "watch.dead";
+}
+
+TEST_F(WatchHolderTest, OnDeadSignal) {
+ EXPECT_NE(WatchHolderTest::stub, nullptr);
+ __app_com_cb("end", AUL_APP_COM_R_OK, b.GetHandle(), stub);
+ global_end = "watch.ambientchange";
+}
+
+TEST_F(WatchHolderTest, OnAmbientChangedSignal) {
+ EXPECT_NE(WatchHolderTest::stub, nullptr);
+ __app_com_cb("end", AUL_APP_COM_R_OK, b.GetHandle(), stub);
+ global_end = "aod.ambientevent";
+}
+
+TEST_F(WatchHolderTest, OnReceiveSignal) {
+ EXPECT_NE(WatchHolderTest::stub, nullptr);
+ __app_com_cb("end", AUL_APP_COM_R_OK, b.GetHandle(), stub);
+}
\ 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 <glib.h>
+#include <gtest/gtest.h>
+#include <gmock/gmock.h>
+
+#include <watch_mirror.hh>
+#include <watch.hh>
+#include <vconf_mock.h>
+
+using namespace std;
+using namespace tizen_base;
+using namespace watch_holder;
+
+class WatchMirrorStub : public WatchMirror {
+ public:
+ WatchMirrorStub(Evas_Object* win)
+ : WatchMirror(win) {
+ }
+
+ void OnChanged(const ISharableWatch& watch) override {}
+ void OnAdded(const ISharableWatch& watch) override {}
+ void OnUpdated(const ISharableWatch& watch) override {}
+ void OnRemoved(const ISharableWatch& watch) override {}
+};
+
+static int __vconf_notify_key_changed_fake(const char* key, vconf_callback_fn cb,
+ void* data) {
+ return 0;
+}
+
+static char* __vconf_get_str_fake(const char* key) {
+ bundle_raw* raw;
+ int len;
+ bundle* b = bundle_create();
+ bundle_add_str(b, NOTIFY_CHANGED_EVENT_APPID_KEY, "appid");
+ bundle_add_str(b, NOTIFY_CHANGED_EVENT_RID_KEY, "rid");
+
+ bundle_encode(b, &raw, &len);
+ bundle_free(b);
+ return (char*)raw;
+}
+
+
+class WatchMirrorTest : public ::testing::Test {
+ public:
+ WatchMirrorStub* mirrorstub;
+
+ virtual void SetUp() {
+ Evas_Object* mirwin = elm_win_add(NULL, "Watch Mirror", ELM_WIN_BASIC);
+ mirrorstub = new WatchMirrorStub(mirwin);
+ }
+ virtual void TearDown() {
+ delete mirrorstub;
+ }
+};
+
+ TEST_F(WatchMirrorTest, CreateMirrorInstance) {
+ EXPECT_NE(WatchMirrorTest::mirrorstub, nullptr);
+ }
+
+TEST_F(WatchMirrorTest, MirrorListen) {
+ int ret;
+
+ vconf_notify_key_changed_fake.custom_fake = __vconf_notify_key_changed_fake;
+ vconf_get_str_fake.custom_fake = __vconf_get_str_fake;
+
+ ret = WatchMirrorTest::mirrorstub->Listen();
+ EXPECT_EQ(ret, 0);
+}
+
+TEST_F(WatchMirrorTest, MirrorGetCurrent_N) {
+ shared_ptr<ISharableWatch> sw;
+ sw = WatchMirrorTest::mirrorstub->GetCurrent();
+ EXPECT_EQ(sw, nullptr);
+}