Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | * |
michael@0 | 8 | * Date: 13 Sep 2002 |
michael@0 | 9 | * SUMMARY: Testing F.toString() |
michael@0 | 10 | * See http://bugzilla.mozilla.org/show_bug.cgi?id=168347 |
michael@0 | 11 | * |
michael@0 | 12 | */ |
michael@0 | 13 | //----------------------------------------------------------------------------- |
michael@0 | 14 | var UBound = 0; |
michael@0 | 15 | var BUGNUMBER = 168347; |
michael@0 | 16 | var summary = "Testing F.toString()"; |
michael@0 | 17 | var status = ''; |
michael@0 | 18 | var statusitems = []; |
michael@0 | 19 | var actual = ''; |
michael@0 | 20 | var actualvalues = []; |
michael@0 | 21 | var expect= ''; |
michael@0 | 22 | var expectedvalues = []; |
michael@0 | 23 | var FtoString = ''; |
michael@0 | 24 | var sFunc = ''; |
michael@0 | 25 | |
michael@0 | 26 | sFunc += 'function F()'; |
michael@0 | 27 | sFunc += '{'; |
michael@0 | 28 | sFunc += ' var f = arguments.callee;'; |
michael@0 | 29 | sFunc += ' f.i = 0;'; |
michael@0 | 30 | sFunc += ''; |
michael@0 | 31 | sFunc += ' try'; |
michael@0 | 32 | sFunc += ' {'; |
michael@0 | 33 | sFunc += ' f.i = f.i + 1;'; |
michael@0 | 34 | sFunc += ' print("i = i+1 succeeded \ti = " + f.i);'; |
michael@0 | 35 | sFunc += ' }'; |
michael@0 | 36 | sFunc += ' catch(e)'; |
michael@0 | 37 | sFunc += ' {'; |
michael@0 | 38 | sFunc += ' print("i = i+1 failed with " + e + "\ti = " + f.i);'; |
michael@0 | 39 | sFunc += ' }'; |
michael@0 | 40 | sFunc += ''; |
michael@0 | 41 | sFunc += ' try'; |
michael@0 | 42 | sFunc += ' {'; |
michael@0 | 43 | sFunc += ' ++f.i;'; |
michael@0 | 44 | sFunc += ' print("++i succeeded \t\ti = " + f.i);'; |
michael@0 | 45 | sFunc += ' }'; |
michael@0 | 46 | sFunc += ' catch(e)'; |
michael@0 | 47 | sFunc += ' {'; |
michael@0 | 48 | sFunc += ' print("++i failed with " + e + "\ti = " + f.i);'; |
michael@0 | 49 | sFunc += ' }'; |
michael@0 | 50 | sFunc += ''; |
michael@0 | 51 | sFunc += ' try'; |
michael@0 | 52 | sFunc += ' {'; |
michael@0 | 53 | sFunc += ' f.i++;'; |
michael@0 | 54 | sFunc += ' print("i++ succeeded \t\ti = " + f.i);'; |
michael@0 | 55 | sFunc += ' }'; |
michael@0 | 56 | sFunc += ' catch(e)'; |
michael@0 | 57 | sFunc += ' {'; |
michael@0 | 58 | sFunc += ' print("i++ failed with " + e + "\ti = " + f.i);'; |
michael@0 | 59 | sFunc += ' }'; |
michael@0 | 60 | sFunc += ''; |
michael@0 | 61 | sFunc += ' try'; |
michael@0 | 62 | sFunc += ' {'; |
michael@0 | 63 | sFunc += ' --f.i;'; |
michael@0 | 64 | sFunc += ' print("--i succeeded \t\ti = " + f.i);'; |
michael@0 | 65 | sFunc += ' }'; |
michael@0 | 66 | sFunc += ' catch(e)'; |
michael@0 | 67 | sFunc += ' {'; |
michael@0 | 68 | sFunc += ' print("--i failed with " + e + "\ti = " + f.i);'; |
michael@0 | 69 | sFunc += ' }'; |
michael@0 | 70 | sFunc += ''; |
michael@0 | 71 | sFunc += ' try'; |
michael@0 | 72 | sFunc += ' {'; |
michael@0 | 73 | sFunc += ' f.i--;'; |
michael@0 | 74 | sFunc += ' print("i-- succeeded \t\ti = " + f.i);'; |
michael@0 | 75 | sFunc += ' }'; |
michael@0 | 76 | sFunc += ' catch(e)'; |
michael@0 | 77 | sFunc += ' {'; |
michael@0 | 78 | sFunc += ' print("i-- failed with " + e + "\ti = " + f.i);'; |
michael@0 | 79 | sFunc += ' }'; |
michael@0 | 80 | sFunc += '}'; |
michael@0 | 81 | |
michael@0 | 82 | |
michael@0 | 83 | /* |
michael@0 | 84 | * Use sFunc to define the function F. The test |
michael@0 | 85 | * then rests on comparing F.toString() to sFunc. |
michael@0 | 86 | */ |
michael@0 | 87 | eval(sFunc); |
michael@0 | 88 | |
michael@0 | 89 | |
michael@0 | 90 | /* |
michael@0 | 91 | * There are trivial whitespace differences between F.toString() |
michael@0 | 92 | * and sFunc. So strip out whitespace before comparing them - |
michael@0 | 93 | */ |
michael@0 | 94 | sFunc = stripWhite(sFunc); |
michael@0 | 95 | FtoString = stripWhite(F.toString()); |
michael@0 | 96 | |
michael@0 | 97 | |
michael@0 | 98 | /* |
michael@0 | 99 | * Break comparison into sections to make any failures |
michael@0 | 100 | * easier for the developer to track down - |
michael@0 | 101 | */ |
michael@0 | 102 | status = inSection(1); |
michael@0 | 103 | actual = FtoString.substring(0,100); |
michael@0 | 104 | expect = sFunc.substring(0,100); |
michael@0 | 105 | addThis(); |
michael@0 | 106 | |
michael@0 | 107 | status = inSection(2); |
michael@0 | 108 | actual = FtoString.substring(100,200); |
michael@0 | 109 | expect = sFunc.substring(100,200); |
michael@0 | 110 | addThis(); |
michael@0 | 111 | |
michael@0 | 112 | status = inSection(3); |
michael@0 | 113 | actual = FtoString.substring(200,300); |
michael@0 | 114 | expect = sFunc.substring(200,300); |
michael@0 | 115 | addThis(); |
michael@0 | 116 | |
michael@0 | 117 | status = inSection(4); |
michael@0 | 118 | actual = FtoString.substring(300,400); |
michael@0 | 119 | expect = sFunc.substring(300,400); |
michael@0 | 120 | addThis(); |
michael@0 | 121 | |
michael@0 | 122 | status = inSection(5); |
michael@0 | 123 | actual = FtoString.substring(400,500); |
michael@0 | 124 | expect = sFunc.substring(400,500); |
michael@0 | 125 | addThis(); |
michael@0 | 126 | |
michael@0 | 127 | status = inSection(6); |
michael@0 | 128 | actual = FtoString.substring(500,600); |
michael@0 | 129 | expect = sFunc.substring(500,600); |
michael@0 | 130 | addThis(); |
michael@0 | 131 | |
michael@0 | 132 | status = inSection(7); |
michael@0 | 133 | actual = FtoString.substring(600,700); |
michael@0 | 134 | expect = sFunc.substring(600,700); |
michael@0 | 135 | addThis(); |
michael@0 | 136 | |
michael@0 | 137 | status = inSection(8); |
michael@0 | 138 | actual = FtoString.substring(700,800); |
michael@0 | 139 | expect = sFunc.substring(700,800); |
michael@0 | 140 | addThis(); |
michael@0 | 141 | |
michael@0 | 142 | status = inSection(9); |
michael@0 | 143 | actual = FtoString.substring(800,900); |
michael@0 | 144 | expect = sFunc.substring(800,900); |
michael@0 | 145 | addThis(); |
michael@0 | 146 | |
michael@0 | 147 | |
michael@0 | 148 | |
michael@0 | 149 | //----------------------------------------------------------------------------- |
michael@0 | 150 | test(); |
michael@0 | 151 | //----------------------------------------------------------------------------- |
michael@0 | 152 | |
michael@0 | 153 | |
michael@0 | 154 | |
michael@0 | 155 | function addThis() |
michael@0 | 156 | { |
michael@0 | 157 | statusitems[UBound] = status; |
michael@0 | 158 | actualvalues[UBound] = actual; |
michael@0 | 159 | expectedvalues[UBound] = expect; |
michael@0 | 160 | UBound++; |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | /* |
michael@0 | 164 | * Remove any whitespace characters; also |
michael@0 | 165 | * any escaped tabs or escaped newlines. |
michael@0 | 166 | */ |
michael@0 | 167 | function stripWhite(str) |
michael@0 | 168 | { |
michael@0 | 169 | var re = /\s|\\t|\\n/g; |
michael@0 | 170 | return str.replace(re, ''); |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | |
michael@0 | 174 | function test() |
michael@0 | 175 | { |
michael@0 | 176 | enterFunc('test'); |
michael@0 | 177 | printBugNumber(BUGNUMBER); |
michael@0 | 178 | printStatus(summary); |
michael@0 | 179 | |
michael@0 | 180 | for (var i=0; i<UBound; i++) |
michael@0 | 181 | { |
michael@0 | 182 | reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | exitFunc ('test'); |
michael@0 | 186 | } |