6 #include "test-feedback-internal.h"
11 static int pattern_s[ARRAY_SIZE(test_pattern)] = { -1, };
12 static int pattern_i_s[ARRAY_SIZE(test_pattern_internal)] = { -1, };
13 static int pattern_v[ARRAY_SIZE(test_pattern)] = { -1, };
14 static int pattern_i_v[ARRAY_SIZE(test_pattern_internal)] = { -1, };
16 static void test_play_type_by_name_p()
20 bool s_end = false, v_end = false;
22 feedback_initialize();
24 for (i = 0; i < ARRAY_SIZE(test_pattern); i++)
26 if (pattern_s[i] == -1) s_end = true;
27 if (pattern_v[i] == -1) v_end = true;
29 if (s_end && v_end) break;
31 if (!s_end && (pattern_s[i] != -1)) {
32 name = strdup(test_pattern[pattern_s[i]].name);
33 RESULT(feedback_play_type_by_name("FEEDBACK_TYPE_SOUND", name), FEEDBACK_ERROR_NONE, name)
37 if (!v_end && (pattern_v[i] != -1)) {
38 name = strdup(test_pattern[pattern_v[i]].name);
39 RESULT(feedback_play_type_by_name("FEEDBACK_TYPE_VIBRATION", name), FEEDBACK_ERROR_NONE, name);
49 for (i = 0; i < ARRAY_SIZE(test_pattern_internal); i++)
51 if (pattern_i_s[i] == -1) s_end = true;
52 if (pattern_i_v[i] == -1) v_end = true;
54 if (s_end && v_end) break;
56 if (!s_end && (pattern_i_s[i] != -1)) {
57 name = strdup(test_pattern_internal[pattern_i_s[i]].name);
58 RESULT(feedback_play_type_by_name("FEEDBACK_TYPE_SOUND", name), FEEDBACK_ERROR_NONE, name);
62 if (!v_end && (pattern_i_v[i] != -1)) {
63 name = strdup(test_pattern_internal[pattern_i_v[i]].name);
64 RESULT(feedback_play_type_by_name("FEEDBACK_TYPE_VIBRATION", name), FEEDBACK_ERROR_NONE, name);
71 feedback_deinitialize();
74 static void test_play_type_by_name_n()
76 RESULT(feedback_play_type_by_name(NULL, "FEEDBACK_PATTERN_TAP"), FEEDBACK_ERROR_INVALID_PARAMETER, "type is null");
78 RESULT(feedback_play_type_by_name("FEEDBACK_TYPE_VIBRATION", NULL), FEEDBACK_ERROR_INVALID_PARAMETER, "pattern is null");
80 RESULT(feedback_play_type_by_name("INVALID_FEEDBACK_TYPE", "FEEDBACK_PATTERN_TAP"), FEEDBACK_ERROR_INVALID_PARAMETER, "invalid feedback type");
82 RESULT(feedback_play_type_by_name("FEEDBACK_TYPE_SOUND", "INVALID_FEEDBACK_PATTERN"), FEEDBACK_ERROR_INVALID_PARAMETER, "invalid feedback pattern");
85 bool TEST_FEEDBACK_PLAY_TYPE_BY_NAME(void)
89 test_play_type_by_name_p();
90 test_play_type_by_name_n();
95 static void test_play_internal_p()
99 feedback_initialize();
101 for (i = 0; i < ARRAY_SIZE(test_pattern_internal); i++)
103 RESULT(feedback_play_internal(test_pattern_internal[i].pattern), FEEDBACK_ERROR_NONE, test_pattern_internal[i].name);
107 feedback_deinitialize();
110 static void test_play_internal_n()
112 RESULT(feedback_play_internal(FEEDBACK_PATTERN_TAP), FEEDBACK_ERROR_NOT_INITIALIZED, "not initialize");
114 feedback_initialize();
115 RESULT(feedback_play_internal(FEEDBACK_PATTERN_NONE), FEEDBACK_ERROR_INVALID_PARAMETER, "invalid pattern");
116 feedback_deinitialize();
119 bool TEST_FEEDBACK_PLAY_INTERNAL(void)
123 test_play_internal_p();
124 test_play_internal_n();
129 static void test_play_soundpath_internal_p()
132 struct _pattern_internal *pattern;
134 feedback_initialize();
136 for (i = 0; i < ARRAY_SIZE(test_pattern_internal); i++)
138 if (pattern_i_s[i] == -1)
141 pattern = &test_pattern_internal[pattern_i_s[i]];
142 if (pattern->path == NULL)
145 RESULT(feedback_play_soundpath_internal(pattern->pattern, pattern->path), FEEDBACK_ERROR_NONE, pattern->name);
149 feedback_deinitialize();
152 static void test_play_soundpath_internal_n()
154 RESULT(feedback_play_soundpath_internal(FEEDBACK_PATTERN_TAP, "/usr/share/feedback/sound/operation/operation.wav"), FEEDBACK_ERROR_NOT_INITIALIZED, "not initialize");
156 feedback_initialize();
158 RESULT(feedback_play_soundpath_internal(FEEDBACK_PATTERN_NONE, "/usr/share/feedback/sound/operation/operation.wav"), FEEDBACK_ERROR_INVALID_PARAMETER, "invalid pattern");
159 RESULT(feedback_play_soundpath_internal(FEEDBACK_PATTERN_TAP, NULL), FEEDBACK_ERROR_INVALID_PARAMETER, "NULL sound path");
161 feedback_deinitialize();
164 bool TEST_FEEDBACK_PLAY_SOUNDPATH_INTERNAL(void)
168 test_play_soundpath_internal_p();
169 test_play_soundpath_internal_n();
174 static void test_play_type_internal_p()
177 bool s_end = false, v_end = false;
179 feedback_initialize();
181 for (i = 0; i < ARRAY_SIZE(test_pattern_internal); i++)
183 if (pattern_i_s[i] == -1) s_end = true;
184 if (pattern_i_v[i] == -1) v_end = true;
186 if (s_end && v_end) break;
188 if (!s_end && (pattern_i_s[i] != -1))
189 RESULT(feedback_play_type_internal(FEEDBACK_TYPE_SOUND, test_pattern_internal[pattern_i_s[i]].pattern), FEEDBACK_ERROR_NONE, test_pattern_internal[pattern_i_s[i]].name);
191 if (!v_end && (pattern_i_v[i] != -1))
192 RESULT(feedback_play_type_internal(FEEDBACK_TYPE_VIBRATION, test_pattern_internal[pattern_i_v[i]].pattern), FEEDBACK_ERROR_NONE, test_pattern_internal[pattern_i_v[i]].name);
197 feedback_deinitialize();
200 static void test_play_type_internal_n()
202 RESULT(feedback_play_type_internal(FEEDBACK_TYPE_SOUND, FEEDBACK_PATTERN_TAP), FEEDBACK_ERROR_NOT_INITIALIZED, "not initialize");
204 feedback_initialize();
206 RESULT(feedback_play_type_internal(FEEDBACK_TYPE_NONE, FEEDBACK_PATTERN_TAP), FEEDBACK_ERROR_INVALID_PARAMETER, "invalid type");
207 RESULT(feedback_play_type_internal(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_NONE), FEEDBACK_ERROR_INVALID_PARAMETER, "invalid pattern");
209 feedback_deinitialize();
212 bool TEST_FEEDBACK_PLAY_TYPE_INTERNAL(void)
216 test_play_type_internal_p();
217 test_play_type_internal_n();
221 static void test_play_type_soundpath_internal_p()
224 bool s_end = false, v_end = false;
225 struct _pattern_internal *pattern;
227 feedback_initialize();
229 for (i = 0; i < ARRAY_SIZE(test_pattern_internal); i++)
231 if (pattern_i_s[i] == -1) s_end = true;
232 if (pattern_i_v[i] == -1) v_end = true;
234 if (s_end && v_end) break;
236 if (!s_end && (pattern_i_s[i] != -1)) {
237 pattern = &test_pattern_internal[pattern_i_s[i]];
238 if (pattern->path != NULL)
239 RESULT(feedback_play_type_soundpath_internal(FEEDBACK_TYPE_SOUND, pattern->pattern, pattern->path), FEEDBACK_ERROR_NONE, pattern->name);
242 if (!v_end && (pattern_i_v[i] != -1)) {
243 pattern = &test_pattern_internal[pattern_i_v[i]];
244 RESULT(feedback_play_type_soundpath_internal(FEEDBACK_TYPE_VIBRATION, pattern->pattern, NULL), FEEDBACK_ERROR_NONE, pattern->name);
250 feedback_deinitialize();
254 static void test_play_type_soundpath_internal_n()
256 RESULT(feedback_play_type_soundpath_internal(FEEDBACK_TYPE_SOUND, FEEDBACK_PATTERN_TAP, "/usr/share/feedback/sound/operation/operation.wav"), FEEDBACK_ERROR_NOT_INITIALIZED, "not initialize");
258 feedback_initialize();
260 RESULT(feedback_play_type_soundpath_internal(FEEDBACK_TYPE_NONE, FEEDBACK_PATTERN_TAP, "/usr/share/feedback/sound/operation/operation.wav"), FEEDBACK_ERROR_INVALID_PARAMETER, "invalid type");
261 RESULT(feedback_play_type_soundpath_internal(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_NONE, "/usr/share/feedback/sound/operation/operation.wav"), FEEDBACK_ERROR_INVALID_PARAMETER, "invalid pattern");
262 RESULT(feedback_play_type_soundpath_internal(FEEDBACK_TYPE_SOUND, FEEDBACK_PATTERN_TAP, NULL), FEEDBACK_ERROR_INVALID_PARAMETER, "invalid soundpath");
264 feedback_deinitialize();
267 bool TEST_FEEDBACK_PLAY_TYPE_SOUNDPATH_INTERNAL(void)
271 test_play_type_soundpath_internal_p();
272 test_play_type_soundpath_internal_n();
277 const char *feedback_play_sound_by_name(const char *pattern_name)
281 feedback_initialize();
282 ret = feedback_play_type_by_name("FEEDBACK_TYPE_SOUND", (char *)pattern_name);
283 usleep(DELAY_TIME*10);
284 feedback_deinitialize();
286 return err_to_str(ret);
289 const char *feedback_play_vibration_by_name(const char *pattern_name)
293 feedback_initialize();
294 ret = feedback_play_type_by_name("FEEDBACK_TYPE_VIBRATION", (char *)pattern_name);
295 usleep(DELAY_TIME*10);
296 feedback_deinitialize();
298 return err_to_str(ret);
301 void feedback_play_by_name(const char *pattern_name)
303 feedback_play_sound_by_name(pattern_name);
304 feedback_play_vibration_by_name(pattern_name);
307 static void init_supported_pattern(feedback_type_e type, int *pattern)
310 int idx_supported = 0;
313 feedback_initialize();
315 for(i = 0; i < ARRAY_SIZE(test_pattern); i++) {
316 ret = feedback_is_supported_pattern(type, test_pattern[i].pattern, &status);
317 if ((ret == FEEDBACK_ERROR_NONE) && status)
318 pattern[idx_supported++] = i;
320 pattern[idx_supported] = -1;
322 feedback_deinitialize();
325 static void init_supported_pattern_i(feedback_type_e type, int *pattern_i)
328 int idx_supported = 0;
331 feedback_initialize();
333 for(i = 0; i < ARRAY_SIZE(test_pattern_internal); i++) {
334 ret = feedback_is_supported_pattern(type, test_pattern_internal[i].pattern, &status);
335 if ((ret == FEEDBACK_ERROR_NONE) && status)
336 pattern_i[idx_supported++] = i;
338 pattern_i[idx_supported] = -1;
340 feedback_deinitialize();
343 static void test_get_count_of_sound_theme_internal(void)
345 unsigned int count_of_theme = 0;
347 RESULT(feedback_get_count_of_theme_internal(FEEDBACK_TYPE_SOUND, &count_of_theme),
348 FEEDBACK_ERROR_NOT_INITIALIZED, "not initialized");
350 feedback_initialize();
351 RESULT(feedback_get_count_of_theme_internal(FEEDBACK_TYPE_SOUND, NULL),
352 FEEDBACK_ERROR_INVALID_PARAMETER, "invalid parameter");
353 RESULT(feedback_get_count_of_theme_internal(FEEDBACK_TYPE_VIBRATION, &count_of_theme),
354 FEEDBACK_ERROR_NOT_SUPPORTED, "not supported");
355 RESULT(feedback_get_count_of_theme_internal(FEEDBACK_TYPE_SOUND, &count_of_theme),
356 FEEDBACK_ERROR_NONE, "error none");
357 _D("Feedback type=%d count of theme=%d is get", FEEDBACK_TYPE_SOUND, count_of_theme);
358 feedback_deinitialize();
361 bool TEST_FEEDBACK_GET_COUNT_OF_SOUND_THEME_INTERNAL(void)
364 test_get_count_of_sound_theme_internal();
368 static void test_get_sound_theme_id_internal(void)
370 unsigned int id_of_theme = 0;
372 feedback_initialize();
373 RESULT(feedback_get_theme_id_internal(FEEDBACK_TYPE_SOUND, NULL),
374 FEEDBACK_ERROR_INVALID_PARAMETER, "invalid parameter");
375 RESULT(feedback_get_theme_id_internal(FEEDBACK_TYPE_VIBRATION, &id_of_theme),
376 FEEDBACK_ERROR_NOT_SUPPORTED, "not supported");
377 RESULT(feedback_get_theme_id_internal(FEEDBACK_TYPE_SOUND, &id_of_theme),
378 FEEDBACK_ERROR_NONE, "error none");
379 _D("Feedback type=%d sound theme id=%d is get", FEEDBACK_TYPE_SOUND, id_of_theme);
380 feedback_deinitialize();
383 bool TEST_FEEDBACK_GET_SOUND_THEME_ID_INTERNAL(void)
386 test_get_sound_theme_id_internal();
390 static void test_set_sound_theme_id_internal(void)
394 feedback_initialize();
395 feedback_get_theme_id_internal(FEEDBACK_TYPE_SOUND, &id);
397 RESULT(feedback_set_theme_id_internal(FEEDBACK_TYPE_SOUND, id),
398 FEEDBACK_ERROR_NONE, "error none");
400 RESULT(feedback_set_theme_id_internal(FEEDBACK_TYPE_VIBRATION, id),
401 FEEDBACK_ERROR_NOT_SUPPORTED, "not supported");
403 feedback_deinitialize();
406 bool TEST_FEEDBACK_SET_SOUND_THEME_ID_INTERNAL(void)
409 test_set_sound_theme_id_internal();
413 static void test_get_sound_theme_ids_internal(void)
415 unsigned int count_of_theme = 0;
416 unsigned int *sound_theme_ids = NULL;
419 feedback_initialize();
420 RESULT(feedback_get_theme_ids_internal(FEEDBACK_TYPE_VIBRATION, &count_of_theme, &sound_theme_ids),
421 FEEDBACK_ERROR_NOT_SUPPORTED, "not supported");
422 RESULT(feedback_get_theme_ids_internal(FEEDBACK_TYPE_SOUND, NULL, NULL),
423 FEEDBACK_ERROR_INVALID_PARAMETER, "invalid parameter");
425 feedback_get_theme_ids_internal(FEEDBACK_TYPE_SOUND, &count_of_theme, &sound_theme_ids);
427 for (index = 0; index < count_of_theme; index++)
429 _D("Feedback type=Sound, sound theme id=%d is get", sound_theme_ids[index]);
430 RESULT(feedback_set_theme_id_internal(FEEDBACK_TYPE_SOUND, sound_theme_ids[index]),
431 FEEDBACK_ERROR_NONE, "error none");
434 feedback_deinitialize();
437 bool TEST_FEEDBACK_GET_SOUND_THEME_IDS_INTERNAL(void)
440 test_get_sound_theme_ids_internal();
444 static void test_put_sound_theme_ids_internal(void)
446 unsigned int count_of_theme = 0;
447 unsigned int *sound_theme_ids = NULL;
449 feedback_initialize();
450 RESULT(feedback_put_theme_ids_internal(&sound_theme_ids),
451 FEEDBACK_ERROR_INVALID_PARAMETER, "invalid parameter");
452 RESULT(feedback_put_theme_ids_internal(NULL),
453 FEEDBACK_ERROR_INVALID_PARAMETER, "invalid parameter");
455 feedback_get_theme_ids_internal(FEEDBACK_TYPE_SOUND, &count_of_theme, &sound_theme_ids);
456 RESULT(feedback_put_theme_ids_internal(&sound_theme_ids),
457 FEEDBACK_ERROR_NONE, "error none");
458 feedback_deinitialize();
461 bool TEST_FEEDBACK_PUT_SOUND_THEME_IDS_INTERNAL(void)
464 test_put_sound_theme_ids_internal();
468 static void test_feedback_play_type_with_flags_internal(void)
470 feedback_initialize();
471 RESULT(feedback_play_type_with_flags_internal(FEEDBACK_TYPE_SOUND, FEEDBACK_PATTERN_TAP, -1), FEEDBACK_ERROR_INVALID_PARAMETER, "invalid parameter");
472 RESULT(feedback_play_type_with_flags_internal(FEEDBACK_TYPE_VIBRATION, FEEDBACK_PATTERN_TAP, FEEDBACK_FLAG_PRIORITY_BASED_PLAY), FEEDBACK_ERROR_OPERATION_FAILED, "operation failed");
473 RESULT(feedback_play_type_with_flags_internal(FEEDBACK_TYPE_SOUND, FEEDBACK_PATTERN_TAP, FEEDBACK_FLAG_PRIORITY_BASED_PLAY), FEEDBACK_ERROR_NONE, "error none");
474 RESULT(feedback_play_type_with_flags_internal(FEEDBACK_TYPE_SOUND, FEEDBACK_PATTERN_TAP, FEEDBACK_FLAG_NONE), FEEDBACK_ERROR_NONE, "error none");
475 feedback_deinitialize();
478 bool TEST_FEEDBACK_PLAY_TYPE_WITH_FLAGS_INTERNAL(void)
481 test_feedback_play_type_with_flags_internal();
485 void TEST_INTERNAL_INIT()
487 init_supported_pattern(FEEDBACK_TYPE_SOUND, pattern_s);
488 init_supported_pattern(FEEDBACK_TYPE_VIBRATION, pattern_v);
489 init_supported_pattern_i(FEEDBACK_TYPE_SOUND, pattern_i_s);
490 init_supported_pattern_i(FEEDBACK_TYPE_VIBRATION, pattern_i_v);