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
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/
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
15 * The Original Code is JavaScript Engine testing utilities.
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.
23 * rogerl@netscape.com, pschwartau@netscape.com
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.
37 * ***** END LICENSE BLOCK ***** */
42 * SUMMARY: Utf8ToOneUcs4Char in jsstr.cpp ,overlong UTF-8 seqence detection problem
43 * See http://bugzilla.mozilla.org/show_bug.cgi?id=511859
46 //-----------------------------------------------------------------------------
48 var BUGNUMBER = 511859;
49 var summary = 'Utf8ToOneUcs4Char in jsstr.cpp ,overlong UTF-8 seqence detection problem';
53 var actualvalues = [];
55 var expectedvalues = [];
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 -
62 var EX="(Exception thrown)";
73 //Phase1: overlong sequences
76 status = "Overlong 2byte U+7f :" + arg;
77 actual = getActual(arg);
81 status = "Overlong 3byte U+7ff :" + arg;
82 actual = getActual(arg);
86 status = "Overlong 4byte U+8000 :" + arg;
87 actual = getActual(arg);
91 status = "Overlong 4byte U+ffff :" + arg;
92 actual = getActual(arg);
95 arg = "%F0%80%C0%80%80";
96 status = "Overlong 5byte U+20000 :" + arg;
97 actual = getActual(arg);
100 arg = "%F8%84%8F%BF%BF";
101 status = "Overlong 5byte U+10FFFF :" + arg;
102 actual = getActual(arg);
105 arg = "%FC%80%84%8F%BF%BF";
106 status = "Overlong 6byte U+10FFFF :" + arg;
107 actual = getActual(arg);
110 //Phase 2:Out of Unicode range
111 arg = "%F4%90%80%80%80";
112 status = "4byte 0x110000 :" + arg;
113 actual = getActual(arg);
115 arg = "%F8%84%90%80%80";
116 status = "5byte 0x110000 :" + arg;
117 actual = getActual(arg);
120 arg = "%FC%80%84%90%80%80";
121 status = "6byte 0x110000 :" + arg;
122 actual = getActual(arg);
125 //Phase 3:Valid sequences must be decoded correctly
127 status = "valid sequence U+7F :" + arg;
128 actual = getActual("%7F");
133 status = "valid sequence U+80 :" + arg;
134 actual = getActual(arg);
139 status = "valid sequence U+800 :" + arg;
140 actual = getActual("%E0%A0%80");
145 status = "valid sequence U+10000 :" + arg;
146 actual = getActual(arg);
147 expect = "\uD800\uDC00";
150 arg = "%F4%8F%BF%BF";
151 status = "valid sequence U+10FFFF :" + arg;
152 actual = getActual(arg);
153 expect = "\uDBFF\uDFFF";
156 //-----------------------------------------------------------------------------
158 //-----------------------------------------------------------------------------
164 statusitems[UBound] = status;
165 actualvalues[UBound] = actual;
166 expectedvalues[UBound] = expect;
174 printBugNumber(BUGNUMBER);
175 printStatus(summary);
177 for (var i=0; i<UBound; i++)
179 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
182 for (var i=5; i<=9; i++)
183 status = summary + ': UTF-8 test: bad UTF-8 sequence ' + i;
185 actual = 'No error!';
194 reportCompare(expect, actual, status);