summaryrefslogtreecommitdiff
path: root/tests/main.c
blob: b3313be3f35a37845ead437a321f133690b9d4a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <stdio.h>
#include <strings.h>

#include "test-feedback.h"
#include "test-feedback-internal.h"

#define LOG_RESULT(ret, func)	printf("[%s] %s\n", (ret)? "PASS": "FAIL", func)

void test_all()
{
	printf("---------------- FEEDBACK TEST -----------------\n");
	printf("  For more details,\n");
	printf("  check dlog with 'FEEDBACK_TEST' tag.\n");
	printf("------------------------------------------------\n");

	LOG_RESULT(TEST_FEEDBACK_INITIALIZE(), "TEST_FEEDBACK_INITIALIZE");
	LOG_RESULT(TEST_FEEDBACK_DEINITIALIZE(), "TEST_FEEDBACK_DEINITIALIZE");
	LOG_RESULT(TEST_FEEDBACK_IS_SUPPORTED_PATTERN(), "TEST_FEEDBACK_IS_SUPPORTED_PATTERN");
	LOG_RESULT(TEST_FEEDBACK_PLAY(), "TEST_FEEDBACK_PLAY");
	LOG_RESULT(TEST_FEEDBACK_PLAY_TYPE(), "TEST_FEEDBACK_PLAY_TYPE");
	LOG_RESULT(TEST_FEEDBACK_STOP(), "TEST_FEEDBACK_STOP");

	TEST_INTERNAL_INIT();

	LOG_RESULT(TEST_FEEDBACK_PLAY_TYPE_BY_NAME(), "TEST_FEEDBACK_PLAY_TYPE_BY_NAME");
	LOG_RESULT(TEST_FEEDBACK_PLAY_INTERNAL(), "TEST_FEEDBACK_PLAY_INTERNAL");
	LOG_RESULT(TEST_FEEDBACK_PLAY_SOUNDPATH_INTERNAL(), "TEST_FEEDBACK_PLAY_SOUNDPATH_INTERNAL");
	LOG_RESULT(TEST_FEEDBACK_PLAY_TYPE_INTERNAL(), "TEST_FEEDBACK_PLAY_TYPE_INTERNAL");
	LOG_RESULT(TEST_FEEDBACK_PLAY_TYPE_SOUNDPATH_INTERNAL(), "TEST_FEEDBACK_PLAY_TYPE_SOUNDPATH_INTERNAL");
}

void show_usage()
{
	printf("Usage: feedback-test [OPTION] ...\n");
	printf("OPTION: \n");
	printf("  -a\t\t\tTest all APIs\n");
	printf("  -p <pattern name>\tPlay feedback with pattern name\n");
	printf("  \t-s\t\tfeedback type sound\n");
	printf("  \t-v\t\tfeedback type vibration\n");
}

void test_play(int argc, char **argv)
{
	int index = 1;
	const char *name = NULL;
	bool sound = false, vibration = false;

	while(index < argc) {
		if (0 == strcasecmp(argv[index], "-p")) {
			if (name) {
				show_usage();
				break;
			}
			index++;
			name = argv[index];
		} else if (0 == strcasecmp(argv[index], "-s"))
			sound = true;
		else if (0 == strcasecmp(argv[index], "-v"))
			vibration = true;
		else {
			show_usage();
			return ;
		}

		index++;
	}

	if (!name) {
		show_usage();
		return;
	}

	if (!sound && !vibration)
		feedback_play_by_name(name);
	else if (sound)
		printf("return: %s\n", feedback_play_sound_by_name(name));
	else if (vibration)
		printf("return: %s\n", feedback_play_vibration_by_name(name));

}

int main(int argc, char **argv)
{
	if (argc < 2) {
		show_usage();
		return 0;
	}

	if ((argc == 2) && (0 == strcasecmp(argv[1], "-a"))) {
		test_all();
		return 0;
	}

	if (argc >= 3)
		test_play(argc, argv);
	else
		show_usage();

	return 0;
}