tizen 2.3 release
[framework/web/wearable/wrt-security.git] / tests / smack_security / smackSecurityTest1 / js / WAC2.0 / TestOrientation.js
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * This file contains the implementation of test Orientation class.
18  *
19  * @author      xiangguo.qi (xiangguo.qi @samsung.com)
20  * @version     0.1
21  */
22
23
24 var OrientationObj = deviceapis.orientation;
25 var OrientationWatchID = "";
26
27 // Orientation001
28 function presenceTest()
29 {
30     TestEngine.test("Checking checking", true);
31     TestEngine.test("Checking deviceapis object", deviceapis);
32     TestEngine.test("Checking Orientation object", OrientationObj);
33
34     TestEngine.test("Checking type of getCurrentOrientation", isFunction(OrientationObj.getCurrentOrientation));
35     TestEngine.test("Checking type of watchOrientation", isFunction(OrientationObj.watchOrientation));
36     TestEngine.test("Checking type of clearWatch", isFunction(OrientationObj.clearWatch));
37 }
38
39 function getSuccess(orientation)
40 {
41     TestEngine.test("get current orientation", true);
42     TestEngine.test("orientation.alpha", isNumber(orientation.alpha));
43     TestEngine.test("orientation.beta", isNumber(orientation.beta));
44     TestEngine.test("orientation.gamma", isNumber(orientation.gamma));
45 }
46
47 function getFail()
48 {
49     TestEngine.test("get current orientation", false);
50 }
51
52 //Orientation002
53 function getCurrentOrientationValidParameters()
54 {
55     var cbObj = TestEngine.registerCallback("getCurrentOrientation", getSuccess, getFail, 3);
56     try {
57         OrientationObj.getCurrentOrientation(cbObj.successCallback, cbObj.errorCallback);
58         TestEngine.test("exception not thrown", true);
59     } catch(e) {
60         TestEngine.logErr("Exception should not be thrown" + e);
61     }
62     try {
63         OrientationObj.getCurrentOrientation(cbObj.successCallback);
64         TestEngine.test("exception not thrown", true);
65     } catch(e) {
66         TestEngine.logErr("Exception should not be thrown" + e);
67     }
68     try {
69         OrientationObj.getCurrentOrientation(cbObj.successCallback, undefined);
70         TestEngine.test("exception not thrown", true);
71     } catch(e) {
72         TestEngine.logErr("Exception should not be thrown" + e);
73     }
74
75 }
76
77 // Orientation003
78 function getCurrentOrientationInvalidParamsTest()
79 {
80     TestEngine.catchErrorType("code",17, OrientationObj, "getCurrentOrientation", 1234, undefined);
81     TestEngine.catchErrorType("code",17, OrientationObj, "getCurrentOrientation", "test");
82     TestEngine.catchErrorType("code",17, OrientationObj, "getCurrentOrientation", new Date());
83     TestEngine.catchErrorType("code",17, OrientationObj, "getCurrentOrientation", [6, 6, 6]);
84 }
85
86
87 function successFail()
88 {
89     TestEngine.test("Correctly onError called", true);
90 }
91
92 // Orientation004
93 function getCurrentOrientationCheckErrorCallback()
94 {
95     var failObj = TestEngine.registerCallback("getCurrentOrientation", getSuccess, successFail);
96     try {
97         OrientationObj.getCurrentOrientation(undefined, failObj.errorCallback);
98     } catch(e) {
99         TestEngine.logErr("Exception should not be thrown" + e);
100     }
101     try {
102         OrientationObj.getCurrentOrientation(1234, failObj.errorCallback);
103         TestEngine.logErr("Exception should be thrown");
104     } catch(e) {
105         TestEngine.logOK("Exception thrown" + e);
106     }
107 }
108
109
110 // Orientation005
111 function watchOrientationInvalidParamsTest()
112 {
113     TestEngine.catchErrorType("code",17, OrientationObj, "watchOrientation", "test");
114     TestEngine.catchErrorType("code",17, OrientationObj, "watchOrientation", new Date());
115     TestEngine.catchErrorType("code",17, OrientationObj, "watchOrientation", [6, 6, 6]);
116 }
117
118 // Orientation006
119 function watchOrientationCheck()
120 {
121     function watchSuccess(orientation)
122     {
123         OrientationObj.clearWatch(OrientationWatchID);
124         TestEngine.test("watch orientation",true);
125         TestEngine.test("orientation.alpha", isNumber(orientation.alpha));
126         TestEngine.test("orientation.beta", isNumber(orientation.beta));
127         TestEngine.test("orientation.gamma", isNumber(orientation.gamma));
128     }
129
130     function watchFail()
131     {
132         TestEngine.test("watch orientation",false);
133     }
134
135     var cbObj = TestEngine.registerCallback("watchOrientation", watchSuccess, watchFail);
136     try {
137         OrientationWatchID = OrientationObj.watchOrientation(cbObj.successCallback, cbObj.errorCallback, {
138             minNotificationInterval:20
139             });
140         TestEngine.logOK("No exception thrown");
141     } catch (e) {
142         TestEngine.logErr("Exception should not be thrown" + e.toString());
143     }
144 }
145
146 // Orientation007
147 function clearWatchTest()
148 {
149     try
150     {
151         OrientationObj.clearWatch(OrientationWatchID);
152         TestEngine.logOK("clearWatch OK");
153     }
154     catch (error) {
155         TestEngine.logErr("clearWatch Error");
156     }
157     try
158     {
159         OrientationObj.clearWatch(undefined);
160         TestEngine.logOK("clearWatch OK");
161     }
162     catch (error) {
163         TestEngine.logErr("clearWatch Error");
164     }
165     try
166     {
167         OrientationObj.clearWatch(null);
168         TestEngine.logOK("clearWatch OK");
169     }
170     catch (error) {
171         TestEngine.logErr("clearWatch Error");
172     }
173 }
174
175
176 //=============================================================================
177 TestEngine.setTestSuiteName("[WAC2.0][Orientation]", 2*1000); //2sec time out for callbacks
178 //TestEngine.addTest(true, presenceTest, "[WAC2.0][Orientation] Orientation functions presence test");
179 TestEngine.addTest(true, getCurrentOrientationValidParameters, "[WAC2.0][Orientation] Valid parameters");
180 //TestEngine.addTest(true, getCurrentOrientationInvalidParamsTest, "[WAC2.0][Orientation] getCurrentOrientation invalid params  test");
181 //TestEngine.addTest(true, getCurrentOrientationCheckErrorCallback, "[WAC2.0][Orientation] getCurrentOrientation test");
182 //TestEngine.addTest(true, watchOrientationInvalidParamsTest, "[WAC2.0][Orientation] watchOrientation invalid params  test");
183 //TestEngine.addTest(true, watchOrientationCheck, "[WAC2.0][Orientation] watchtAcceleration test");
184 //TestEngine.addTest(true, clearWatchTest, "[WAC2.0][Orientation] clearWatch test");
185
186