patch tizen_2.0_build
[framework/api/device.git] / TC / testcase / utc_system_device_battery.c
1 /*
2  * 
3  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4  * PROPRIETARY/CONFIDENTIAL
5  * 
6  * This software is the confidential and proprietary information of SAMSUNG 
7  * ELECTRONICS ("Confidential Information"). You agree and acknowledge that 
8  * this software is owned by Samsung and you shall not disclose such 
9  * Confidential Information and shall use it only in accordance with the terms 
10  * of the license agreement you entered into with SAMSUNG ELECTRONICS. SAMSUNG 
11  * make no representations or warranties about the suitability of the software, 
12  * either express or implied, including but not limited to the implied 
13  * warranties of merchantability, fitness for a particular purpose, or 
14  * non-infringement. SAMSUNG shall not be liable for any damages suffered by 
15  * licensee arising out of or related to this software.
16  * 
17  */
18 #include <tet_api.h>
19 #include <device.h>
20
21 #define API_NAME_DEVICE_BATTERY_GET_PERCENT "device_battery_get_percent"
22 #define API_NAME_DEVICE_BATTERY_IS_FULL "device_battery_is_full"
23 #define API_NAME_DEVICE_BATTERY_IS_CHARGING "device_battery_is_charging"
24 #define API_NAME_DEVICE_BATTERY_SET_CB "device_battery_set_cb"
25 #define API_NAME_DEVICE_BATTERY_UNSET_CB "device_battery_unset_cb"
26
27 static void startup(void);
28 static void cleanup(void);
29
30 void (*tet_startup)(void) = startup;
31 void (*tet_cleanup)(void) = cleanup;
32
33 static void utc_system_device_battery_get_percent_p(void);
34 static void utc_system_device_battery_get_percent_n(void);
35 static void utc_system_device_battery_is_full_p(void);
36 static void utc_system_device_battery_is_full_n(void);
37 static void utc_system_device_battery_is_charging_p(void);
38 static void utc_system_device_battery_is_charging_n(void);
39 static void utc_system_device_battery_set_cb_p(void);
40 static void utc_system_device_battery_set_cb_n(void);
41 static void utc_system_device_battery_unset_cb_p(void);
42
43
44 enum {
45         POSITIVE_TC_IDX = 0x01,
46         NEGATIVE_TC_IDX,
47 };
48
49 struct tet_testlist tet_testlist[] = {
50         { utc_system_device_battery_get_percent_p, POSITIVE_TC_IDX },
51         { utc_system_device_battery_get_percent_n, NEGATIVE_TC_IDX },
52         { utc_system_device_battery_is_full_p, POSITIVE_TC_IDX },
53         { utc_system_device_battery_is_full_n, NEGATIVE_TC_IDX },
54         { utc_system_device_battery_is_charging_p, POSITIVE_TC_IDX },
55         { utc_system_device_battery_is_charging_n, NEGATIVE_TC_IDX },
56         { utc_system_device_battery_set_cb_p, POSITIVE_TC_IDX },
57         { utc_system_device_battery_set_cb_n, NEGATIVE_TC_IDX },
58         { utc_system_device_battery_unset_cb_p, POSITIVE_TC_IDX },
59         { NULL, 0},
60 };
61
62 static void startup(void)
63 {
64         /* start of TC */
65 }
66
67 static void cleanup(void)
68 {
69         /* end of TC */
70 }
71
72 /**
73  * @brief Positive test case of device_battery_get_percent()
74  */
75 static void utc_system_device_battery_get_percent_p(void)
76 {
77     int percent = 0;
78     int error = DEVICE_ERROR_NONE;
79     error = device_battery_get_percent(&percent);
80
81     dts_check_eq(API_NAME_DEVICE_BATTERY_GET_PERCENT, error, DEVICE_ERROR_NONE);
82 }
83
84 /**
85  * @brief Negative test case of device_battery_get_percent()
86  */
87 static void utc_system_device_battery_get_percent_n(void)
88 {
89     int error = DEVICE_ERROR_NONE;
90     error = device_battery_get_percent(NULL);
91
92     dts_check_ne(API_NAME_DEVICE_BATTERY_GET_PERCENT, error, DEVICE_ERROR_NONE);
93 }
94
95 /**
96  * @brief Positive test case of device_battery_is_full()
97  */
98 static void utc_system_device_battery_is_full_p(void)
99 {
100     bool full;
101     int error = DEVICE_ERROR_NONE;
102     error = device_battery_is_full(&full);
103     dts_check_eq(API_NAME_DEVICE_BATTERY_IS_FULL, error, DEVICE_ERROR_NONE);
104 }
105
106 /**
107  * @brief Negative test case of device_battery_is_full()
108  */
109 static void utc_system_device_battery_is_full_n(void)
110 {
111     int error = DEVICE_ERROR_NONE;
112     error = device_battery_is_full(NULL);
113     dts_check_ne(API_NAME_DEVICE_BATTERY_IS_FULL, error, DEVICE_ERROR_NONE);
114 }
115
116
117 static void utc_system_device_battery_is_charging_p(void)
118 {
119     bool charging;
120     int error = DEVICE_ERROR_NONE;
121     error = device_battery_is_charging(&charging);
122     dts_check_eq(API_NAME_DEVICE_BATTERY_IS_CHARGING, error, DEVICE_ERROR_NONE);
123 }
124
125 static void utc_system_device_battery_is_charging_n(void)
126 {
127     bool charging;
128     int error = DEVICE_ERROR_NONE;
129     error = device_battery_is_charging(NULL);
130     dts_check_ne(API_NAME_DEVICE_BATTERY_IS_CHARGING, error, DEVICE_ERROR_NONE);
131 }
132
133 static void battery_cb(int percent, void *user_data)
134 {
135 }
136
137 static void utc_system_device_battery_set_cb_p(void)
138 {
139     int error = device_battery_set_cb(battery_cb, NULL);
140     device_battery_unset_cb();
141     dts_check_eq(API_NAME_DEVICE_BATTERY_SET_CB, error, DEVICE_ERROR_NONE);
142 }
143
144 static void utc_system_device_battery_set_cb_n(void)
145 {
146     int error = device_battery_set_cb(NULL, NULL);
147     device_battery_unset_cb();
148     dts_check_ne(API_NAME_DEVICE_BATTERY_SET_CB, error, DEVICE_ERROR_NONE);
149 }
150
151 static void utc_system_device_battery_unset_cb_p(void)
152 {
153     device_battery_set_cb(battery_cb, NULL);
154     int error = device_battery_unset_cb();
155     dts_check_eq(API_NAME_DEVICE_BATTERY_SET_CB, error, DEVICE_ERROR_NONE);
156 }