6 #include "test-feedback.h"
11 static void test_initialize_p(void)
13 RESULT(feedback_initialize(), FEEDBACK_ERROR_NONE, "nomal test");
14 RESULT(feedback_initialize(), FEEDBACK_ERROR_NONE, "2nd test"); // checking multi initialize
16 feedback_deinitialize();
17 feedback_deinitialize();
20 bool TEST_FEEDBACK_INITIALIZE(void)
27 static void test_deinitialize_p(void)
29 feedback_initialize();
30 feedback_initialize();
32 RESULT(feedback_deinitialize(), FEEDBACK_ERROR_NONE, "normal test");
33 RESULT(feedback_deinitialize(), FEEDBACK_ERROR_NONE, "2nd test");
36 static void test_deinitialize_n(void)
38 RESULT(feedback_deinitialize(), FEEDBACK_ERROR_NOT_INITIALIZED, "without init");
40 feedback_initialize();
41 feedback_deinitialize();
42 RESULT(feedback_deinitialize(), FEEDBACK_ERROR_NOT_INITIALIZED, "duplicated");
45 bool TEST_FEEDBACK_DEINITIALIZE(void)
48 test_deinitialize_p();
49 test_deinitialize_n();
53 static void test_is_supported_pattern_p(void)
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);
65 feedback_deinitialize();
68 static void test_is_supported_pattern_n(void)
72 RESULT(feedback_is_supported_pattern(FEEDBACK_TYPE_SOUND, test_pattern[0].pattern, &status),
73 FEEDBACK_ERROR_NOT_INITIALIZED, "without init");
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();
89 bool TEST_FEEDBACK_IS_SUPPORTED_PATTERN(void)
92 test_is_supported_pattern_p();
93 test_is_supported_pattern_n();
97 static void test_play_p(void)
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);
106 feedback_deinitialize();
109 static void test_play_n(void)
111 RESULT(feedback_play(FEEDBACK_PATTERN_TAP), FEEDBACK_ERROR_NOT_INITIALIZED, "without init");
113 feedback_initialize();
114 RESULT(feedback_play(FEEDBACK_PATTERN_NONE), FEEDBACK_ERROR_INVALID_PARAMETER, "pattern NULL");
115 feedback_deinitialize();
118 bool TEST_FEEDBACK_PLAY(void)
126 static void INIT_PATTERN_LIST(feedback_type_e type, int *supported, int *nsupported, int *not_supported, int *n_not_supported)
128 int idx_supported = 0, idx_not_supported = 0;
132 if (!supported || !not_supported)
135 memset(supported, -1, ARRAY_SIZE(test_pattern) * sizeof(int));
136 memset(not_supported, -1, ARRAY_SIZE(test_pattern) * sizeof(int));
138 feedback_initialize();
140 for (i = 0; i < ARRAY_SIZE(test_pattern); ++i) {
141 feedback_is_supported_pattern(type, test_pattern[i].pattern, &status);
143 supported[idx_supported++] = i;
145 not_supported[idx_not_supported++] = i;
147 feedback_deinitialize();
149 if (nsupported) *nsupported = idx_supported;
150 if (n_not_supported) *n_not_supported = idx_not_supported;
153 static void test_play_type_p(feedback_type_e type, int *supported, int ncount)
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);
165 feedback_deinitialize();
168 static void test_play_type_n(feedback_type_e type, int *notsupported, int ncount)
175 RESULT(feedback_play_type(type, FEEDBACK_PATTERN_TAP), FEEDBACK_ERROR_NOT_INITIALIZED, "without init");
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);
182 feedback_deinitialize();
185 bool TEST_FEEDBACK_PLAY_TYPE(void)
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));
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);
207 static void test_stop_p()
209 feedback_initialize();
210 RESULT(feedback_stop(), FEEDBACK_ERROR_NONE, "normal test");
211 feedback_deinitialize();
214 static void test_stop_n()
216 RESULT(feedback_stop(), FEEDBACK_ERROR_NOT_INITIALIZED, "without init");
219 bool TEST_FEEDBACK_STOP(void)