sound: Intialize theme id by default value only when it hasn't been initialized
[platform/core/system/libsvi.git] / tests / test-feedback.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4
5 #include "test.h"
6 #include "test-feedback.h"
7
8 static int pass;
9 static int fail;
10
11 static void test_initialize_p(void)
12 {
13         RESULT(feedback_initialize(), FEEDBACK_ERROR_NONE, "nomal test");
14         RESULT(feedback_initialize(), FEEDBACK_ERROR_NONE, "2nd test"); // checking multi initialize
15
16         feedback_deinitialize();
17         feedback_deinitialize();
18 }
19
20 bool TEST_FEEDBACK_INITIALIZE(void)
21 {
22         INIT();
23         test_initialize_p();
24         REPORT_AND_RETURN();
25 }
26
27 static void test_deinitialize_p(void)
28 {
29         feedback_initialize();
30         feedback_initialize();
31
32         RESULT(feedback_deinitialize(), FEEDBACK_ERROR_NONE, "normal test");
33         RESULT(feedback_deinitialize(), FEEDBACK_ERROR_NONE, "2nd test");
34 }
35
36 static void test_deinitialize_n(void)
37 {
38         RESULT(feedback_deinitialize(), FEEDBACK_ERROR_NOT_INITIALIZED, "without init");
39
40         feedback_initialize();
41         feedback_deinitialize();
42         RESULT(feedback_deinitialize(), FEEDBACK_ERROR_NOT_INITIALIZED, "duplicated");
43 }
44
45 bool TEST_FEEDBACK_DEINITIALIZE(void)
46 {
47         INIT();
48         test_deinitialize_p();
49         test_deinitialize_n();
50         REPORT_AND_RETURN();
51 }
52
53 static void test_is_supported_pattern_p(void)
54 {
55         int type, j;
56         bool status;
57
58         feedback_initialize();
59         for (type = FEEDBACK_TYPE_NONE+1; type < FEEDBACK_TYPE_END; type++) {
60                 for (j = 0; j < ARRAY_SIZE(test_pattern); j++) {
61                         RESULT(feedback_is_supported_pattern(type, test_pattern[j].pattern, &status),
62                                 FEEDBACK_ERROR_NONE, test_pattern[j].name);
63                 }
64         }
65         feedback_deinitialize();
66 }
67
68 static void test_is_supported_pattern_n(void)
69 {
70         bool status;
71
72         RESULT(feedback_is_supported_pattern(FEEDBACK_TYPE_SOUND, test_pattern[0].pattern, &status),
73                                 FEEDBACK_ERROR_NOT_INITIALIZED, "without init");
74
75         feedback_initialize();
76         RESULT(feedback_is_supported_pattern(FEEDBACK_TYPE_NONE, test_pattern[0].pattern, &status),
77                                 FEEDBACK_ERROR_INVALID_PARAMETER, "type none");
78         RESULT(feedback_is_supported_pattern(FEEDBACK_TYPE_END, test_pattern[0].pattern, &status),
79                                 FEEDBACK_ERROR_INVALID_PARAMETER, "type end");
80         RESULT(feedback_is_supported_pattern(FEEDBACK_TYPE_SOUND, test_pattern[0].pattern, NULL),
81                                 FEEDBACK_ERROR_INVALID_PARAMETER, "status NULL");
82         RESULT(feedback_is_supported_pattern(FEEDBACK_TYPE_SOUND, FEEDBACK_PATTERN_NONE, &status),
83                                 FEEDBACK_ERROR_INVALID_PARAMETER, "pattern NULL");
84         //RESULT(feedback_is_supported_pattern(FEEDBACK_TYPE_SOUND, FEEDBACK_PATTERN_END, &status),
85         //                      FEEDBACK_ERROR_INVALID_PARAMETER, "pattern end");
86         feedback_deinitialize();
87 }
88
89 bool TEST_FEEDBACK_IS_SUPPORTED_PATTERN(void)
90 {
91         INIT();
92         test_is_supported_pattern_p();
93         test_is_supported_pattern_n();
94         REPORT_AND_RETURN();
95 }
96
97 static void test_play_p(void)
98 {
99         int i;
100
101         feedback_initialize();
102         for (i = 0; i < ARRAY_SIZE(test_pattern); ++i) {
103                 RESULT(feedback_play(test_pattern[i].pattern), FEEDBACK_ERROR_NONE, test_pattern[i].name);
104                 usleep(DELAY_TIME);
105         }
106         feedback_deinitialize();
107 }
108
109 static void test_play_n(void)
110 {
111         RESULT(feedback_play(FEEDBACK_PATTERN_TAP), FEEDBACK_ERROR_NOT_INITIALIZED, "without init");
112
113         feedback_initialize();
114         RESULT(feedback_play(FEEDBACK_PATTERN_NONE), FEEDBACK_ERROR_INVALID_PARAMETER, "pattern NULL");
115         feedback_deinitialize();
116 }
117
118 bool TEST_FEEDBACK_PLAY(void)
119 {
120         INIT();
121         test_play_p();
122         test_play_n();
123         REPORT_AND_RETURN();
124 }
125
126 static void INIT_PATTERN_LIST(feedback_type_e type, int *supported, int *nsupported, int *not_supported, int *n_not_supported)
127 {
128     int idx_supported = 0, idx_not_supported = 0;
129     int i;
130     bool status;
131
132     if (!supported || !not_supported)
133         return;
134
135     memset(supported, -1, ARRAY_SIZE(test_pattern) * sizeof(int));
136     memset(not_supported, -1, ARRAY_SIZE(test_pattern) * sizeof(int));
137
138     feedback_initialize();
139
140     for (i = 0; i < ARRAY_SIZE(test_pattern); ++i) {
141         feedback_is_supported_pattern(type, test_pattern[i].pattern, &status);
142         if (status)
143             supported[idx_supported++] = i;
144         else
145             not_supported[idx_not_supported++] = i;
146     }
147     feedback_deinitialize();
148
149         if (nsupported) *nsupported = idx_supported;
150         if (n_not_supported) *n_not_supported = idx_not_supported;
151 }
152
153 static void test_play_type_p(feedback_type_e type, int *supported, int ncount)
154 {
155         int i;
156
157         if (!supported)
158                 return ;
159
160         feedback_initialize();
161         for (i = 0; i < ncount; i++) {
162                 RESULT(feedback_play_type(type, test_pattern[(feedback_pattern_e)supported[i]].pattern),
163                         FEEDBACK_ERROR_NONE, test_pattern[(feedback_pattern_e)supported[i]].name);
164         }
165         feedback_deinitialize();
166 }
167
168 static void test_play_type_n(feedback_type_e type, int *notsupported, int ncount)
169 {
170         int i;
171
172         if (!notsupported)
173                 return ;
174
175         RESULT(feedback_play_type(type, FEEDBACK_PATTERN_TAP), FEEDBACK_ERROR_NOT_INITIALIZED, "without init");
176
177         feedback_initialize();
178         for (i = 0; i < ncount; i++) {
179                 RESULT(feedback_play_type(type, test_pattern[(feedback_pattern_e)notsupported[i]].pattern),
180                         FEEDBACK_ERROR_NOT_SUPPORTED, test_pattern[(feedback_pattern_e)notsupported[i]].name);
181         }
182         feedback_deinitialize();
183 }
184
185 bool TEST_FEEDBACK_PLAY_TYPE(void)
186 {
187         int type;
188         int nSupported = 0, nNotSupported = 0;
189         int *pSupported = malloc(ARRAY_SIZE(test_pattern)*sizeof(int));
190         int *pNotSupported = malloc(ARRAY_SIZE(test_pattern)*sizeof(int));
191
192         INIT();
193
194         for (type = FEEDBACK_TYPE_NONE+1; type < FEEDBACK_TYPE_END; type++) {
195                 INIT_PATTERN_LIST(type, pSupported, &nSupported, pNotSupported, &nNotSupported);
196                 test_play_type_p(type, pSupported, nSupported);
197                 if (type != FEEDBACK_TYPE_VIBRATION)
198                         test_play_type_n(type, pNotSupported, nNotSupported);
199         }
200
201         free(pSupported);
202         free(pNotSupported);
203
204         REPORT_AND_RETURN();
205 }
206
207 static void test_stop_p()
208 {
209         feedback_initialize();
210         RESULT(feedback_stop(), FEEDBACK_ERROR_NONE, "normal test");
211         feedback_deinitialize();
212 }
213
214 static void test_stop_n()
215 {
216         RESULT(feedback_stop(), FEEDBACK_ERROR_NOT_INITIALIZED, "without init");
217 }
218
219 bool TEST_FEEDBACK_STOP(void)
220 {
221         INIT();
222         test_stop_p();
223         test_stop_n();
224         REPORT_AND_RETURN();
225 }