1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
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);
}
|