Add font size configuation file
[platform/core/api/system-settings.git] / tests / sst_gtest_err_font.cpp
1 /*
2  * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <string.h>
18 #include <glib.h>
19 #include <gtest/gtest.h>
20 #include <vconf.h>
21 #include <dlfcn.h>
22
23 #include "system_settings.h"
24 #include "mocks/sstt_mock.h"
25
26 extern "C" {
27 #include "sst.h"
28 #include "sst_font.h"
29 #include "sst_vconf.h"
30 #include "sst_interface.h"
31
32 typedef struct __font_size_info {
33         int small;
34         int normal;
35         int large;
36         int huge;
37         int giant;
38 } font_size_info;
39 }
40
41
42 static void* _utils_load_lib()
43 {
44         const char* const path = SETTING_UTILS_SO_FILE_PATH;
45         void *handle = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);
46         if (NULL == handle)
47                 ERR("dlopen(%s) Fail", path);
48
49         return handle;
50 }
51
52 TEST(SstFontTest,loadFontSizeInfoPathERR)
53 {
54         static font_size_info info;
55         void *handle = _utils_load_lib();
56         EXPECT_NE((void*)NULL, handle);
57
58         typedef int (*fn_impl)(font_size_info *info, const char *path);
59         fn_impl load_font_size_info = NULL;
60
61         load_font_size_info = (fn_impl)dlsym(handle, "load_font_size_info");
62         char *error = dlerror();
63         EXPECT_EQ(0, error);
64
65         int ret = load_font_size_info(&info, "/error/asdlfajsdf.json");
66         EXPECT_EQ(0, ret);
67
68 #ifdef TIZEN_WEARABLE
69         EXPECT_EQ(-90, info.small);
70         EXPECT_EQ(-110, info.large);
71 #else
72         EXPECT_EQ(-80, info.small);
73         EXPECT_EQ(-150, info.large);
74 #endif
75         EXPECT_EQ(-100, info.normal);
76         EXPECT_EQ(-190, info.huge);
77         EXPECT_EQ(-250, info.giant);
78
79         dlclose(handle);
80         handle = NULL;
81 }
82
83 TEST(SstFontTest,loadFontSizeInfoInputERR)
84 {
85         void *handle = _utils_load_lib();
86         EXPECT_NE((void*)NULL, handle);
87
88         typedef int (*fn_impl)(font_size_info *info, const char *path);
89         fn_impl load_font_size_info = NULL;
90
91         load_font_size_info = (fn_impl)dlsym(handle, "load_font_size_info");
92         char *error = dlerror();
93         EXPECT_EQ(0, error);
94
95         int ret = load_font_size_info(NULL, "/error/asdlfajsdf.json");
96         EXPECT_NE(0, ret);
97
98         dlclose(handle);
99         handle = NULL;
100 }
101
102 TEST(SstFontTest,loadFontSizeInfoSmallERR)
103 {
104         font_size_info info;
105         void *handle = _utils_load_lib();
106         EXPECT_NE((void*)NULL, handle);
107
108         typedef int (*fn_impl)(font_size_info *info, const char *path);
109         fn_impl load_font_size_info = NULL;
110
111         load_font_size_info = (fn_impl)dlsym(handle, "load_font_size_info");
112         char *error = dlerror();
113         EXPECT_EQ(0, error);
114
115         int ret = load_font_size_info(&info, "tests/res/font_scale_small_error.json");
116         EXPECT_EQ(0, ret);
117
118 #ifdef TIZEN_WEARABLE
119         EXPECT_EQ(-90, info.small);
120         EXPECT_EQ(-110, info.large);
121 #else
122         EXPECT_EQ(-80, info.small);
123         EXPECT_EQ(-150, info.large);
124 #endif
125         EXPECT_EQ(-100, info.normal);
126         EXPECT_EQ(-190, info.huge);
127         EXPECT_EQ(-250, info.giant);
128
129         dlclose(handle);
130         handle = NULL;
131 }
132
133 TEST(SstFontTest,loadFontSizeInfoNormalERR)
134 {
135         font_size_info info;
136         void *handle = _utils_load_lib();
137         EXPECT_NE((void*)NULL, handle);
138
139         typedef int (*fn_impl)(font_size_info *info, const char *path);
140         fn_impl load_font_size_info = NULL;
141
142         load_font_size_info = (fn_impl)dlsym(handle, "load_font_size_info");
143         char *error = dlerror();
144         EXPECT_EQ(0, error);
145
146         int ret = load_font_size_info(&info, "tests/res/font_scale_normal_error.json");
147         EXPECT_EQ(0, ret);
148
149 #ifdef TIZEN_WEARABLE
150         EXPECT_EQ(-90, info.small);
151         EXPECT_EQ(-110, info.large);
152 #else
153         EXPECT_EQ(-80, info.small);
154         EXPECT_EQ(-150, info.large);
155 #endif
156         EXPECT_EQ(-100, info.normal);
157         EXPECT_EQ(-190, info.huge);
158         EXPECT_EQ(-250, info.giant);
159
160         dlclose(handle);
161         handle = NULL;
162 }
163
164 TEST(SstFontTest,loadFontSizeInfoLargeERR)
165 {
166         font_size_info info;
167         void *handle = _utils_load_lib();
168         EXPECT_NE((void*)NULL, handle);
169
170         typedef int (*fn_impl)(font_size_info *info, const char *path);
171         fn_impl load_font_size_info = NULL;
172
173         load_font_size_info = (fn_impl)dlsym(handle, "load_font_size_info");
174         char *error = dlerror();
175         EXPECT_EQ(0, error);
176
177         int ret = load_font_size_info(&info, "tests/res/font_scale_large_error.json");
178         EXPECT_EQ(0, ret);
179
180 #ifdef TIZEN_WEARABLE
181         EXPECT_EQ(-90, info.small);
182         EXPECT_EQ(-110, info.large);
183 #else
184         EXPECT_EQ(-80, info.small);
185         EXPECT_EQ(-150, info.large);
186 #endif
187         EXPECT_EQ(-100, info.normal);
188         EXPECT_EQ(-190, info.huge);
189         EXPECT_EQ(-250, info.giant);
190
191         dlclose(handle);
192         handle = NULL;
193 }
194
195 TEST(SstFontTest,loadFontSizeInfoHugeERR)
196 {
197         font_size_info info;
198         void *handle = _utils_load_lib();
199         EXPECT_NE((void*)NULL, handle);
200
201         typedef int (*fn_impl)(font_size_info *info, const char *path);
202         fn_impl load_font_size_info = NULL;
203
204         load_font_size_info = (fn_impl)dlsym(handle, "load_font_size_info");
205         char *error = dlerror();
206         EXPECT_EQ(0, error);
207
208         int ret = load_font_size_info(&info, "tests/res/font_scale_huge_error.json");
209         EXPECT_EQ(0, ret);
210
211 #ifdef TIZEN_WEARABLE
212         EXPECT_EQ(-90, info.small);
213         EXPECT_EQ(-110, info.large);
214 #else
215         EXPECT_EQ(-80, info.small);
216         EXPECT_EQ(-150, info.large);
217 #endif
218         EXPECT_EQ(-100, info.normal);
219         EXPECT_EQ(-190, info.huge);
220         EXPECT_EQ(-250, info.giant);
221
222         dlclose(handle);
223         handle = NULL;
224 }
225
226 TEST(SstFontTest,loadFontSizeInfoGiantERR)
227 {
228         font_size_info info;
229         void *handle = _utils_load_lib();
230         EXPECT_NE((void*)NULL, handle);
231
232         typedef int (*fn_impl)(font_size_info *info, const char *path);
233         fn_impl load_font_size_info = NULL;
234
235         load_font_size_info = (fn_impl)dlsym(handle, "load_font_size_info");
236         char *error = dlerror();
237         EXPECT_EQ(0, error);
238
239         int ret = load_font_size_info(&info, "tests/res/font_scale_giant_error.json");
240         EXPECT_EQ(0, ret);
241
242 #ifdef TIZEN_WEARABLE
243         EXPECT_EQ(-90, info.small);
244         EXPECT_EQ(-110, info.large);
245 #else
246         EXPECT_EQ(-80, info.small);
247         EXPECT_EQ(-150, info.large);
248 #endif
249         EXPECT_EQ(-100, info.normal);
250         EXPECT_EQ(-190, info.huge);
251         EXPECT_EQ(-250, info.giant);
252
253         dlclose(handle);
254         handle = NULL;
255 }
256