Imported Upstream version 1.0.0
[platform/upstream/js.git] / js / src / tests / js1_5 / Regress / regress-511859.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 Communications Corp.
19  * Portions created by the Initial Developer are Copyright (C) 2002
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *   rogerl@netscape.com, pschwartau@netscape.com
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39 /*
40  *
41  * Date:    22 Aug 2009
42  * SUMMARY: Utf8ToOneUcs4Char in jsstr.cpp ,overlong UTF-8 seqence detection problem
43  * See http://bugzilla.mozilla.org/show_bug.cgi?id=511859
44  *
45  */
46 //-----------------------------------------------------------------------------
47 var UBound = 0;
48 var BUGNUMBER = 511859;
49 var summary = 'Utf8ToOneUcs4Char in jsstr.cpp ,overlong UTF-8 seqence detection problem';
50 var status = '';
51 var statusitems = [];
52 var actual = '';
53 var actualvalues = [];
54 var expect =  '';
55 var expectedvalues = [];
56 var arg;
57 /*
58  * The patch for http://bugzilla.mozilla.org/show_bug.cgi?id=511859
59  * defined this value to be the result of an overlong UTF-8 sequence -
60  */
61
62 var EX="(Exception thrown)";
63
64 function getActual(s)
65 {
66   try {
67     return decodeURI(s);
68   } catch (e) {
69     return EX;
70   }
71 }
72
73 //Phase1: overlong sequences
74 expect = EX;
75 arg = "%C1%BF";
76 status = "Overlong 2byte U+7f :" + arg;
77 actual = getActual(arg);
78 addThis();
79
80 arg = "%E0%9F%BF";
81 status = "Overlong 3byte U+7ff :" + arg;
82 actual = getActual(arg);
83 addThis();
84
85 arg = "%F0%88%80%80";
86 status = "Overlong 4byte U+8000 :" + arg;
87 actual = getActual(arg);
88 addThis();
89
90 arg = "%F0%8F%BF%BF";
91 status = "Overlong 4byte U+ffff :" + arg;
92 actual = getActual(arg);
93 addThis();
94
95 arg = "%F0%80%C0%80%80";
96 status = "Overlong 5byte U+20000 :" + arg;
97 actual = getActual(arg);
98 addThis();
99
100 arg = "%F8%84%8F%BF%BF";
101 status = "Overlong 5byte U+10FFFF :" + arg;
102 actual = getActual(arg);
103 addThis();
104
105 arg = "%FC%80%84%8F%BF%BF";
106 status = "Overlong 6byte U+10FFFF :" + arg;
107 actual = getActual(arg);
108 addThis();
109
110 //Phase 2:Out of Unicode range
111 arg = "%F4%90%80%80%80";
112 status = "4byte 0x110000 :" + arg;
113 actual = getActual(arg);
114 addThis();
115 arg = "%F8%84%90%80%80";
116 status = "5byte 0x110000 :" + arg;
117 actual = getActual(arg);
118 addThis();
119
120 arg = "%FC%80%84%90%80%80";
121 status = "6byte 0x110000 :" + arg;
122 actual = getActual(arg);
123 addThis();
124
125 //Phase 3:Valid sequences must be decoded correctly
126 arg = "%7F";
127 status = "valid sequence U+7F :" + arg;
128 actual = getActual("%7F");
129 expect = "\x7f";
130 addThis();
131
132 arg = "%C2%80";
133 status = "valid sequence U+80 :" + arg;
134 actual = getActual(arg);
135 expect = "\x80";
136 addThis();
137
138 arg = "%E0%A0%80";
139 status = "valid sequence U+800 :" + arg;
140 actual = getActual("%E0%A0%80");
141 expect = "\u0800";
142 addThis();
143
144 arg = "%F0%90%80%80"
145 status = "valid sequence U+10000 :" + arg;
146 actual = getActual(arg);
147 expect = "\uD800\uDC00";
148 addThis();
149
150 arg = "%F4%8F%BF%BF";
151 status = "valid sequence U+10FFFF :" + arg;
152 actual = getActual(arg);
153 expect = "\uDBFF\uDFFF";
154 addThis();
155
156 //-----------------------------------------------------------------------------
157 test();
158 //-----------------------------------------------------------------------------
159
160
161
162 function addThis()
163 {
164   statusitems[UBound] = status;
165   actualvalues[UBound] = actual;
166   expectedvalues[UBound] = expect;
167   UBound++;
168 }
169
170
171 function test()
172 {
173   enterFunc('test');
174   printBugNumber(BUGNUMBER);
175   printStatus(summary);
176
177   for (var i=0; i<UBound; i++)
178   {
179     reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
180   }
181
182   for (var i=5; i<=9; i++)
183     status = summary + ': UTF-8 test: bad UTF-8 sequence ' + i;
184     expect = 'Error';
185     actual = 'No error!';
186     try
187     {
188       testUTF8(i);
189     }
190     catch (e)
191     {
192       actual = 'Error';
193     }
194     reportCompare(expect, actual, status);
195
196   exitFunc('test');
197 }