QML_RUNTIME_TESTING should be disabled by default.
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / parserstress / tests / ecma_2 / Statements / switch-004.js
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4  *
5  * The contents of this file are subject to the Mozilla Public License Version
6  * 1.1 (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  * http://www.mozilla.org/MPL/
9  *
10  * Software distributed under the License is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12  * for the specific language governing rights and limitations under the
13  * License.
14  *
15  * The Original Code is JavaScript Engine testing utilities.
16  *
17  * The Initial Developer of the Original Code is
18  * Netscape Communication Corporation.
19  * Portions created by the Initial Developer are Copyright (C) 1998
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *
24  * Alternatively, the contents of this file may be used under the terms of
25  * either the GNU General Public License Version 2 or later (the "GPL"), or
26  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27  * in which case the provisions of the GPL or the LGPL are applicable instead
28  * of those above. If you wish to allow use of your version of this file only
29  * under the terms of either the GPL or the LGPL, and not to allow others to
30  * use your version of this file under the terms of the MPL, indicate your
31  * decision by deleting the provisions above and replace them with the notice
32  * and other provisions required by the GPL or the LGPL. If you do not delete
33  * the provisions above, a recipient may use your version of this file under
34  * the terms of any one of the MPL, the GPL or the LGPL.
35  *
36  * ***** END LICENSE BLOCK ***** */
37
38 gTestfile = 'switch-004.js';
39
40 /**
41  *  File Name:          switch-003.js
42  *  ECMA Section:
43  *  Description:        The switch Statement
44  *
45  *  This uses variables and objects as case expressions in switch statements.
46  * This verifies a bunch of bugs:
47  *
48  * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=315988
49  * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=315975
50  * http://scopus.mcom.com/bugsplat/show_bug.cgi?id=315954
51  *
52  *  Author:             christine@netscape.com
53  *  Date:               11 August 1998
54  *
55  */
56 var SECTION = "switch-003";
57 var VERSION = "ECMA_2";
58 var TITLE   = "The switch statement";
59 var BUGNUMBER= "315988";
60
61 startTest();
62 writeHeaderToLog( SECTION + " "+ TITLE);
63
64 ONE = new Number(1);
65 ZERO = new Number(0);
66 var A = new String("A");
67 var B = new String("B");
68 TRUE = new Boolean( true );
69 FALSE = new Boolean( false );
70 UNDEFINED  = void 0;
71 NULL = null;
72
73 SwitchTest( ZERO, "ZERO" );
74 SwitchTest( NULL, "NULL" );
75 SwitchTest( UNDEFINED, "UNDEFINED" );
76 SwitchTest( FALSE, "FALSE" );
77 SwitchTest( false,  "false" );
78 SwitchTest( 0,      "0" );
79
80 SwitchTest ( TRUE, "TRUE" );
81 SwitchTest( 1,     "1" );
82 SwitchTest( ONE,   "ONE" );
83 SwitchTest( true,  "true" );
84
85 SwitchTest( "a",   "a" );
86 SwitchTest( A,     "A" );
87 SwitchTest( "b",   "b" );
88 SwitchTest( B,     "B" );
89
90 SwitchTest( new Boolean( true ), "default" );
91 SwitchTest( new Boolean(false ), "default" );
92 SwitchTest( new String( "A" ),   "default" );
93 SwitchTest( new Number( 0 ),     "default" );
94
95 test();
96
97 function SwitchTest( input, expect ) {
98   var result = "";
99
100   switch ( input ) {
101   default:   result += "default"; break;
102   case "a":  result += "a";       break;
103   case "b":  result += "b";       break;
104   case A:    result += "A";       break;
105   case B:    result += "B";       break;
106   case new Boolean(true): result += "new TRUE";   break;
107   case new Boolean(false): result += "new FALSE"; break;
108   case NULL: result += "NULL";    break;
109   case UNDEFINED: result += "UNDEFINED"; break;
110   case true: result += "true";    break;
111   case false: result += "false";  break;
112   case TRUE:  result += "TRUE";   break;
113   case FALSE: result += "FALSE";  break;
114   case 0:    result += "0";       break;
115   case 1:    result += "1";       break;
116   case new Number(0) : result += "new ZERO";  break;
117   case new Number(1) : result += "new ONE";   break;
118   case ONE:  result += "ONE";     break;
119   case ZERO: result += "ZERO";    break;
120   }
121
122   new TestCase(
123     SECTION,
124     "switch with no breaks:  input is " + input,
125     expect,
126     result );
127 }