Initialize Tizen 2.3
[framework/api/system-info.git] / TC / testcase / utc_system_info.c
1 /*
2  * Copyright (c) 2011 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
18 #include <tet_api.h>
19 #include <system_info.h>
20
21
22 static void startup(void);
23 static void cleanup(void);
24
25 void (*tet_startup)(void) = startup;
26 void (*tet_cleanup)(void) = cleanup;
27
28
29 #define API_NAME_SYSINFO_ACCESSIBLE "system_info_type_accessible"
30 #define API_NAME_SYSINFO_GOOD_VALUE "system_info_good_value"
31 #define API_NAME_SYSINFO_SUPPORT_CHECK(key) "system_info_support_check_"#key
32
33 /* this is the sting with 2^15 elements, really huge */
34 #define HUGE_STRING_LEN 65536
35
36 /****************************************************************/
37 /* check if all defined types for results are accessible */
38 static void utc_system_info_get_int_p(void);
39 static void utc_system_info_get_int_n(void);
40 static void utc_system_info_get_bool_p(void);
41 static void utc_system_info_get_bool_n(void);
42 static void utc_system_info_get_string_p(void);
43 static void utc_system_info_get_string_n(void);
44 static void utc_system_info_get_double_p(void);
45 static void utc_system_info_get_double_n(void);
46 static void utc_system_info_get_platform_bool(void);
47 static void utc_system_info_get_platform_int(void);
48 static void utc_system_info_get_platform_double(void);
49 static void utc_system_info_get_platform_string(void);
50 static void utc_system_info_get_custom_bool(void);
51 static void utc_system_info_get_custom_int(void);
52 static void utc_system_info_get_custom_double(void);
53 static void utc_system_info_get_custom_string(void);
54 static void utc_system_info_get_internal_value(void);
55
56 /****************************************************************/
57 /* check if all particular informations have reasonable values */
58 static void utc_system_info_model_p(void);
59 static void utc_system_info_tizen_ver_p(void);
60 static void utc_system_info_h_res_p(void);
61 static void utc_system_info_w_res_p(void);
62 static void utc_system_info_platform_name_p(void);
63 static void utc_system_info_platform_ver_p(void);
64 static void utc_system_info_screen_DPI_p(void);
65 static void utc_system_info_core_cpu_arch_p(void);
66 static void utc_system_info_core_freq_p(void);
67 static void utc_system_info_physical_screen_height_p(void);
68 static void utc_system_info_physical_screen_width_p(void);
69 static void utc_system_info_build_string_p(void);
70 static void utc_system_info_build_date_p(void);
71 static void utc_system_info_build_time_p(void);
72 static void utc_system_info_manufacturer_p(void);
73 static void utc_system_info_tethering_support_key_p(void);
74
75 struct tet_testlist tet_testlist[] = {
76         {utc_system_info_get_int_p, 1},
77         {utc_system_info_get_int_n, 1},
78         {utc_system_info_get_bool_p, 1},
79         {utc_system_info_get_bool_n, 1},
80         {utc_system_info_get_string_p, 1},
81         {utc_system_info_get_string_n, 1},
82         {utc_system_info_get_double_p, 1},
83         {utc_system_info_get_double_n, 1},
84         {utc_system_info_model_p, 1},
85         {utc_system_info_tizen_ver_p, 1},
86         {utc_system_info_h_res_p, 1},
87         {utc_system_info_w_res_p, 1},
88         {utc_system_info_platform_name_p, 1},
89         {utc_system_info_platform_ver_p, 1},
90         {utc_system_info_screen_DPI_p, 1},
91         {utc_system_info_core_cpu_arch_p, 1},
92         {utc_system_info_core_freq_p, 1},
93         {utc_system_info_physical_screen_height_p, 1},
94         {utc_system_info_physical_screen_width_p, 1},
95         {utc_system_info_build_string_p, 1},
96         {utc_system_info_build_date_p, 1},
97         {utc_system_info_build_time_p, 1},
98         {utc_system_info_manufacturer_p, 1},
99         {utc_system_info_tethering_support_key_p, 1},
100         {utc_system_info_get_platform_bool, 1},
101         {utc_system_info_get_platform_int, 1},
102         {utc_system_info_get_platform_double, 1},
103         {utc_system_info_get_platform_string, 1},
104         {utc_system_info_get_custom_bool, 1},
105         {utc_system_info_get_custom_int, 1},
106         {utc_system_info_get_custom_double, 1},
107         {utc_system_info_get_custom_string, 1},
108         {utc_system_info_get_internal_value, 1},
109         {NULL, 0},
110 };
111
112 static void startup(void)
113 {
114
115 }
116
117 static void cleanup(void)
118 {
119         /* end of TC */
120 }
121
122 /****************************************************************/
123 /* check if all defined types for results are accessible */
124 static void utc_system_info_get_int_p(void)
125 {
126         int value;
127
128         int retcode = system_info_get_value_int(SYSTEM_INFO_KEY_CAMERA_COUNT, &value);
129
130         if (retcode == SYSTEM_INFO_ERROR_NONE)
131                 dts_pass(API_NAME_SYSINFO_ACCESSIBLE, "passed");
132         else
133                 dts_fail(API_NAME_SYSINFO_ACCESSIBLE, "failed");
134 }
135
136 static void utc_system_info_get_int_n(void)
137 {
138         int retcode = system_info_get_value_int(SYSTEM_INFO_KEY_CAMERA_COUNT, NULL);
139
140         if (retcode != SYSTEM_INFO_ERROR_NONE)
141                 dts_pass(API_NAME_SYSINFO_ACCESSIBLE, "passed");
142         else
143                 dts_fail(API_NAME_SYSINFO_ACCESSIBLE, "failed");
144 }
145
146 static void utc_system_info_get_bool_p(void)
147 {
148         bool value;
149
150         int retcode = system_info_get_value_bool(SYSTEM_INFO_KEY_BLUETOOTH_SUPPORTED, &value);
151
152         if (retcode == SYSTEM_INFO_ERROR_NONE)
153                 dts_pass(API_NAME_SYSINFO_ACCESSIBLE, "passed");
154         else
155                 dts_fail(API_NAME_SYSINFO_ACCESSIBLE, "failed");
156 }
157
158 static void utc_system_info_get_bool_n(void)
159 {
160         int retcode = system_info_get_value_bool(SYSTEM_INFO_KEY_BLUETOOTH_SUPPORTED, NULL);
161
162         if (retcode != SYSTEM_INFO_ERROR_NONE)
163                 dts_pass(API_NAME_SYSINFO_ACCESSIBLE, "passed");
164         else
165                 dts_fail(API_NAME_SYSINFO_ACCESSIBLE, "failed");
166 }
167
168 static void utc_system_info_get_string_p(void)
169 {
170         char *value = NULL;
171
172         int retcode = system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &value);
173
174         if (value) {
175                 free(value);
176         }
177
178         if (retcode == SYSTEM_INFO_ERROR_NONE)
179                 dts_pass(API_NAME_SYSINFO_ACCESSIBLE, "passed");
180         else
181                 dts_fail(API_NAME_SYSINFO_ACCESSIBLE, "failed");
182 }
183
184 static void utc_system_info_get_string_n(void)
185 {
186         int retcode = system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, NULL);
187
188         if (retcode != SYSTEM_INFO_ERROR_NONE)
189                 dts_pass(API_NAME_SYSINFO_ACCESSIBLE, "passed");
190         else
191                 dts_fail(API_NAME_SYSINFO_ACCESSIBLE, "failed");
192 }
193
194
195 static void utc_system_info_get_double_p(void)
196 {
197         double value;
198
199         int retcode = system_info_get_value_double(SYSTEM_INFO_KEY_CORE_CPU_FREQ, &value);
200
201         if (retcode == SYSTEM_INFO_ERROR_NONE)
202                 dts_pass(API_NAME_SYSINFO_ACCESSIBLE, "passed");
203         else
204                 dts_fail(API_NAME_SYSINFO_ACCESSIBLE, "failed");
205 }
206
207 static void utc_system_info_get_double_n(void)
208 {
209         int retcode = system_info_get_value_double(SYSTEM_INFO_KEY_CORE_CPU_FREQ, NULL);
210
211         if (retcode != SYSTEM_INFO_ERROR_NONE)
212                 dts_pass(API_NAME_SYSINFO_ACCESSIBLE, "passed");
213         else
214                 dts_fail(API_NAME_SYSINFO_ACCESSIBLE, "failed");
215 }
216
217 /****************************************************************/
218 /* check if all particular informations have reasonable values */
219
220 static void utc_system_info_model_p(void)
221 {
222         char *string = NULL;
223         int string_len = 0;
224         int result = 0;
225
226         system_info_get_value_string(SYSTEM_INFO_KEY_MODEL, &string);
227
228         if (string) {
229                 string_len = strlen(string);
230                 free(string);
231         }
232
233         result = (string_len < HUGE_STRING_LEN)  &&  (string_len > 0);
234
235         dts_check_eq(API_NAME_SYSINFO_GOOD_VALUE, result, 1);
236 }
237
238 static void utc_system_info_tizen_ver_p(void)
239 {
240         char *string = NULL;
241         int string_len = 0;
242         int result = 0;
243
244         system_info_get_value_string(SYSTEM_INFO_KEY_TIZEN_VERSION, &string);
245
246         if (string) {
247                 string_len = strlen(string);
248                 free(string);
249         }
250
251         result = (string_len < HUGE_STRING_LEN)  &&  (string_len > 0);
252
253         dts_check_eq(API_NAME_SYSINFO_GOOD_VALUE, result, 1);
254 }
255
256 static void utc_system_info_h_res_p(void)
257 {
258         int h = -1;
259         int result = 0;
260
261         system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_HEIGHT, &h);
262
263         result = (h > 0)  &&  (h < 10000);
264
265         dts_check_eq(API_NAME_SYSINFO_GOOD_VALUE, result, 1);
266 }
267
268 static void utc_system_info_w_res_p(void)
269 {
270         int w = -1;
271         int result = 0;
272
273         system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_WIDTH, &w);
274
275         result = (w > 0)  &&  (w < 10000);
276
277         dts_check_eq(API_NAME_SYSINFO_GOOD_VALUE, result, 1);
278 }
279
280 static void utc_system_info_platform_name_p(void)
281 {
282         char *string = NULL;
283         int string_len = 0;
284         int result = 0;
285
286         system_info_get_value_string(SYSTEM_INFO_KEY_PLATFORM_NAME, &string);
287
288         if (string) {
289                 string_len = strlen(string);
290                 free(string);
291         }
292
293         result = (string_len < HUGE_STRING_LEN)  &&  (string_len > 0);
294
295         dts_check_eq(API_NAME_SYSINFO_GOOD_VALUE, result, 1);
296 }
297
298 static void utc_system_info_platform_ver_p(void)
299 {
300         char *string = NULL;
301         int string_len = 0;
302         int result = 0;
303
304         system_info_get_value_string(SYSTEM_INFO_KEY_TIZEN_VERSION_NAME, &string);
305
306         if (string) {
307                 string_len = strlen(string);
308                 free(string);
309         }
310
311         result = (string_len < HUGE_STRING_LEN)  &&  (string_len > 0);
312
313         dts_check_eq(API_NAME_SYSINFO_GOOD_VALUE, result, 1);
314 }
315
316 static void utc_system_info_screen_DPI_p(void)
317 {
318         int w = -1;
319         int result = 0;
320
321         system_info_get_value_int(SYSTEM_INFO_KEY_SCREEN_DPI, &w);
322
323         result = (w > 0)  &&  (w < 10000);
324
325         dts_check_eq(API_NAME_SYSINFO_GOOD_VALUE, result, 1);
326 }
327
328 static void utc_system_info_core_cpu_arch_p(void)
329 {
330         char *string = NULL;
331
332         int result = system_info_get_value_string(SYSTEM_INFO_KEY_CORE_CPU_ARCH, &string);
333
334         if (string) {
335                 free(string);
336         }
337
338         dts_check_eq(API_NAME_SYSINFO_GOOD_VALUE, result, 0);
339 }
340
341 static void utc_system_info_core_freq_p(void)
342 {
343         double w = 0;
344         int result = 0;
345
346         system_info_get_value_double(SYSTEM_INFO_KEY_CORE_CPU_FREQ, &w);
347
348         result = (w > 0)  &&  (w < 10000);
349
350         dts_check_eq(API_NAME_SYSINFO_GOOD_VALUE, result, 1);
351 }
352
353 static void utc_system_info_physical_screen_height_p(void)
354 {
355         int w = -1;
356         int result = 0;
357
358         system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_HEIGHT, &w);
359
360         result = (w > 0)  &&  (w < 10000);
361
362         dts_check_eq(API_NAME_SYSINFO_GOOD_VALUE, result, 1);
363 }
364
365 static void utc_system_info_physical_screen_width_p(void)
366 {
367         int w = -1;
368         int result = 0;
369
370         system_info_get_value_int(SYSTEM_INFO_KEY_PHYSICAL_SCREEN_WIDTH, &w);
371
372         result = (w > 0)  &&  (w < 10000);
373
374         dts_check_eq(API_NAME_SYSINFO_GOOD_VALUE, result, 1);
375 }
376
377 static void utc_system_info_build_string_p(void)
378 {
379         char *string = NULL;
380         int string_len = 0;
381         int result = 0;
382
383         system_info_get_value_string(SYSTEM_INFO_KEY_BUILD_STRING, &string);
384
385         if (string) {
386                 string_len = strlen(string);
387                 free(string);
388         }
389
390         result = (string_len < HUGE_STRING_LEN)  &&  (string_len > 0);
391
392         dts_check_eq(API_NAME_SYSINFO_GOOD_VALUE, result, 1);
393 }
394
395 static void utc_system_info_build_date_p(void)
396 {
397         char *string = NULL;
398         int string_len = 0;
399         int result = 0;
400
401         system_info_get_value_string(SYSTEM_INFO_KEY_BUILD_DATE, &string);
402
403         if (string) {
404                 string_len = strlen(string);
405                 free(string);
406         }
407
408         result = (string_len < HUGE_STRING_LEN)  &&  (string_len > 0);
409
410         dts_check_eq(API_NAME_SYSINFO_GOOD_VALUE, result, 1);
411 }
412
413 static void utc_system_info_build_time_p(void)
414 {
415         char *string = NULL;
416         int string_len = 0;
417         int result = 0;
418
419         system_info_get_value_string(SYSTEM_INFO_KEY_BUILD_TIME, &string);
420
421         if (string) {
422                 string_len = strlen(string);
423                 free(string);
424         }
425
426         result = (string_len < HUGE_STRING_LEN)  &&  (string_len > 0);
427
428         dts_check_eq(API_NAME_SYSINFO_GOOD_VALUE, result, 1);
429 }
430
431 static void utc_system_info_manufacturer_p(void)
432 {
433         char *string = NULL;
434         int string_len = 0;
435         int result = 0;
436
437         system_info_get_value_string(SYSTEM_INFO_KEY_MANUFACTURER, &string);
438
439         if (string) {
440                 string_len = strlen(string);
441                 free(string);
442         }
443
444         result = (string_len < HUGE_STRING_LEN)  &&  (string_len > 0);
445
446         dts_check_eq(API_NAME_SYSINFO_GOOD_VALUE, result, 1);
447 }
448
449 static void utc_system_info_tethering_support_key_p(void)
450 {
451         bool supported;
452         int retcode = -1;
453         int i;
454
455         retcode = system_info_get_value_bool(SYSTEM_INFO_KEY_TETHERING_SUPPORTED, &supported);
456
457         if (retcode == SYSTEM_INFO_ERROR_NONE)
458                 dts_pass(API_NAME_SYSINFO_SUPPORT_CHECK(i), "passed");
459         else
460                 dts_fail(API_NAME_SYSINFO_SUPPORT_CHECK(i), "failed");
461 }
462
463 static void utc_system_info_get_platform_bool(void)
464 {
465         bool supported;
466         int retcode = -1;
467
468         retcode = system_info_get_platform_bool("tizen.org/feature/fmradio", &supported);
469
470         if (retcode == SYSTEM_INFO_ERROR_NONE)
471                 dts_pass(API_NAME_SYSINFO_SUPPORT_CHECK(i), "passed");
472         else
473                 dts_fail(API_NAME_SYSINFO_SUPPORT_CHECK(i), "failed");
474 }
475
476 static void utc_system_info_get_platform_int(void)
477 {
478         int value = -1;
479         int result = 0;
480
481         system_info_get_value_int("tizen.org/feature/screen.bpp", &value);
482
483         result = (value > 0)  &&  (value < 10000);
484
485         dts_check_eq(API_NAME_SYSINFO_GOOD_VALUE, result, 1);
486 }
487
488 static void utc_system_info_get_platform_double(void)
489 {
490         double value;
491         int retcode = -1;
492
493         retcode = system_info_get_platform_double("tizen.org/feature/double", &value);
494
495         if (retcode == SYSTEM_INFO_ERROR_IO_ERROR)
496                 dts_pass(API_NAME_SYSINFO_SUPPORT_CHECK(i), "passed");
497         else
498                 dts_fail(API_NAME_SYSINFO_SUPPORT_CHECK(i), "failed");
499 }
500
501 static void utc_system_info_get_platform_string(void)
502 {
503         char *string = NULL;
504         int string_len = 0;
505         int result = 0;
506
507         system_info_get_platform_string("tizen.org/system/platform.name", &string);
508
509         if (string) {
510                 string_len = strlen(string);
511                 free(string);
512         }
513
514         result = (string_len < HUGE_STRING_LEN)  &&  (string_len > 0);
515
516         dts_check_eq(API_NAME_SYSINFO_GOOD_VALUE, result, 1);
517 }
518
519 static void utc_system_info_get_custom_bool(void)
520 {
521         bool value;
522         int retcode = -1;
523
524         retcode = system_info_get_custom_bool("tizen.org/feature/double", &value);
525
526         if (retcode == SYSTEM_INFO_ERROR_IO_ERROR)
527                 dts_pass(API_NAME_SYSINFO_SUPPORT_CHECK(i), "passed");
528         else
529                 dts_fail(API_NAME_SYSINFO_SUPPORT_CHECK(i), "failed");
530 }
531
532 static void utc_system_info_get_custom_int(void)
533 {
534         int value;
535         int retcode = -1;
536
537         retcode = system_info_get_custom_int("tizen.org/feature/double", &value);
538
539         if (retcode == SYSTEM_INFO_ERROR_IO_ERROR)
540                 dts_pass(API_NAME_SYSINFO_SUPPORT_CHECK(i), "passed");
541         else
542                 dts_fail(API_NAME_SYSINFO_SUPPORT_CHECK(i), "failed");
543 }
544
545 static void utc_system_info_get_custom_double(void)
546 {
547         int value;
548         int retcode = -1;
549
550         retcode = system_info_get_custom_double("tizen.org/feature/double", &value);
551
552         if (retcode == SYSTEM_INFO_ERROR_IO_ERROR)
553                 dts_pass(API_NAME_SYSINFO_SUPPORT_CHECK(i), "passed");
554         else
555                 dts_fail(API_NAME_SYSINFO_SUPPORT_CHECK(i), "failed");
556 }
557
558 static void utc_system_info_get_custom_string(void)
559 {
560         char *value = NULL;
561         int retcode = -1;
562
563         retcode = system_info_get_custom_string("tizen.org/feature/double", &value);
564
565         if (value)
566                 free(value);
567
568         if (retcode == SYSTEM_INFO_ERROR_IO_ERROR)
569                 dts_pass(API_NAME_SYSINFO_SUPPORT_CHECK(i), "passed");
570         else
571                 dts_fail(API_NAME_SYSINFO_SUPPORT_CHECK(i), "failed");
572 }
573
574 static void utc_system_info_get_internal_value(void)
575 {
576         char *value = NULL;
577         int retcode = -1;
578
579         retcode = system_info_get_internal_value("board.display.height_mm", &value);
580
581         if (value)
582                 free(value);
583
584         if (retcode == SYSTEM_INFO_ERROR_NONE)
585                 dts_pass(API_NAME_SYSINFO_SUPPORT_CHECK(i), "passed");
586         else
587                 dts_fail(API_NAME_SYSINFO_SUPPORT_CHECK(i), "failed");
588 }