2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * This file contains the implementation of test Orientation class.
19 * @author xiangguo.qi (xiangguo.qi @samsung.com)
24 var OrientationObj = deviceapis.orientation;
25 var OrientationWatchID = "";
28 function presenceTest()
30 TestEngine.test("Checking checking", true);
31 TestEngine.test("Checking deviceapis object", deviceapis);
32 TestEngine.test("Checking Orientation object", OrientationObj);
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));
39 function getSuccess(orientation)
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));
49 TestEngine.test("get current orientation", false);
53 function getCurrentOrientationValidParameters()
55 var cbObj = TestEngine.registerCallback("getCurrentOrientation", getSuccess, getFail, 3);
57 OrientationObj.getCurrentOrientation(cbObj.successCallback, cbObj.errorCallback);
58 TestEngine.test("exception not thrown", true);
60 TestEngine.logErr("Exception should not be thrown" + e);
63 OrientationObj.getCurrentOrientation(cbObj.successCallback);
64 TestEngine.test("exception not thrown", true);
66 TestEngine.logErr("Exception should not be thrown" + e);
69 OrientationObj.getCurrentOrientation(cbObj.successCallback, undefined);
70 TestEngine.test("exception not thrown", true);
72 TestEngine.logErr("Exception should not be thrown" + e);
78 function getCurrentOrientationInvalidParamsTest()
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]);
87 function successFail()
89 TestEngine.test("Correctly onError called", true);
93 function getCurrentOrientationCheckErrorCallback()
95 var failObj = TestEngine.registerCallback("getCurrentOrientation", getSuccess, successFail);
97 OrientationObj.getCurrentOrientation(undefined, failObj.errorCallback);
99 TestEngine.logErr("Exception should not be thrown" + e);
102 OrientationObj.getCurrentOrientation(1234, failObj.errorCallback);
103 TestEngine.logErr("Exception should be thrown");
105 TestEngine.logOK("Exception thrown" + e);
111 function watchOrientationInvalidParamsTest()
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]);
119 function watchOrientationCheck()
121 function watchSuccess(orientation)
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));
132 TestEngine.test("watch orientation",false);
135 var cbObj = TestEngine.registerCallback("watchOrientation", watchSuccess, watchFail);
137 OrientationWatchID = OrientationObj.watchOrientation(cbObj.successCallback, cbObj.errorCallback, {
138 minNotificationInterval:20
140 TestEngine.logOK("No exception thrown");
142 TestEngine.logErr("Exception should not be thrown" + e.toString());
147 function clearWatchTest()
151 OrientationObj.clearWatch(OrientationWatchID);
152 TestEngine.logOK("clearWatch OK");
155 TestEngine.logErr("clearWatch Error");
159 OrientationObj.clearWatch(undefined);
160 TestEngine.logOK("clearWatch OK");
163 TestEngine.logErr("clearWatch Error");
167 OrientationObj.clearWatch(null);
168 TestEngine.logOK("clearWatch OK");
171 TestEngine.logErr("clearWatch Error");
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");