patch tizen_2.0_build
[framework/api/haptic.git] / TC / testcase / utc_system_haptic_play.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 <stdio.h>
19 #include <tet_api.h>
20 #include <haptic.h>
21
22 #define API_NAME_HAPTIC_PLAY_FILE "haptic_vibrate_file" 
23 #define API_NAME_PLAY_MONOTONE "haptic_vibrate_monotone"
24 #define API_NAME_STOP_PLAY "haptic_stop_device"
25 #define API_NAME_PLAY_PTN "haptic_play_pattern"
26 #define API_NAME_STOP_PTN "haptic_stop_pattern"
27 #define TEST_IVT "/usr/share/immersion/01_Touch/touch_20ms_sharp.ivt"
28
29 static void startup(void);
30 static void cleanup(void);
31
32 void (*tet_startup)(void) = startup;
33 void (*tet_cleanup)(void) = cleanup;
34
35 static void utc_system_haptic_vibrate_monotone_p(void);
36 static void utc_system_haptic_vibrate_monotone_n_1(void);
37 static void utc_system_haptic_vibrate_monotone_n_2(void);
38 static void utc_system_haptic_stop_device_p(void);
39 static void utc_system_haptic_stop_device_n(void);
40
41 static void utc_system_haptic_vibrate_p(void);
42 static void utc_system_haptic_vibrate_n(void);
43
44 static void utc_system_haptic_stop_pattern_p(void);
45 static void utc_system_haptic_stop_pattern_n(void);
46
47 enum {
48         POSITIVE_TC_IDX = 0x01,
49         NEGATIVE_TC_IDX,
50 };
51
52 struct tet_testlist tet_testlist[] = {
53     { utc_system_haptic_vibrate_monotone_p, POSITIVE_TC_IDX },
54     { utc_system_haptic_vibrate_monotone_n_1, NEGATIVE_TC_IDX },
55     { utc_system_haptic_vibrate_monotone_n_2, NEGATIVE_TC_IDX },
56         { utc_system_haptic_stop_device_p, POSITIVE_TC_IDX },
57         { utc_system_haptic_stop_device_n, NEGATIVE_TC_IDX },
58     { utc_system_haptic_vibrate_p, POSITIVE_TC_IDX},
59     { utc_system_haptic_vibrate_n, NEGATIVE_TC_IDX},
60     { utc_system_haptic_stop_pattern_p, POSITIVE_TC_IDX},
61     { utc_system_haptic_stop_pattern_n, NEGATIVE_TC_IDX},
62         { NULL, 0},
63 };
64
65
66 static void startup(void)
67 {
68     int error = HAPTIC_ERROR_NONE;
69
70     error = haptic_initialize();
71
72     dts_check_eq("haptic_initialize", error, HAPTIC_ERROR_NONE, "fail initialize in startup");
73 }
74
75 static void cleanup(void)
76 {
77     int error = HAPTIC_ERROR_NONE;
78
79     error = haptic_deinitialize();
80
81     dts_check_eq("haptic_deinitialize", error, HAPTIC_ERROR_NONE, "fail deinitialize in startup");
82 }
83
84
85 /**
86  * @brief Positive test case of haptic_vibrate_monotone()
87  */
88 static void utc_system_haptic_vibrate_monotone_p(void)
89 {
90     int error = HAPTIC_ERROR_NONE;
91
92     error = haptic_vibrate_monotone(0, 1000);
93     if(error != HAPTIC_ERROR_NONE)
94         dts_fail(API_NAME_PLAY_MONOTONE);
95
96     dts_pass(API_NAME_PLAY_MONOTONE);
97 }
98
99 /**
100  * @brief Negative test case of haptic_vibrate_monotone()
101  */
102 static void utc_system_haptic_vibrate_monotone_n_1(void)
103 {
104     int error = HAPTIC_ERROR_NONE;
105
106     error = haptic_vibrate_monotone(-1, 1000);
107     if(error == HAPTIC_ERROR_NONE)
108         dts_fail(API_NAME_PLAY_MONOTONE);
109
110     dts_pass(API_NAME_PLAY_MONOTONE);
111 }
112
113 /**
114  * @brief Negative test case of haptic_vibrate_monotone()
115  */
116 static void utc_system_haptic_vibrate_monotone_n_2(void)
117 {
118     int error = HAPTIC_ERROR_NONE;
119
120     error = haptic_vibrate_monotone(0, -1);
121     if(error == HAPTIC_ERROR_NONE)
122         dts_fail(API_NAME_PLAY_MONOTONE);
123
124     dts_pass(API_NAME_PLAY_MONOTONE);
125 }
126
127
128 /**
129  * @brief Positive test case of haptic_stop_device()
130  */
131 static void utc_system_haptic_stop_device_p(void)
132 {
133     int error = HAPTIC_ERROR_NONE;
134
135     error = haptic_vibrate_monotone(0, 1000);
136     if(error != HAPTIC_ERROR_NONE)
137         dts_fail(API_NAME_STOP_PLAY);
138
139     error = haptic_stop_device(0);
140     if(error != HAPTIC_ERROR_NONE)
141         dts_fail(API_NAME_STOP_PLAY);
142
143     dts_pass(API_NAME_STOP_PLAY);
144 }
145
146 /**
147  * @brief Negative test case of haptic_stop_device()
148  */
149 static void utc_system_haptic_stop_device_n(void)
150 {
151     int error = HAPTIC_ERROR_NONE;
152
153     error = haptic_stop_device(-1);
154     if(error == HAPTIC_ERROR_NONE)
155         dts_fail(API_NAME_STOP_PLAY);
156
157     dts_pass(API_NAME_STOP_PLAY);
158 }
159
160 static void utc_system_haptic_vibrate_p(void)
161 {
162     haptic_vibration_iter_s ptn[] = {
163         {0, HAPTIC_LEVEL_5, 500},
164         {0, HAPTIC_LEVEL_1, 500},
165     };
166
167     int ptn_id;
168     if(haptic_play_pattern(ptn, 2, 1, 0, &ptn_id) < 0){
169         dts_fail(API_NAME_PLAY_PTN);
170     }else{
171         dts_pass(API_NAME_PLAY_PTN);
172     }
173 }
174
175 static void utc_system_haptic_vibrate_n(void)
176 {
177     int ptn_id;
178     if(haptic_play_pattern(NULL, 7, 1, 0, &ptn_id) < 0){
179         dts_pass(API_NAME_PLAY_PTN);
180     }else{
181         dts_fail(API_NAME_PLAY_PTN);
182     }
183 }
184
185 static void utc_system_haptic_stop_pattern_p(void)
186 {
187     haptic_vibration_iter_s ptn[] = {
188         {0, HAPTIC_LEVEL_5, 500},
189         {0, HAPTIC_LEVEL_1, 500},
190     };
191
192     int ptn_id;
193     haptic_play_pattern(ptn, 2, 1, 0, &ptn_id);
194
195     int err = haptic_stop_pattern(ptn_id);
196     if(err < 0){
197         dts_fail(API_NAME_STOP_PTN);
198     }
199     else{
200         dts_pass(API_NAME_STOP_PTN);
201     }
202 }
203
204 static void utc_system_haptic_stop_pattern_n(void)
205 {
206     int err = haptic_stop_pattern(-1);
207     if(err < 0){
208         dts_pass(API_NAME_STOP_PTN);
209     }
210     else{
211         dts_fail(API_NAME_STOP_PTN);
212     }
213
214 }