Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Side by Side Diff: vm/dart_api_impl_test.cc

Issue 9075008: Cleanup some of the tests to use the macro TEST_CASE instead of UNIT_TEST_CASE (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/assert.h" 7 #include "vm/assert.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_api_state.h" 9 #include "vm/dart_api_state.h"
10 #include "vm/thread.h" 10 #include "vm/thread.h"
11 #include "vm/unit_test.h" 11 #include "vm/unit_test.h"
12 #include "vm/utils.h" 12 #include "vm/utils.h"
13 #include "vm/verifier.h" 13 #include "vm/verifier.h"
14 14
15 namespace dart { 15 namespace dart {
16 16
17 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests. 17 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests.
18 18
19 UNIT_TEST_CASE(ErrorHandles) { 19 TEST_CASE(ErrorHandles) {
20 const char* kScriptChars = 20 const char* kScriptChars =
21 "class TestClass {\n" 21 "class TestClass {\n"
22 " static void testMain() {\n" 22 " static void testMain() {\n"
23 " throw new Exception(\"bad news\");\n" 23 " throw new Exception(\"bad news\");\n"
24 " }\n" 24 " }\n"
25 "}\n"; 25 "}\n";
26 26
27 TestIsolateScope __test_isolate__;
28
29 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 27 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
30 28
31 Dart_Handle instance = Dart_True(); 29 Dart_Handle instance = Dart_True();
32 Dart_Handle error = Api::Error("myerror"); 30 Dart_Handle error = Api::Error("myerror");
33 Dart_Handle exception = Dart_InvokeStatic(lib, 31 Dart_Handle exception = Dart_InvokeStatic(lib,
34 Dart_NewString("TestClass"), 32 Dart_NewString("TestClass"),
35 Dart_NewString("testMain"), 33 Dart_NewString("testMain"),
36 0, 34 0,
37 NULL); 35 NULL);
38 36
(...skipping 18 matching lines...) Expand all
57 EXPECT_VALID(Dart_ErrorGetException(exception)); 55 EXPECT_VALID(Dart_ErrorGetException(exception));
58 56
59 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(instance))); 57 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(instance)));
60 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(error))); 58 EXPECT(Dart_IsError(Dart_ErrorGetStacktrace(error)));
61 EXPECT_VALID(Dart_ErrorGetStacktrace(exception)); 59 EXPECT_VALID(Dart_ErrorGetStacktrace(exception));
62 } 60 }
63 61
64 #endif 62 #endif
65 63
66 64
67 UNIT_TEST_CASE(Dart_Error) { 65 TEST_CASE(Dart_Error) {
68 TestIsolateScope __test_isolate__;
69
70 Dart_Handle error = Dart_Error("An %s", "error"); 66 Dart_Handle error = Dart_Error("An %s", "error");
71 EXPECT(Dart_IsError(error)); 67 EXPECT(Dart_IsError(error));
72 EXPECT_STREQ("An error", Dart_GetError(error)); 68 EXPECT_STREQ("An error", Dart_GetError(error));
73 } 69 }
74 70
75 71
76 UNIT_TEST_CASE(Null) { 72 TEST_CASE(Null) {
77 TestIsolateScope __test_isolate__;
78
79 Dart_Handle null = Dart_Null(); 73 Dart_Handle null = Dart_Null();
80 EXPECT_VALID(null); 74 EXPECT_VALID(null);
81 EXPECT(Dart_IsNull(null)); 75 EXPECT(Dart_IsNull(null));
82 76
83 Dart_Handle str = Dart_NewString("test"); 77 Dart_Handle str = Dart_NewString("test");
84 EXPECT_VALID(str); 78 EXPECT_VALID(str);
85 EXPECT(!Dart_IsNull(str)); 79 EXPECT(!Dart_IsNull(str));
86 } 80 }
87 81
88 82
89 UNIT_TEST_CASE(IsSame) { 83 TEST_CASE(IsSame) {
90 TestIsolateScope __test_isolate__;
91
92 bool same = false; 84 bool same = false;
93 Dart_Handle five = Dart_NewString("5"); 85 Dart_Handle five = Dart_NewString("5");
94 Dart_Handle five_again = Dart_NewString("5"); 86 Dart_Handle five_again = Dart_NewString("5");
95 Dart_Handle seven = Dart_NewString("7"); 87 Dart_Handle seven = Dart_NewString("7");
96 88
97 // Same objects. 89 // Same objects.
98 EXPECT_VALID(Dart_IsSame(five, five, &same)); 90 EXPECT_VALID(Dart_IsSame(five, five, &same));
99 EXPECT(same); 91 EXPECT(same);
100 92
101 // Equal objects. 93 // Equal objects.
(...skipping 16 matching lines...) Expand all
118 EXPECT(same); 110 EXPECT(same);
119 111
120 EXPECT_VALID(Dart_IsSame(class1, class2, &same)); 112 EXPECT_VALID(Dart_IsSame(class1, class2, &same));
121 EXPECT(!same); 113 EXPECT(!same);
122 } 114 }
123 } 115 }
124 116
125 117
126 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests. 118 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests.
127 119
128 UNIT_TEST_CASE(ObjectEquals) { 120 TEST_CASE(ObjectEquals) {
129 TestIsolateScope __test_isolate__;
130
131 bool equal = false; 121 bool equal = false;
132 Dart_Handle five = Dart_NewString("5"); 122 Dart_Handle five = Dart_NewString("5");
133 Dart_Handle five_again = Dart_NewString("5"); 123 Dart_Handle five_again = Dart_NewString("5");
134 Dart_Handle seven = Dart_NewString("7"); 124 Dart_Handle seven = Dart_NewString("7");
135 125
136 // Same objects. 126 // Same objects.
137 EXPECT_VALID(Dart_ObjectEquals(five, five, &equal)); 127 EXPECT_VALID(Dart_ObjectEquals(five, five, &equal));
138 EXPECT(equal); 128 EXPECT(equal);
139 129
140 // Equal objects. 130 // Equal objects.
141 EXPECT_VALID(Dart_ObjectEquals(five, five_again, &equal)); 131 EXPECT_VALID(Dart_ObjectEquals(five, five_again, &equal));
142 EXPECT(equal); 132 EXPECT(equal);
143 133
144 // Different objects. 134 // Different objects.
145 EXPECT_VALID(Dart_ObjectEquals(five, seven, &equal)); 135 EXPECT_VALID(Dart_ObjectEquals(five, seven, &equal));
146 EXPECT(!equal); 136 EXPECT(!equal);
147 } 137 }
148 138
149 #endif 139 #endif
150 140
151 UNIT_TEST_CASE(BooleanValues) { 141 TEST_CASE(BooleanValues) {
152 TestIsolateScope __test_isolate__;
153
154 Dart_Handle str = Dart_NewString("test"); 142 Dart_Handle str = Dart_NewString("test");
155 EXPECT(!Dart_IsBoolean(str)); 143 EXPECT(!Dart_IsBoolean(str));
156 144
157 bool value = false; 145 bool value = false;
158 Dart_Handle result = Dart_BooleanValue(str, &value); 146 Dart_Handle result = Dart_BooleanValue(str, &value);
159 EXPECT(Dart_IsError(result)); 147 EXPECT(Dart_IsError(result));
160 148
161 Dart_Handle val1 = Dart_NewBoolean(true); 149 Dart_Handle val1 = Dart_NewBoolean(true);
162 EXPECT(Dart_IsBoolean(val1)); 150 EXPECT(Dart_IsBoolean(val1));
163 151
164 result = Dart_BooleanValue(val1, &value); 152 result = Dart_BooleanValue(val1, &value);
165 EXPECT_VALID(result); 153 EXPECT_VALID(result);
166 EXPECT(value); 154 EXPECT(value);
167 155
168 Dart_Handle val2 = Dart_NewBoolean(false); 156 Dart_Handle val2 = Dart_NewBoolean(false);
169 EXPECT(Dart_IsBoolean(val2)); 157 EXPECT(Dart_IsBoolean(val2));
170 158
171 result = Dart_BooleanValue(val2, &value); 159 result = Dart_BooleanValue(val2, &value);
172 EXPECT_VALID(result); 160 EXPECT_VALID(result);
173 EXPECT(!value); 161 EXPECT(!value);
174 } 162 }
175 163
176 164
177 UNIT_TEST_CASE(BooleanConstants) { 165 TEST_CASE(BooleanConstants) {
178 TestIsolateScope __test_isolate__;
179
180 Dart_Handle true_handle = Dart_True(); 166 Dart_Handle true_handle = Dart_True();
181 EXPECT_VALID(true_handle); 167 EXPECT_VALID(true_handle);
182 EXPECT(Dart_IsBoolean(true_handle)); 168 EXPECT(Dart_IsBoolean(true_handle));
183 169
184 bool value = false; 170 bool value = false;
185 Dart_Handle result = Dart_BooleanValue(true_handle, &value); 171 Dart_Handle result = Dart_BooleanValue(true_handle, &value);
186 EXPECT_VALID(result); 172 EXPECT_VALID(result);
187 EXPECT(value); 173 EXPECT(value);
188 174
189 Dart_Handle false_handle = Dart_False(); 175 Dart_Handle false_handle = Dart_False();
190 EXPECT_VALID(false_handle); 176 EXPECT_VALID(false_handle);
191 EXPECT(Dart_IsBoolean(false_handle)); 177 EXPECT(Dart_IsBoolean(false_handle));
192 178
193 result = Dart_BooleanValue(false_handle, &value); 179 result = Dart_BooleanValue(false_handle, &value);
194 EXPECT_VALID(result); 180 EXPECT_VALID(result);
195 EXPECT(!value); 181 EXPECT(!value);
196 } 182 }
197 183
198 184
199 UNIT_TEST_CASE(DoubleValues) { 185 TEST_CASE(DoubleValues) {
200 TestIsolateScope __test_isolate__;
201
202 const double kDoubleVal1 = 201.29; 186 const double kDoubleVal1 = 201.29;
203 const double kDoubleVal2 = 101.19; 187 const double kDoubleVal2 = 101.19;
204 Dart_Handle val1 = Dart_NewDouble(kDoubleVal1); 188 Dart_Handle val1 = Dart_NewDouble(kDoubleVal1);
205 EXPECT(Dart_IsDouble(val1)); 189 EXPECT(Dart_IsDouble(val1));
206 Dart_Handle val2 = Dart_NewDouble(kDoubleVal2); 190 Dart_Handle val2 = Dart_NewDouble(kDoubleVal2);
207 EXPECT(Dart_IsDouble(val2)); 191 EXPECT(Dart_IsDouble(val2));
208 double out1, out2; 192 double out1, out2;
209 Dart_Handle result = Dart_DoubleValue(val1, &out1); 193 Dart_Handle result = Dart_DoubleValue(val1, &out1);
210 EXPECT_VALID(result); 194 EXPECT_VALID(result);
211 EXPECT_EQ(kDoubleVal1, out1); 195 EXPECT_EQ(kDoubleVal1, out1);
212 result = Dart_DoubleValue(val2, &out2); 196 result = Dart_DoubleValue(val2, &out2);
213 EXPECT_VALID(result); 197 EXPECT_VALID(result);
214 EXPECT_EQ(kDoubleVal2, out2); 198 EXPECT_EQ(kDoubleVal2, out2);
215 } 199 }
216 200
217 201
218 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests. 202 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests.
219 203
220 UNIT_TEST_CASE(NumberValues) { 204 TEST_CASE(NumberValues) {
221 // TODO(antonm): add various kinds of ints (smi, mint, bigint). 205 // TODO(antonm): add various kinds of ints (smi, mint, bigint).
222 const char* kScriptChars = 206 const char* kScriptChars =
223 "class NumberValuesHelper {\n" 207 "class NumberValuesHelper {\n"
224 " static int getInt() { return 1; }\n" 208 " static int getInt() { return 1; }\n"
225 " static double getDouble() { return 1.0; }\n" 209 " static double getDouble() { return 1.0; }\n"
226 " static bool getBool() { return false; }\n" 210 " static bool getBool() { return false; }\n"
227 " static getNull() { return null; }\n" 211 " static getNull() { return null; }\n"
228 "}\n"; 212 "}\n";
229 Dart_Handle result; 213 Dart_Handle result;
214 // Create a test library and Load up a test script in it.
215 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
230 216
231 TestIsolateScope __test_isolate__; 217 Dart_Handle class_name = Dart_NewString("NumberValuesHelper");
232 { 218 // Check int case.
233 // Create a test library and Load up a test script in it. 219 result = Dart_InvokeStatic(lib,
234 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 220 class_name,
221 Dart_NewString("getInt"),
222 0,
223 NULL);
224 EXPECT_VALID(result);
225 EXPECT(Dart_IsNumber(result));
235 226
236 Dart_Handle class_name = Dart_NewString("NumberValuesHelper"); 227 // Check double case.
237 // Check int case. 228 result = Dart_InvokeStatic(lib,
238 result = Dart_InvokeStatic(lib, 229 class_name,
239 class_name, 230 Dart_NewString("getDouble"),
240 Dart_NewString("getInt"), 231 0,
241 0, 232 NULL);
242 NULL); 233 EXPECT_VALID(result);
243 EXPECT_VALID(result); 234 EXPECT(Dart_IsNumber(result));
244 EXPECT(Dart_IsNumber(result));
245 235
246 // Check double case. 236 // Check bool case.
247 result = Dart_InvokeStatic(lib, 237 result = Dart_InvokeStatic(lib,
248 class_name, 238 class_name,
249 Dart_NewString("getDouble"), 239 Dart_NewString("getBool"),
250 0, 240 0,
251 NULL); 241 NULL);
252 EXPECT_VALID(result); 242 EXPECT_VALID(result);
253 EXPECT(Dart_IsNumber(result)); 243 EXPECT(!Dart_IsNumber(result));
254 244
255 // Check bool case. 245 // Check null case.
256 result = Dart_InvokeStatic(lib, 246 result = Dart_InvokeStatic(lib,
257 class_name, 247 class_name,
258 Dart_NewString("getBool"), 248 Dart_NewString("getNull"),
259 0, 249 0,
260 NULL); 250 NULL);
261 EXPECT_VALID(result); 251 EXPECT_VALID(result);
262 EXPECT(!Dart_IsNumber(result)); 252 EXPECT(!Dart_IsNumber(result));
263
264 // Check null case.
265 result = Dart_InvokeStatic(lib,
266 class_name,
267 Dart_NewString("getNull"),
268 0,
269 NULL);
270 EXPECT_VALID(result);
271 EXPECT(!Dart_IsNumber(result));
272 }
273 } 253 }
274 254
275 #endif 255 #endif
276 256
277 257
278 UNIT_TEST_CASE(IntegerValues) { 258 TEST_CASE(IntegerValues) {
279 TestIsolateScope __test_isolate__;
280
281 const int64_t kIntegerVal1 = 100; 259 const int64_t kIntegerVal1 = 100;
282 const int64_t kIntegerVal2 = 0xffffffff; 260 const int64_t kIntegerVal2 = 0xffffffff;
283 const char* kIntegerVal3 = "0x123456789123456789123456789"; 261 const char* kIntegerVal3 = "0x123456789123456789123456789";
284 262
285 Dart_Handle val1 = Dart_NewInteger(kIntegerVal1); 263 Dart_Handle val1 = Dart_NewInteger(kIntegerVal1);
286 EXPECT(Dart_IsInteger(val1)); 264 EXPECT(Dart_IsInteger(val1));
287 bool fits = false; 265 bool fits = false;
288 Dart_Handle result = Dart_IntegerFitsIntoInt64(val1, &fits); 266 Dart_Handle result = Dart_IntegerFitsIntoInt64(val1, &fits);
289 EXPECT_VALID(result); 267 EXPECT_VALID(result);
290 EXPECT(fits); 268 EXPECT(fits);
(...skipping 19 matching lines...) Expand all
310 EXPECT_VALID(result); 288 EXPECT_VALID(result);
311 EXPECT_EQ(kIntegerVal2, out); 289 EXPECT_EQ(kIntegerVal2, out);
312 290
313 const char* chars = NULL; 291 const char* chars = NULL;
314 result = Dart_IntegerToHexCString(val3, &chars); 292 result = Dart_IntegerToHexCString(val3, &chars);
315 EXPECT_VALID(result); 293 EXPECT_VALID(result);
316 EXPECT(!strcmp(kIntegerVal3, chars)); 294 EXPECT(!strcmp(kIntegerVal3, chars));
317 } 295 }
318 296
319 297
320 UNIT_TEST_CASE(IntegerFitsIntoInt64) { 298 TEST_CASE(IntegerFitsIntoInt64) {
321 TestIsolateScope __test_isolate__;
322
323 Dart_Handle max = Dart_NewInteger(DART_INT64_C(0x7FFFFFFFFFFFFFFF)); 299 Dart_Handle max = Dart_NewInteger(DART_INT64_C(0x7FFFFFFFFFFFFFFF));
324 EXPECT(Dart_IsInteger(max)); 300 EXPECT(Dart_IsInteger(max));
325 bool fits = false; 301 bool fits = false;
326 Dart_Handle result = Dart_IntegerFitsIntoInt64(max, &fits); 302 Dart_Handle result = Dart_IntegerFitsIntoInt64(max, &fits);
327 EXPECT_VALID(result); 303 EXPECT_VALID(result);
328 EXPECT(fits); 304 EXPECT(fits);
329 305
330 Dart_Handle above_max = Dart_NewIntegerFromHexCString("0x8000000000000000"); 306 Dart_Handle above_max = Dart_NewIntegerFromHexCString("0x8000000000000000");
331 EXPECT(Dart_IsInteger(above_max)); 307 EXPECT(Dart_IsInteger(above_max));
332 fits = true; 308 fits = true;
(...skipping 10 matching lines...) Expand all
343 319
344 Dart_Handle below_min = Dart_NewIntegerFromHexCString("-0x8000000000000001"); 320 Dart_Handle below_min = Dart_NewIntegerFromHexCString("-0x8000000000000001");
345 EXPECT(Dart_IsInteger(below_min)); 321 EXPECT(Dart_IsInteger(below_min));
346 fits = true; 322 fits = true;
347 result = Dart_IntegerFitsIntoInt64(below_min, &fits); 323 result = Dart_IntegerFitsIntoInt64(below_min, &fits);
348 EXPECT_VALID(result); 324 EXPECT_VALID(result);
349 EXPECT(!fits); 325 EXPECT(!fits);
350 } 326 }
351 327
352 328
353 UNIT_TEST_CASE(IntegerFitsIntoUint64) { 329 TEST_CASE(IntegerFitsIntoUint64) {
354 TestIsolateScope __test_isolate__;
355
356 Dart_Handle max = Dart_NewIntegerFromHexCString("0xFFFFFFFFFFFFFFFF"); 330 Dart_Handle max = Dart_NewIntegerFromHexCString("0xFFFFFFFFFFFFFFFF");
357 EXPECT(Dart_IsInteger(max)); 331 EXPECT(Dart_IsInteger(max));
358 bool fits = false; 332 bool fits = false;
359 Dart_Handle result = Dart_IntegerFitsIntoUint64(max, &fits); 333 Dart_Handle result = Dart_IntegerFitsIntoUint64(max, &fits);
360 EXPECT_VALID(result); 334 EXPECT_VALID(result);
361 EXPECT(fits); 335 EXPECT(fits);
362 336
363 Dart_Handle above_max = Dart_NewIntegerFromHexCString("0x10000000000000000"); 337 Dart_Handle above_max = Dart_NewIntegerFromHexCString("0x10000000000000000");
364 EXPECT(Dart_IsInteger(above_max)); 338 EXPECT(Dart_IsInteger(above_max));
365 fits = true; 339 fits = true;
(...skipping 10 matching lines...) Expand all
376 350
377 Dart_Handle below_min = Dart_NewIntegerFromHexCString("-1"); 351 Dart_Handle below_min = Dart_NewIntegerFromHexCString("-1");
378 EXPECT(Dart_IsInteger(below_min)); 352 EXPECT(Dart_IsInteger(below_min));
379 fits = true; 353 fits = true;
380 result = Dart_IntegerFitsIntoUint64(below_min, &fits); 354 result = Dart_IntegerFitsIntoUint64(below_min, &fits);
381 EXPECT_VALID(result); 355 EXPECT_VALID(result);
382 EXPECT(!fits); 356 EXPECT(!fits);
383 } 357 }
384 358
385 359
386 UNIT_TEST_CASE(ArrayValues) { 360 TEST_CASE(ArrayValues) {
387 TestIsolateScope __test_isolate__;
388
389 const int kArrayLength = 10; 361 const int kArrayLength = 10;
390 Dart_Handle str = Dart_NewString("test"); 362 Dart_Handle str = Dart_NewString("test");
391 EXPECT(!Dart_IsList(str)); 363 EXPECT(!Dart_IsList(str));
392 Dart_Handle val = Dart_NewList(kArrayLength); 364 Dart_Handle val = Dart_NewList(kArrayLength);
393 EXPECT(Dart_IsList(val)); 365 EXPECT(Dart_IsList(val));
394 intptr_t len = 0; 366 intptr_t len = 0;
395 Dart_Handle result = Dart_ListLength(val, &len); 367 Dart_Handle result = Dart_ListLength(val, &len);
396 EXPECT_VALID(result); 368 EXPECT_VALID(result);
397 EXPECT_EQ(kArrayLength, len); 369 EXPECT_EQ(kArrayLength, len);
398 370
(...skipping 15 matching lines...) Expand all
414 result = Dart_ListGetAt(val, i); 386 result = Dart_ListGetAt(val, i);
415 EXPECT_VALID(result); 387 EXPECT_VALID(result);
416 int64_t value; 388 int64_t value;
417 result = Dart_IntegerToInt64(result, &value); 389 result = Dart_IntegerToInt64(result, &value);
418 EXPECT_VALID(result); 390 EXPECT_VALID(result);
419 EXPECT_EQ(i, value); 391 EXPECT_EQ(i, value);
420 } 392 }
421 } 393 }
422 394
423 395
424 UNIT_TEST_CASE(IsString) { 396 TEST_CASE(IsString) {
425 TestIsolateScope __test_isolate__;
426
427 uint8_t data8[] = { 'o', 'n', 'e', 0xFF }; 397 uint8_t data8[] = { 'o', 'n', 'e', 0xFF };
428 398
429 Dart_Handle str8 = Dart_NewString8(data8, ARRAY_SIZE(data8)); 399 Dart_Handle str8 = Dart_NewString8(data8, ARRAY_SIZE(data8));
430 EXPECT_VALID(str8); 400 EXPECT_VALID(str8);
431 EXPECT(Dart_IsString(str8)); 401 EXPECT(Dart_IsString(str8));
432 EXPECT(Dart_IsString8(str8)); 402 EXPECT(Dart_IsString8(str8));
433 EXPECT(Dart_IsString16(str8)); 403 EXPECT(Dart_IsString16(str8));
434 EXPECT(!Dart_IsExternalString(str8)); 404 EXPECT(!Dart_IsExternalString(str8));
435 405
436 Dart_Handle ext8 = Dart_NewExternalString8(data8, ARRAY_SIZE(data8), 406 Dart_Handle ext8 = Dart_NewExternalString8(data8, ARRAY_SIZE(data8),
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 Dart_Handle ext32 = Dart_NewExternalString32(data32, ARRAY_SIZE(data32), 440 Dart_Handle ext32 = Dart_NewExternalString32(data32, ARRAY_SIZE(data32),
471 NULL, NULL); 441 NULL, NULL);
472 EXPECT_VALID(ext32); 442 EXPECT_VALID(ext32);
473 EXPECT(Dart_IsString(ext32)); 443 EXPECT(Dart_IsString(ext32));
474 EXPECT(!Dart_IsString8(ext32)); 444 EXPECT(!Dart_IsString8(ext32));
475 EXPECT(!Dart_IsString16(ext32)); 445 EXPECT(!Dart_IsString16(ext32));
476 EXPECT(Dart_IsExternalString(ext32)); 446 EXPECT(Dart_IsExternalString(ext32));
477 } 447 }
478 448
479 449
480 UNIT_TEST_CASE(ExternalStringGetPeer) { 450 TEST_CASE(ExternalStringGetPeer) {
481 TestIsolateScope __test_isolate__;
482 Dart_Handle result; 451 Dart_Handle result;
483 452
484 uint8_t data8[] = { 'o', 'n', 'e', 0xFF }; 453 uint8_t data8[] = { 'o', 'n', 'e', 0xFF };
485 int peer_data = 123; 454 int peer_data = 123;
486 void* peer = NULL; 455 void* peer = NULL;
487 456
488 // Success. 457 // Success.
489 Dart_Handle ext8 = Dart_NewExternalString8(data8, ARRAY_SIZE(data8), 458 Dart_Handle ext8 = Dart_NewExternalString8(data8, ARRAY_SIZE(data8),
490 &peer_data, NULL); 459 &peer_data, NULL);
491 EXPECT_VALID(ext8); 460 EXPECT_VALID(ext8);
(...skipping 23 matching lines...) Expand all
515 result = Dart_ExternalStringGetPeer(Dart_True(), &peer); 484 result = Dart_ExternalStringGetPeer(Dart_True(), &peer);
516 EXPECT(Dart_IsError(result)); 485 EXPECT(Dart_IsError(result));
517 EXPECT_STREQ("Dart_ExternalStringGetPeer expects argument 'object' to be " 486 EXPECT_STREQ("Dart_ExternalStringGetPeer expects argument 'object' to be "
518 "of type String.", Dart_GetError(result)); 487 "of type String.", Dart_GetError(result));
519 EXPECT(peer == NULL); 488 EXPECT(peer == NULL);
520 } 489 }
521 490
522 491
523 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests. 492 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests.
524 493
525 UNIT_TEST_CASE(ListAccess) { 494 TEST_CASE(ListAccess) {
526 const char* kScriptChars = 495 const char* kScriptChars =
527 "class ListAccessTest {" 496 "class ListAccessTest {"
528 " ListAccessTest() {}" 497 " ListAccessTest() {}"
529 " static List testMain() {" 498 " static List testMain() {"
530 " List a = new List();" 499 " List a = new List();"
531 " a.add(10);" 500 " a.add(10);"
532 " a.add(20);" 501 " a.add(20);"
533 " a.add(30);" 502 " a.add(30);"
534 " return a;" 503 " return a;"
535 " }" 504 " }"
536 "}"; 505 "}";
537 Dart_Handle result; 506 Dart_Handle result;
538 507
539 TestIsolateScope __test_isolate__; 508 // Create a test library and Load up a test script in it.
540 { 509 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
541 // Create a test library and Load up a test script in it.
542 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
543 510
544 // Invoke a function which returns an object of type InstanceOf.. 511 // Invoke a function which returns an object of type InstanceOf..
545 result = Dart_InvokeStatic(lib, 512 result = Dart_InvokeStatic(lib,
546 Dart_NewString("ListAccessTest"), 513 Dart_NewString("ListAccessTest"),
547 Dart_NewString("testMain"), 514 Dart_NewString("testMain"),
548 0, 515 0,
549 NULL); 516 NULL);
550 EXPECT_VALID(result); 517 EXPECT_VALID(result);
551 518
552 // First ensure that the returned object is an array. 519 // First ensure that the returned object is an array.
553 Dart_Handle ListAccessTestObj = result; 520 Dart_Handle ListAccessTestObj = result;
554 521
555 EXPECT(Dart_IsList(ListAccessTestObj)); 522 EXPECT(Dart_IsList(ListAccessTestObj));
556 523
557 // Get length of array object. 524 // Get length of array object.
558 intptr_t len = 0; 525 intptr_t len = 0;
559 result = Dart_ListLength(ListAccessTestObj, &len); 526 result = Dart_ListLength(ListAccessTestObj, &len);
560 EXPECT_VALID(result); 527 EXPECT_VALID(result);
561 EXPECT_EQ(3, len); 528 EXPECT_EQ(3, len);
562 529
563 // Access elements in the array. 530 // Access elements in the array.
564 int64_t value; 531 int64_t value;
565 532
566 result = Dart_ListGetAt(ListAccessTestObj, 0); 533 result = Dart_ListGetAt(ListAccessTestObj, 0);
567 EXPECT_VALID(result); 534 EXPECT_VALID(result);
568 result = Dart_IntegerToInt64(result, &value); 535 result = Dart_IntegerToInt64(result, &value);
569 EXPECT_VALID(result); 536 EXPECT_VALID(result);
570 EXPECT_EQ(10, value); 537 EXPECT_EQ(10, value);
571 538
572 result = Dart_ListGetAt(ListAccessTestObj, 1); 539 result = Dart_ListGetAt(ListAccessTestObj, 1);
573 EXPECT_VALID(result); 540 EXPECT_VALID(result);
574 result = Dart_IntegerToInt64(result, &value); 541 result = Dart_IntegerToInt64(result, &value);
575 EXPECT_VALID(result); 542 EXPECT_VALID(result);
576 EXPECT_EQ(20, value); 543 EXPECT_EQ(20, value);
577 544
578 result = Dart_ListGetAt(ListAccessTestObj, 2); 545 result = Dart_ListGetAt(ListAccessTestObj, 2);
579 EXPECT_VALID(result); 546 EXPECT_VALID(result);
580 result = Dart_IntegerToInt64(result, &value); 547 result = Dart_IntegerToInt64(result, &value);
581 EXPECT_VALID(result); 548 EXPECT_VALID(result);
582 EXPECT_EQ(30, value); 549 EXPECT_EQ(30, value);
583 550
584 // Set some elements in the array. 551 // Set some elements in the array.
585 result = Dart_ListSetAt(ListAccessTestObj, 0, Dart_NewInteger(0)); 552 result = Dart_ListSetAt(ListAccessTestObj, 0, Dart_NewInteger(0));
586 EXPECT_VALID(result); 553 EXPECT_VALID(result);
587 result = Dart_ListSetAt(ListAccessTestObj, 1, Dart_NewInteger(1)); 554 result = Dart_ListSetAt(ListAccessTestObj, 1, Dart_NewInteger(1));
588 EXPECT_VALID(result); 555 EXPECT_VALID(result);
589 result = Dart_ListSetAt(ListAccessTestObj, 2, Dart_NewInteger(2)); 556 result = Dart_ListSetAt(ListAccessTestObj, 2, Dart_NewInteger(2));
590 EXPECT_VALID(result); 557 EXPECT_VALID(result);
591 558
592 // Get length of array object. 559 // Get length of array object.
593 result = Dart_ListLength(ListAccessTestObj, &len); 560 result = Dart_ListLength(ListAccessTestObj, &len);
594 EXPECT_VALID(result); 561 EXPECT_VALID(result);
595 EXPECT_EQ(3, len); 562 EXPECT_EQ(3, len);
596 563
597 // Now try and access these elements in the array. 564 // Now try and access these elements in the array.
598 result = Dart_ListGetAt(ListAccessTestObj, 0); 565 result = Dart_ListGetAt(ListAccessTestObj, 0);
599 EXPECT_VALID(result); 566 EXPECT_VALID(result);
600 result = Dart_IntegerToInt64(result, &value); 567 result = Dart_IntegerToInt64(result, &value);
601 EXPECT_VALID(result); 568 EXPECT_VALID(result);
602 EXPECT_EQ(0, value); 569 EXPECT_EQ(0, value);
603 570
604 result = Dart_ListGetAt(ListAccessTestObj, 1); 571 result = Dart_ListGetAt(ListAccessTestObj, 1);
605 EXPECT_VALID(result); 572 EXPECT_VALID(result);
606 result = Dart_IntegerToInt64(result, &value); 573 result = Dart_IntegerToInt64(result, &value);
607 EXPECT_VALID(result); 574 EXPECT_VALID(result);
608 EXPECT_EQ(1, value); 575 EXPECT_EQ(1, value);
609 576
610 result = Dart_ListGetAt(ListAccessTestObj, 2); 577 result = Dart_ListGetAt(ListAccessTestObj, 2);
611 EXPECT_VALID(result); 578 EXPECT_VALID(result);
612 result = Dart_IntegerToInt64(result, &value); 579 result = Dart_IntegerToInt64(result, &value);
613 EXPECT_VALID(result); 580 EXPECT_VALID(result);
614 EXPECT_EQ(2, value); 581 EXPECT_EQ(2, value);
615 582
616 uint8_t native_array[3]; 583 uint8_t native_array[3];
617 result = Dart_ListGetAsBytes(ListAccessTestObj, 0, native_array, 3); 584 result = Dart_ListGetAsBytes(ListAccessTestObj, 0, native_array, 3);
618 EXPECT_VALID(result); 585 EXPECT_VALID(result);
619 EXPECT_EQ(0, native_array[0]); 586 EXPECT_EQ(0, native_array[0]);
620 EXPECT_EQ(1, native_array[1]); 587 EXPECT_EQ(1, native_array[1]);
621 EXPECT_EQ(2, native_array[2]); 588 EXPECT_EQ(2, native_array[2]);
622 589
623 native_array[0] = 10; 590 native_array[0] = 10;
624 native_array[1] = 20; 591 native_array[1] = 20;
625 native_array[2] = 30; 592 native_array[2] = 30;
626 result = Dart_ListSetAsBytes(ListAccessTestObj, 0, native_array, 3); 593 result = Dart_ListSetAsBytes(ListAccessTestObj, 0, native_array, 3);
627 EXPECT_VALID(result); 594 EXPECT_VALID(result);
628 result = Dart_ListGetAsBytes(ListAccessTestObj, 0, native_array, 3); 595 result = Dart_ListGetAsBytes(ListAccessTestObj, 0, native_array, 3);
629 EXPECT_VALID(result); 596 EXPECT_VALID(result);
630 EXPECT_EQ(10, native_array[0]); 597 EXPECT_EQ(10, native_array[0]);
631 EXPECT_EQ(20, native_array[1]); 598 EXPECT_EQ(20, native_array[1]);
632 EXPECT_EQ(30, native_array[2]); 599 EXPECT_EQ(30, native_array[2]);
633 result = Dart_ListGetAt(ListAccessTestObj, 2); 600 result = Dart_ListGetAt(ListAccessTestObj, 2);
634 EXPECT_VALID(result); 601 EXPECT_VALID(result);
635 result = Dart_IntegerToInt64(result, &value); 602 result = Dart_IntegerToInt64(result, &value);
636 EXPECT_VALID(result); 603 EXPECT_VALID(result);
637 EXPECT_EQ(30, value); 604 EXPECT_EQ(30, value);
638 605
639 // Check if we get an exception when accessing beyond limit. 606 // Check if we get an exception when accessing beyond limit.
640 result = Dart_ListGetAt(ListAccessTestObj, 4); 607 result = Dart_ListGetAt(ListAccessTestObj, 4);
641 EXPECT(Dart_IsError(result)); 608 EXPECT(Dart_IsError(result));
642 }
643 } 609 }
644 610
645 #endif // TARGET_ARCH_IA32. 611 #endif // TARGET_ARCH_IA32.
646 612
647 613
648 // Unit test for entering a scope, creating a local handle and exiting 614 // Unit test for entering a scope, creating a local handle and exiting
649 // the scope. 615 // the scope.
650 UNIT_TEST_CASE(EnterExitScope) { 616 UNIT_TEST_CASE(EnterExitScope) {
651 TestIsolateScope __test_isolate__; 617 TestIsolateScope __test_isolate__;
652 618
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
1026 Dart_SetMessageCallbacks(&MyPostMessageCallback, &MyClosePortCallback); 992 Dart_SetMessageCallbacks(&MyPostMessageCallback, &MyClosePortCallback);
1027 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate); 993 Isolate* isolate = reinterpret_cast<Isolate*>(dart_isolate);
1028 EXPECT_EQ(&MyPostMessageCallback, isolate->post_message_callback()); 994 EXPECT_EQ(&MyPostMessageCallback, isolate->post_message_callback());
1029 EXPECT_EQ(&MyClosePortCallback, isolate->close_port_callback()); 995 EXPECT_EQ(&MyClosePortCallback, isolate->close_port_callback());
1030 Dart_ShutdownIsolate(); 996 Dart_ShutdownIsolate();
1031 } 997 }
1032 998
1033 999
1034 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests. 1000 #if defined(TARGET_ARCH_IA32) // only ia32 can run execution tests.
1035 1001
1036 UNIT_TEST_CASE(FieldAccess) { 1002 TEST_CASE(FieldAccess) {
1037 const char* kScriptChars = 1003 const char* kScriptChars =
1038 "class Fields {\n" 1004 "class Fields {\n"
1039 " Fields(int i, int j) : fld1 = i, fld2 = j {}\n" 1005 " Fields(int i, int j) : fld1 = i, fld2 = j {}\n"
1040 " int fld1;\n" 1006 " int fld1;\n"
1041 " final int fld2;\n" 1007 " final int fld2;\n"
1042 " static int fld3;\n" 1008 " static int fld3;\n"
1043 " static final int fld4 = 10;\n" 1009 " static final int fld4 = 10;\n"
1044 "}\n" 1010 "}\n"
1045 "class FieldsTest {\n" 1011 "class FieldsTest {\n"
1046 " static Fields testMain() {\n" 1012 " static Fields testMain() {\n"
1047 " Fields obj = new Fields(10, 20);\n" 1013 " Fields obj = new Fields(10, 20);\n"
1048 " return obj;\n" 1014 " return obj;\n"
1049 " }\n" 1015 " }\n"
1050 "}\n"; 1016 "}\n";
1051 Dart_Handle result; 1017 Dart_Handle result;
1018 // Create a test library and Load up a test script in it.
1019 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1052 1020
1053 TestIsolateScope __test_isolate__; 1021 // Invoke a function which returns an object.
1054 { 1022 Dart_Handle retobj = Dart_InvokeStatic(lib,
1055 // Create a test library and Load up a test script in it. 1023 Dart_NewString("FieldsTest"),
1056 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1024 Dart_NewString("testMain"),
1025 0,
1026 NULL);
1027 EXPECT_VALID(retobj);
1057 1028
1058 // Invoke a function which returns an object. 1029 // Now access and set various static fields of Fields class.
1059 Dart_Handle retobj = Dart_InvokeStatic(lib, 1030 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Fields"));
1060 Dart_NewString("FieldsTest"), 1031 EXPECT_VALID(cls);
1061 Dart_NewString("testMain"), 1032 result = Dart_GetStaticField(cls, Dart_NewString("fld1"));
1062 0, 1033 EXPECT(Dart_IsError(result));
1063 NULL); 1034 result = Dart_GetInstanceField(retobj, Dart_NewString("fld3"));
1064 EXPECT_VALID(retobj); 1035 EXPECT(Dart_IsError(result));
1036 result = Dart_GetStaticField(cls, Dart_NewString("fld4"));
1037 EXPECT_VALID(result);
1038 int64_t value = 0;
1039 result = Dart_IntegerToInt64(result, &value);
1040 EXPECT_EQ(10, value);
1041 result = Dart_SetStaticField(cls,
1042 Dart_NewString("fld4"),
1043 Dart_NewInteger(20));
1044 EXPECT(Dart_IsError(result));
1045 result = Dart_GetStaticField(cls, Dart_NewString("fld3"));
1046 EXPECT_VALID(result);
1047 result = Dart_SetStaticField(cls,
1048 Dart_NewString("fld3"),
1049 Dart_NewInteger(200));
1050 EXPECT_VALID(result);
1051 result = Dart_IntegerToInt64(result, &value);
1052 EXPECT_EQ(200, value);
1065 1053
1066 // Now access and set various static fields of Fields class. 1054 // Now access and set various instance fields of the returned object.
1067 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("Fields")); 1055 result = Dart_GetInstanceField(retobj, Dart_NewString("fld3"));
1068 EXPECT_VALID(cls); 1056 EXPECT(Dart_IsError(result));
1069 result = Dart_GetStaticField(cls, Dart_NewString("fld1")); 1057 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1"));
1070 EXPECT(Dart_IsError(result)); 1058 EXPECT_VALID(result);
1071 result = Dart_GetInstanceField(retobj, Dart_NewString("fld3")); 1059 result = Dart_IntegerToInt64(result, &value);
1072 EXPECT(Dart_IsError(result)); 1060 EXPECT_EQ(10, value);
1073 result = Dart_GetStaticField(cls, Dart_NewString("fld4")); 1061 result = Dart_GetInstanceField(retobj, Dart_NewString("fld2"));
1074 EXPECT_VALID(result); 1062 EXPECT_VALID(result);
1075 int64_t value = 0; 1063 result = Dart_IntegerToInt64(result, &value);
1076 result = Dart_IntegerToInt64(result, &value); 1064 EXPECT_EQ(20, value);
1077 EXPECT_EQ(10, value); 1065 result = Dart_SetInstanceField(retobj,
1078 result = Dart_SetStaticField(cls, 1066 Dart_NewString("fld2"),
1079 Dart_NewString("fld4"), 1067 Dart_NewInteger(40));
1080 Dart_NewInteger(20)); 1068 EXPECT(Dart_IsError(result));
1081 EXPECT(Dart_IsError(result)); 1069 result = Dart_SetInstanceField(retobj,
1082 result = Dart_GetStaticField(cls, Dart_NewString("fld3")); 1070 Dart_NewString("fld1"),
1083 EXPECT_VALID(result); 1071 Dart_NewInteger(40));
1084 result = Dart_SetStaticField(cls, 1072 EXPECT_VALID(result);
1085 Dart_NewString("fld3"), 1073 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1"));
1086 Dart_NewInteger(200)); 1074 EXPECT_VALID(result);
1087 EXPECT_VALID(result); 1075 result = Dart_IntegerToInt64(result, &value);
1088 result = Dart_IntegerToInt64(result, &value); 1076 EXPECT_EQ(40, value);
1089 EXPECT_EQ(200, value);
1090
1091 // Now access and set various instance fields of the returned object.
1092 result = Dart_GetInstanceField(retobj, Dart_NewString("fld3"));
1093 EXPECT(Dart_IsError(result));
1094 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1"));
1095 EXPECT_VALID(result);
1096 result = Dart_IntegerToInt64(result, &value);
1097 EXPECT_EQ(10, value);
1098 result = Dart_GetInstanceField(retobj, Dart_NewString("fld2"));
1099 EXPECT_VALID(result);
1100 result = Dart_IntegerToInt64(result, &value);
1101 EXPECT_EQ(20, value);
1102 result = Dart_SetInstanceField(retobj,
1103 Dart_NewString("fld2"),
1104 Dart_NewInteger(40));
1105 EXPECT(Dart_IsError(result));
1106 result = Dart_SetInstanceField(retobj,
1107 Dart_NewString("fld1"),
1108 Dart_NewInteger(40));
1109 EXPECT_VALID(result);
1110 result = Dart_GetInstanceField(retobj, Dart_NewString("fld1"));
1111 EXPECT_VALID(result);
1112 result = Dart_IntegerToInt64(result, &value);
1113 EXPECT_EQ(40, value);
1114 }
1115 } 1077 }
1116 1078
1117 1079
1118 UNIT_TEST_CASE(HiddenFieldAccess) { 1080 TEST_CASE(HiddenFieldAccess) {
1119 const char* kScriptChars = 1081 const char* kScriptChars =
1120 "class HiddenFields {\n" 1082 "class HiddenFields {\n"
1121 " HiddenFields(int i, int j) : _fld1 = i, _fld2 = j {}\n" 1083 " HiddenFields(int i, int j) : _fld1 = i, _fld2 = j {}\n"
1122 " int _fld1;\n" 1084 " int _fld1;\n"
1123 " final int _fld2;\n" 1085 " final int _fld2;\n"
1124 " static int _fld3;\n" 1086 " static int _fld3;\n"
1125 " static final int _fld4 = 10;\n" 1087 " static final int _fld4 = 10;\n"
1126 "}\n" 1088 "}\n"
1127 "class HiddenFieldsTest {\n" 1089 "class HiddenFieldsTest {\n"
1128 " static HiddenFields testMain() {\n" 1090 " static HiddenFields testMain() {\n"
1129 " HiddenFields obj = new HiddenFields(10, 20);\n" 1091 " HiddenFields obj = new HiddenFields(10, 20);\n"
1130 " return obj;\n" 1092 " return obj;\n"
1131 " }\n" 1093 " }\n"
1132 "}\n"; 1094 "}\n";
1133 Dart_Handle result; 1095 Dart_Handle result;
1096 // Load up a test script which extends the native wrapper class.
1097 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1134 1098
1135 TestIsolateScope __test_isolate__; 1099 // Invoke a function which returns an object.
1136 { 1100 Dart_Handle retobj = Dart_InvokeStatic(lib,
1137 // Load up a test script which extends the native wrapper class. 1101 Dart_NewString("HiddenFieldsTest"),
1138 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1102 Dart_NewString("testMain"),
1103 0,
1104 NULL);
1105 EXPECT_VALID(retobj);
1139 1106
1140 // Invoke a function which returns an object. 1107 // Now access and set various static fields of HiddenFields class.
1141 Dart_Handle retobj = Dart_InvokeStatic(lib, 1108 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("HiddenFields"));
1142 Dart_NewString("HiddenFieldsTest"), 1109 EXPECT_VALID(cls);
1143 Dart_NewString("testMain"), 1110 result = Dart_GetStaticField(cls, Dart_NewString("_fld1"));
1144 0, 1111 EXPECT(Dart_IsError(result));
1145 NULL); 1112 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld3"));
1146 EXPECT_VALID(retobj); 1113 EXPECT(Dart_IsError(result));
1114 result = Dart_GetStaticField(cls, Dart_NewString("_fld4"));
1115 EXPECT_VALID(result);
1116 int64_t value = 0;
1117 result = Dart_IntegerToInt64(result, &value);
1118 EXPECT_EQ(10, value);
1119 result = Dart_SetStaticField(cls,
1120 Dart_NewString("_fld4"),
1121 Dart_NewInteger(20));
1122 EXPECT(Dart_IsError(result));
1123 result = Dart_GetStaticField(cls, Dart_NewString("_fld3"));
1124 EXPECT_VALID(result);
1125 result = Dart_SetStaticField(cls,
1126 Dart_NewString("_fld3"),
1127 Dart_NewInteger(200));
1128 EXPECT_VALID(result);
1129 result = Dart_IntegerToInt64(result, &value);
1130 EXPECT_EQ(200, value);
1147 1131
1148 // Now access and set various static fields of HiddenFields class. 1132 // Now access and set various instance fields of the returned object.
1149 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("HiddenFields")); 1133 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld3"));
1150 EXPECT_VALID(cls); 1134 EXPECT(Dart_IsError(result));
1151 result = Dart_GetStaticField(cls, Dart_NewString("_fld1")); 1135 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld1"));
1152 EXPECT(Dart_IsError(result)); 1136 EXPECT_VALID(result);
1153 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld3")); 1137 result = Dart_IntegerToInt64(result, &value);
1154 EXPECT(Dart_IsError(result)); 1138 EXPECT_EQ(10, value);
1155 result = Dart_GetStaticField(cls, Dart_NewString("_fld4")); 1139 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld2"));
1156 EXPECT_VALID(result); 1140 EXPECT_VALID(result);
1157 int64_t value = 0; 1141 result = Dart_IntegerToInt64(result, &value);
1158 result = Dart_IntegerToInt64(result, &value); 1142 EXPECT_EQ(20, value);
1159 EXPECT_EQ(10, value); 1143 result = Dart_SetInstanceField(retobj,
1160 result = Dart_SetStaticField(cls, 1144 Dart_NewString("_fld2"),
1161 Dart_NewString("_fld4"), 1145 Dart_NewInteger(40));
1162 Dart_NewInteger(20)); 1146 EXPECT(Dart_IsError(result));
1163 EXPECT(Dart_IsError(result)); 1147 result = Dart_SetInstanceField(retobj,
1164 result = Dart_GetStaticField(cls, Dart_NewString("_fld3")); 1148 Dart_NewString("_fld1"),
1165 EXPECT_VALID(result); 1149 Dart_NewInteger(40));
1166 result = Dart_SetStaticField(cls, 1150 EXPECT_VALID(result);
1167 Dart_NewString("_fld3"), 1151 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld1"));
1168 Dart_NewInteger(200)); 1152 EXPECT_VALID(result);
1169 EXPECT_VALID(result); 1153 result = Dart_IntegerToInt64(result, &value);
1170 result = Dart_IntegerToInt64(result, &value); 1154 EXPECT_EQ(40, value);
1171 EXPECT_EQ(200, value);
1172
1173 // Now access and set various instance fields of the returned object.
1174 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld3"));
1175 EXPECT(Dart_IsError(result));
1176 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld1"));
1177 EXPECT_VALID(result);
1178 result = Dart_IntegerToInt64(result, &value);
1179 EXPECT_EQ(10, value);
1180 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld2"));
1181 EXPECT_VALID(result);
1182 result = Dart_IntegerToInt64(result, &value);
1183 EXPECT_EQ(20, value);
1184 result = Dart_SetInstanceField(retobj,
1185 Dart_NewString("_fld2"),
1186 Dart_NewInteger(40));
1187 EXPECT(Dart_IsError(result));
1188 result = Dart_SetInstanceField(retobj,
1189 Dart_NewString("_fld1"),
1190 Dart_NewInteger(40));
1191 EXPECT_VALID(result);
1192 result = Dart_GetInstanceField(retobj, Dart_NewString("_fld1"));
1193 EXPECT_VALID(result);
1194 result = Dart_IntegerToInt64(result, &value);
1195 EXPECT_EQ(40, value);
1196 }
1197 } 1155 }
1198 1156
1199 1157
1200 void NativeFieldLookup(Dart_NativeArguments args) { 1158 void NativeFieldLookup(Dart_NativeArguments args) {
1201 UNREACHABLE(); 1159 UNREACHABLE();
1202 } 1160 }
1203 1161
1204 1162
1205 static Dart_NativeFunction native_field_lookup(Dart_Handle name, 1163 static Dart_NativeFunction native_field_lookup(Dart_Handle name,
1206 int argument_count) { 1164 int argument_count) {
1207 return reinterpret_cast<Dart_NativeFunction>(&NativeFieldLookup); 1165 return reinterpret_cast<Dart_NativeFunction>(&NativeFieldLookup);
1208 } 1166 }
1209 1167
1210 1168
1211 UNIT_TEST_CASE(InjectNativeFields1) { 1169 TEST_CASE(InjectNativeFields1) {
1212 const char* kScriptChars = 1170 const char* kScriptChars =
1213 "class NativeFields extends NativeFieldsWrapper {\n" 1171 "class NativeFields extends NativeFieldsWrapper {\n"
1214 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" 1172 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
1215 " int fld1;\n" 1173 " int fld1;\n"
1216 " final int fld2;\n" 1174 " final int fld2;\n"
1217 " static int fld3;\n" 1175 " static int fld3;\n"
1218 " static final int fld4 = 10;\n" 1176 " static final int fld4 = 10;\n"
1219 "}\n" 1177 "}\n"
1220 "class NativeFieldsTest {\n" 1178 "class NativeFieldsTest {\n"
1221 " static NativeFields testMain() {\n" 1179 " static NativeFields testMain() {\n"
1222 " NativeFields obj = new NativeFields(10, 20);\n" 1180 " NativeFields obj = new NativeFields(10, 20);\n"
1223 " return obj;\n" 1181 " return obj;\n"
1224 " }\n" 1182 " }\n"
1225 "}\n"; 1183 "}\n";
1226 Dart_Handle result; 1184 Dart_Handle result;
1227 1185
1228 TestIsolateScope __test_isolate__; 1186 const int kNumNativeFields = 4;
1229 {
1230 const int kNumNativeFields = 4;
1231 1187
1232 // Create a test library. 1188 // Create a test library.
1233 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, 1189 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars,
1234 native_field_lookup); 1190 native_field_lookup);
1235 1191
1236 // Create a native wrapper class with native fields. 1192 // Create a native wrapper class with native fields.
1237 result = Dart_CreateNativeWrapperClass( 1193 result = Dart_CreateNativeWrapperClass(
1238 lib, 1194 lib,
1239 Dart_NewString("NativeFieldsWrapper"), 1195 Dart_NewString("NativeFieldsWrapper"),
1240 kNumNativeFields); 1196 kNumNativeFields);
1241 1197
1242 // Load up a test script in the test library. 1198 // Load up a test script in the test library.
1243 1199
1244 // Invoke a function which returns an object of type NativeFields. 1200 // Invoke a function which returns an object of type NativeFields.
1245 result = Dart_InvokeStatic(lib, 1201 result = Dart_InvokeStatic(lib,
1246 Dart_NewString("NativeFieldsTest"), 1202 Dart_NewString("NativeFieldsTest"),
1247 Dart_NewString("testMain"), 1203 Dart_NewString("testMain"),
1248 0, 1204 0,
1249 NULL); 1205 NULL);
1250 EXPECT_VALID(result); 1206 EXPECT_VALID(result);
1251 DARTSCOPE_NOCHECKS(Isolate::Current()); 1207 DARTSCOPE_NOCHECKS(Isolate::Current());
1252 Instance& obj = Instance::Handle(); 1208 Instance& obj = Instance::Handle();
1253 obj ^= Api::UnwrapHandle(result); 1209 obj ^= Api::UnwrapHandle(result);
1254 const Class& cls = Class::Handle(obj.clazz()); 1210 const Class& cls = Class::Handle(obj.clazz());
1255 // We expect the newly created "NativeFields" object to have 1211 // We expect the newly created "NativeFields" object to have
1256 // 2 dart instance fields (fld1, fld2) and kNumNativeFields native fields. 1212 // 2 dart instance fields (fld1, fld2) and kNumNativeFields native fields.
1257 // Hence the size of an instance of "NativeFields" should be 1213 // Hence the size of an instance of "NativeFields" should be
1258 // (kNumNativeFields + 2) * kWordSize + size of object header. 1214 // (kNumNativeFields + 2) * kWordSize + size of object header.
1259 // We check to make sure the instance size computed by the VM matches 1215 // We check to make sure the instance size computed by the VM matches
1260 // our expectations. 1216 // our expectations.
1261 intptr_t header_size = sizeof(RawObject); 1217 intptr_t header_size = sizeof(RawObject);
1262 EXPECT_EQ(Utils::RoundUp(((kNumNativeFields + 2) * kWordSize) + header_size, 1218 EXPECT_EQ(Utils::RoundUp(((kNumNativeFields + 2) * kWordSize) + header_size,
1263 kObjectAlignment), 1219 kObjectAlignment),
1264 cls.instance_size()); 1220 cls.instance_size());
1265 }
1266 } 1221 }
1267 1222
1268 1223
1269 UNIT_TEST_CASE(InjectNativeFields2) { 1224 TEST_CASE(InjectNativeFields2) {
1270 const char* kScriptChars = 1225 const char* kScriptChars =
1271 "class NativeFields extends NativeFieldsWrapper {\n" 1226 "class NativeFields extends NativeFieldsWrapper {\n"
1272 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" 1227 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
1273 " int fld1;\n" 1228 " int fld1;\n"
1274 " final int fld2;\n" 1229 " final int fld2;\n"
1275 " static int fld3;\n" 1230 " static int fld3;\n"
1276 " static final int fld4 = 10;\n" 1231 " static final int fld4 = 10;\n"
1277 "}\n" 1232 "}\n"
1278 "class NativeFieldsTest {\n" 1233 "class NativeFieldsTest {\n"
1279 " static NativeFields testMain() {\n" 1234 " static NativeFields testMain() {\n"
1280 " NativeFields obj = new NativeFields(10, 20);\n" 1235 " NativeFields obj = new NativeFields(10, 20);\n"
1281 " return obj;\n" 1236 " return obj;\n"
1282 " }\n" 1237 " }\n"
1283 "}\n"; 1238 "}\n";
1284 Dart_Handle result; 1239 Dart_Handle result;
1240 // Create a test library and Load up a test script in it.
1241 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1285 1242
1286 TestIsolateScope __test_isolate__; 1243 // Invoke a function which returns an object of type NativeFields.
1287 { 1244 result = Dart_InvokeStatic(lib,
1288 // Create a test library and Load up a test script in it. 1245 Dart_NewString("NativeFieldsTest"),
1289 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1246 Dart_NewString("testMain"),
1290 1247 0,
1291 // Invoke a function which returns an object of type NativeFields. 1248 NULL);
1292 result = Dart_InvokeStatic(lib, 1249 // We expect this to fail as class "NativeFields" extends
1293 Dart_NewString("NativeFieldsTest"), 1250 // "NativeFieldsWrapper" and there is no definition of it either
1294 Dart_NewString("testMain"), 1251 // in the dart code or through the native field injection mechanism.
1295 0, 1252 EXPECT(Dart_IsError(result));
1296 NULL);
1297 // We expect this to fail as class "NativeFields" extends
1298 // "NativeFieldsWrapper" and there is no definition of it either
1299 // in the dart code or through the native field injection mechanism.
1300 EXPECT(Dart_IsError(result));
1301 }
1302 } 1253 }
1303 1254
1304 1255
1305 UNIT_TEST_CASE(InjectNativeFields3) { 1256 TEST_CASE(InjectNativeFields3) {
1306 const char* kScriptChars = 1257 const char* kScriptChars =
1307 "#import('dart:nativewrappers');" 1258 "#import('dart:nativewrappers');"
1308 "class NativeFields extends NativeFieldWrapperClass2 {\n" 1259 "class NativeFields extends NativeFieldWrapperClass2 {\n"
1309 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" 1260 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
1310 " int fld1;\n" 1261 " int fld1;\n"
1311 " final int fld2;\n" 1262 " final int fld2;\n"
1312 " static int fld3;\n" 1263 " static int fld3;\n"
1313 " static final int fld4 = 10;\n" 1264 " static final int fld4 = 10;\n"
1314 "}\n" 1265 "}\n"
1315 "class NativeFieldsTest {\n" 1266 "class NativeFieldsTest {\n"
1316 " static NativeFields testMain() {\n" 1267 " static NativeFields testMain() {\n"
1317 " NativeFields obj = new NativeFields(10, 20);\n" 1268 " NativeFields obj = new NativeFields(10, 20);\n"
1318 " return obj;\n" 1269 " return obj;\n"
1319 " }\n" 1270 " }\n"
1320 "}\n"; 1271 "}\n";
1321 Dart_Handle result; 1272 Dart_Handle result;
1273 const int kNumNativeFields = 2;
1322 1274
1323 TestIsolateScope __test_isolate__; 1275 // Load up a test script in the test library.
1324 { 1276 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars,
1325 const int kNumNativeFields = 2; 1277 native_field_lookup);
1326 1278
1327 // Load up a test script in the test library. 1279 // Invoke a function which returns an object of type NativeFields.
1328 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, 1280 result = Dart_InvokeStatic(lib,
1329 native_field_lookup); 1281 Dart_NewString("NativeFieldsTest"),
1330 1282 Dart_NewString("testMain"),
1331 // Invoke a function which returns an object of type NativeFields. 1283 0,
1332 result = Dart_InvokeStatic(lib, 1284 NULL);
1333 Dart_NewString("NativeFieldsTest"), 1285 EXPECT_VALID(result);
1334 Dart_NewString("testMain"), 1286 DARTSCOPE_NOCHECKS(Isolate::Current());
1335 0, 1287 Instance& obj = Instance::Handle();
1336 NULL); 1288 obj ^= Api::UnwrapHandle(result);
1337 EXPECT_VALID(result); 1289 const Class& cls = Class::Handle(obj.clazz());
1338 DARTSCOPE_NOCHECKS(Isolate::Current()); 1290 // We expect the newly created "NativeFields" object to have
1339 Instance& obj = Instance::Handle(); 1291 // 2 dart instance fields (fld1, fld2) and kNumNativeFields native fields.
1340 obj ^= Api::UnwrapHandle(result); 1292 // Hence the size of an instance of "NativeFields" should be
1341 const Class& cls = Class::Handle(obj.clazz()); 1293 // (kNumNativeFields + 2) * kWordSize + size of object header.
1342 // We expect the newly created "NativeFields" object to have 1294 // We check to make sure the instance size computed by the VM matches
1343 // 2 dart instance fields (fld1, fld2) and kNumNativeFields native fields. 1295 // our expectations.
1344 // Hence the size of an instance of "NativeFields" should be 1296 intptr_t header_size = sizeof(RawObject);
1345 // (kNumNativeFields + 2) * kWordSize + size of object header. 1297 EXPECT_EQ(Utils::RoundUp(((kNumNativeFields + 2) * kWordSize) + header_size,
1346 // We check to make sure the instance size computed by the VM matches 1298 kObjectAlignment),
1347 // our expectations. 1299 cls.instance_size());
1348 intptr_t header_size = sizeof(RawObject);
1349 EXPECT_EQ(Utils::RoundUp(((kNumNativeFields + 2) * kWordSize) + header_size,
1350 kObjectAlignment),
1351 cls.instance_size());
1352 }
1353 } 1300 }
1354 1301
1355 1302
1356 UNIT_TEST_CASE(InjectNativeFields4) { 1303 TEST_CASE(InjectNativeFields4) {
1357 const char* kScriptChars = 1304 const char* kScriptChars =
1358 "#import('dart:nativewrappers');" 1305 "#import('dart:nativewrappers');"
1359 "class NativeFields extends NativeFieldWrapperClass2 {\n" 1306 "class NativeFields extends NativeFieldWrapperClass2 {\n"
1360 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" 1307 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
1361 " int fld1;\n" 1308 " int fld1;\n"
1362 " final int fld2;\n" 1309 " final int fld2;\n"
1363 " static int fld3;\n" 1310 " static int fld3;\n"
1364 " static final int fld4 = 10;\n" 1311 " static final int fld4 = 10;\n"
1365 "}\n" 1312 "}\n"
1366 "class NativeFieldsTest {\n" 1313 "class NativeFieldsTest {\n"
1367 " static NativeFields testMain() {\n" 1314 " static NativeFields testMain() {\n"
1368 " NativeFields obj = new NativeFields(10, 20);\n" 1315 " NativeFields obj = new NativeFields(10, 20);\n"
1369 " return obj;\n" 1316 " return obj;\n"
1370 " }\n" 1317 " }\n"
1371 "}\n"; 1318 "}\n";
1372 Dart_Handle result; 1319 Dart_Handle result;
1320 // Load up a test script in the test library.
1321 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1373 1322
1374 TestIsolateScope __test_isolate__; 1323 // Invoke a function which returns an object of type NativeFields.
1375 { 1324 result = Dart_InvokeStatic(lib,
1376 // Load up a test script in the test library. 1325 Dart_NewString("NativeFieldsTest"),
1377 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1326 Dart_NewString("testMain"),
1378 1327 0,
1379 // Invoke a function which returns an object of type NativeFields. 1328 NULL);
1380 result = Dart_InvokeStatic(lib, 1329 // We expect the test script to fail finalization with the error below:
1381 Dart_NewString("NativeFieldsTest"), 1330 EXPECT(Dart_IsError(result));
1382 Dart_NewString("testMain"), 1331 Dart_Handle expected_error = Dart_Error(
1383 0, 1332 "'dart:test-lib': Error: class 'NativeFields' is trying to extend a "
1384 NULL); 1333 "native fields class, but library '%s' has no native resolvers",
1385 // We expect the test script to fail finalization with the error below: 1334 TestCase::url());
1386 EXPECT(Dart_IsError(result)); 1335 EXPECT_STREQ(Dart_GetError(expected_error), Dart_GetError(result));
1387 Dart_Handle expected_error = Dart_Error(
1388 "'dart:test-lib': Error: class 'NativeFields' is trying to extend a "
1389 "native fields class, but library '%s' has no native resolvers",
1390 TestCase::url());
1391 EXPECT_STREQ(Dart_GetError(expected_error), Dart_GetError(result));
1392 }
1393 } 1336 }
1394 1337
1395 1338
1396 static void TestNativeFields(Dart_Handle retobj) { 1339 static void TestNativeFields(Dart_Handle retobj) {
1397 // Access and set various instance fields of the object. 1340 // Access and set various instance fields of the object.
1398 Dart_Handle result = Dart_GetInstanceField(retobj, Dart_NewString("fld3")); 1341 Dart_Handle result = Dart_GetInstanceField(retobj, Dart_NewString("fld3"));
1399 EXPECT(Dart_IsError(result)); 1342 EXPECT(Dart_IsError(result));
1400 result = Dart_GetInstanceField(retobj, Dart_NewString("fld0")); 1343 result = Dart_GetInstanceField(retobj, Dart_NewString("fld0"));
1401 EXPECT_VALID(result); 1344 EXPECT_VALID(result);
1402 EXPECT(Dart_IsNull(result)); 1345 EXPECT(Dart_IsNull(result));
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1463 EXPECT_VALID(result); 1406 EXPECT_VALID(result);
1464 result = Dart_IntegerToInt64(result, &value); 1407 result = Dart_IntegerToInt64(result, &value);
1465 EXPECT_EQ(40, value); 1408 EXPECT_EQ(40, value);
1466 result = Dart_GetInstanceField(retobj, Dart_NewString("fld2")); 1409 result = Dart_GetInstanceField(retobj, Dart_NewString("fld2"));
1467 EXPECT_VALID(result); 1410 EXPECT_VALID(result);
1468 result = Dart_IntegerToInt64(result, &value); 1411 result = Dart_IntegerToInt64(result, &value);
1469 EXPECT_EQ(20, value); 1412 EXPECT_EQ(20, value);
1470 } 1413 }
1471 1414
1472 1415
1473 UNIT_TEST_CASE(NativeFieldAccess) { 1416 TEST_CASE(NativeFieldAccess) {
1474 const char* kScriptChars = 1417 const char* kScriptChars =
1475 "class NativeFields extends NativeFieldsWrapper {\n" 1418 "class NativeFields extends NativeFieldsWrapper {\n"
1476 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" 1419 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
1477 " int fld0;\n" 1420 " int fld0;\n"
1478 " int fld1;\n" 1421 " int fld1;\n"
1479 " final int fld2;\n" 1422 " final int fld2;\n"
1480 " static int fld3;\n" 1423 " static int fld3;\n"
1481 " static final int fld4 = 10;\n" 1424 " static final int fld4 = 10;\n"
1482 "}\n" 1425 "}\n"
1483 "class NativeFieldsTest {\n" 1426 "class NativeFieldsTest {\n"
1484 " static NativeFields testMain() {\n" 1427 " static NativeFields testMain() {\n"
1485 " NativeFields obj = new NativeFields(10, 20);\n" 1428 " NativeFields obj = new NativeFields(10, 20);\n"
1486 " return obj;\n" 1429 " return obj;\n"
1487 " }\n" 1430 " }\n"
1488 "}\n"; 1431 "}\n";
1489 Dart_Handle result; 1432 Dart_Handle result;
1433 const int kNumNativeFields = 4;
1490 1434
1491 TestIsolateScope __test_isolate__; 1435 // Create a test library.
1492 { 1436 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars,
1493 const int kNumNativeFields = 4; 1437 native_field_lookup);
1494 1438
1495 // Create a test library. 1439 // Create a native wrapper class with native fields.
1496 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, 1440 result = Dart_CreateNativeWrapperClass(
1497 native_field_lookup); 1441 lib,
1442 Dart_NewString("NativeFieldsWrapper"),
1443 kNumNativeFields);
1498 1444
1499 // Create a native wrapper class with native fields. 1445 // Load up a test script in it.
1500 result = Dart_CreateNativeWrapperClass(
1501 lib,
1502 Dart_NewString("NativeFieldsWrapper"),
1503 kNumNativeFields);
1504 1446
1505 // Load up a test script in it. 1447 // Invoke a function which returns an object of type NativeFields.
1448 Dart_Handle retobj = Dart_InvokeStatic(lib,
1449 Dart_NewString("NativeFieldsTest"),
1450 Dart_NewString("testMain"),
1451 0,
1452 NULL);
1453 EXPECT_VALID(retobj);
1506 1454
1507 // Invoke a function which returns an object of type NativeFields. 1455 // Now access and set various instance fields of the returned object.
1508 Dart_Handle retobj = Dart_InvokeStatic(lib, 1456 TestNativeFields(retobj);
1509 Dart_NewString("NativeFieldsTest"),
1510 Dart_NewString("testMain"),
1511 0,
1512 NULL);
1513 EXPECT_VALID(retobj);
1514
1515 // Now access and set various instance fields of the returned object.
1516 TestNativeFields(retobj);
1517 }
1518 } 1457 }
1519 1458
1520 1459
1521 UNIT_TEST_CASE(ImplicitNativeFieldAccess) { 1460 TEST_CASE(ImplicitNativeFieldAccess) {
1522 const char* kScriptChars = 1461 const char* kScriptChars =
1523 "#import('dart:nativewrappers');" 1462 "#import('dart:nativewrappers');"
1524 "class NativeFields extends NativeFieldWrapperClass4 {\n" 1463 "class NativeFields extends NativeFieldWrapperClass4 {\n"
1525 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" 1464 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
1526 " int fld0;\n" 1465 " int fld0;\n"
1527 " int fld1;\n" 1466 " int fld1;\n"
1528 " final int fld2;\n" 1467 " final int fld2;\n"
1529 " static int fld3;\n" 1468 " static int fld3;\n"
1530 " static final int fld4 = 10;\n" 1469 " static final int fld4 = 10;\n"
1531 "}\n" 1470 "}\n"
1532 "class NativeFieldsTest {\n" 1471 "class NativeFieldsTest {\n"
1533 " static NativeFields testMain() {\n" 1472 " static NativeFields testMain() {\n"
1534 " NativeFields obj = new NativeFields(10, 20);\n" 1473 " NativeFields obj = new NativeFields(10, 20);\n"
1535 " return obj;\n" 1474 " return obj;\n"
1536 " }\n" 1475 " }\n"
1537 "}\n"; 1476 "}\n";
1538 TestIsolateScope __test_isolate__; 1477 // Load up a test script in the test library.
1539 { 1478 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars,
1540 // Load up a test script in the test library. 1479 native_field_lookup);
1541 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars,
1542 native_field_lookup);
1543 1480
1544 // Invoke a function which returns an object of type NativeFields. 1481 // Invoke a function which returns an object of type NativeFields.
1545 Dart_Handle retobj = Dart_InvokeStatic(lib, 1482 Dart_Handle retobj = Dart_InvokeStatic(lib,
1546 Dart_NewString("NativeFieldsTest"), 1483 Dart_NewString("NativeFieldsTest"),
1547 Dart_NewString("testMain"), 1484 Dart_NewString("testMain"),
1548 0, 1485 0,
1549 NULL); 1486 NULL);
1550 EXPECT_VALID(retobj); 1487 EXPECT_VALID(retobj);
1551 1488
1552 // Now access and set various instance fields of the returned object. 1489 // Now access and set various instance fields of the returned object.
1553 TestNativeFields(retobj); 1490 TestNativeFields(retobj);
1554 }
1555 } 1491 }
1556 1492
1557 1493
1558 UNIT_TEST_CASE(NegativeNativeFieldAccess) { 1494 TEST_CASE(NegativeNativeFieldAccess) {
1559 const char* kScriptChars = 1495 const char* kScriptChars =
1560 "class NativeFields {\n" 1496 "class NativeFields {\n"
1561 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n" 1497 " NativeFields(int i, int j) : fld1 = i, fld2 = j {}\n"
1562 " int fld1;\n" 1498 " int fld1;\n"
1563 " final int fld2;\n" 1499 " final int fld2;\n"
1564 " static int fld3;\n" 1500 " static int fld3;\n"
1565 " static final int fld4 = 10;\n" 1501 " static final int fld4 = 10;\n"
1566 "}\n" 1502 "}\n"
1567 "class NativeFieldsTest {\n" 1503 "class NativeFieldsTest {\n"
1568 " static NativeFields testMain1() {\n" 1504 " static NativeFields testMain1() {\n"
1569 " NativeFields obj = new NativeFields(10, 20);\n" 1505 " NativeFields obj = new NativeFields(10, 20);\n"
1570 " return obj;\n" 1506 " return obj;\n"
1571 " }\n" 1507 " }\n"
1572 " static Function testMain2() {\n" 1508 " static Function testMain2() {\n"
1573 " return function() {};\n" 1509 " return function() {};\n"
1574 " }\n" 1510 " }\n"
1575 "}\n"; 1511 "}\n";
1576 Dart_Handle result; 1512 Dart_Handle result;
1513 DARTSCOPE_NOCHECKS(Isolate::Current());
1577 1514
1578 TestIsolateScope __test_isolate__; 1515 // Create a test library and Load up a test script in it.
1579 { 1516 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1580 DARTSCOPE_NOCHECKS(Isolate::Current());
1581 1517
1582 // Create a test library and Load up a test script in it. 1518 // Invoke a function which returns an object of type NativeFields.
1583 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1519 Dart_Handle retobj = Dart_InvokeStatic(lib,
1520 Dart_NewString("NativeFieldsTest"),
1521 Dart_NewString("testMain1"),
1522 0,
1523 NULL);
1524 EXPECT_VALID(retobj);
1584 1525
1585 // Invoke a function which returns an object of type NativeFields. 1526 // Now access and set various native instance fields of the returned object.
1586 Dart_Handle retobj = Dart_InvokeStatic(lib, 1527 // All of these tests are expected to return failure as there are no
1587 Dart_NewString("NativeFieldsTest"), 1528 // native fields in an instance of NativeFields.
1588 Dart_NewString("testMain1"), 1529 const int kNativeFld0 = 0;
1589 0, 1530 const int kNativeFld1 = 1;
1590 NULL); 1531 const int kNativeFld2 = 2;
1591 EXPECT_VALID(retobj); 1532 const int kNativeFld3 = 3;
1533 const int kNativeFld4 = 4;
1534 intptr_t value = 0;
1535 result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &value);
1536 EXPECT(Dart_IsError(result));
1537 result = Dart_GetNativeInstanceField(retobj, kNativeFld0, &value);
1538 EXPECT(Dart_IsError(result));
1539 result = Dart_GetNativeInstanceField(retobj, kNativeFld1, &value);
1540 EXPECT(Dart_IsError(result));
1541 result = Dart_GetNativeInstanceField(retobj, kNativeFld2, &value);
1542 EXPECT(Dart_IsError(result));
1543 result = Dart_SetNativeInstanceField(retobj, kNativeFld4, 40);
1544 EXPECT(Dart_IsError(result));
1545 result = Dart_SetNativeInstanceField(retobj, kNativeFld3, 40);
1546 EXPECT(Dart_IsError(result));
1547 result = Dart_SetNativeInstanceField(retobj, kNativeFld0, 400);
1548 EXPECT(Dart_IsError(result));
1592 1549
1593 // Now access and set various native instance fields of the returned object. 1550 // Invoke a function which returns a closure object.
1594 // All of these tests are expected to return failure as there are no 1551 retobj = Dart_InvokeStatic(lib,
1595 // native fields in an instance of NativeFields. 1552 Dart_NewString("NativeFieldsTest"),
1596 const int kNativeFld0 = 0; 1553 Dart_NewString("testMain2"),
1597 const int kNativeFld1 = 1; 1554 0,
1598 const int kNativeFld2 = 2; 1555 NULL);
1599 const int kNativeFld3 = 3; 1556 EXPECT_VALID(retobj);
1600 const int kNativeFld4 = 4; 1557 result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &value);
1601 intptr_t value = 0; 1558 EXPECT(Dart_IsError(result));
1602 result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &value); 1559 result = Dart_GetNativeInstanceField(retobj, kNativeFld0, &value);
1603 EXPECT(Dart_IsError(result)); 1560 EXPECT(Dart_IsError(result));
1604 result = Dart_GetNativeInstanceField(retobj, kNativeFld0, &value); 1561 result = Dart_GetNativeInstanceField(retobj, kNativeFld1, &value);
1605 EXPECT(Dart_IsError(result)); 1562 EXPECT(Dart_IsError(result));
1606 result = Dart_GetNativeInstanceField(retobj, kNativeFld1, &value); 1563 result = Dart_GetNativeInstanceField(retobj, kNativeFld2, &value);
1607 EXPECT(Dart_IsError(result)); 1564 EXPECT(Dart_IsError(result));
1608 result = Dart_GetNativeInstanceField(retobj, kNativeFld2, &value); 1565 result = Dart_SetNativeInstanceField(retobj, kNativeFld4, 40);
1609 EXPECT(Dart_IsError(result)); 1566 EXPECT(Dart_IsError(result));
1610 result = Dart_SetNativeInstanceField(retobj, kNativeFld4, 40); 1567 result = Dart_SetNativeInstanceField(retobj, kNativeFld3, 40);
1611 EXPECT(Dart_IsError(result)); 1568 EXPECT(Dart_IsError(result));
1612 result = Dart_SetNativeInstanceField(retobj, kNativeFld3, 40); 1569 result = Dart_SetNativeInstanceField(retobj, kNativeFld0, 400);
1613 EXPECT(Dart_IsError(result)); 1570 EXPECT(Dart_IsError(result));
1614 result = Dart_SetNativeInstanceField(retobj, kNativeFld0, 400);
1615 EXPECT(Dart_IsError(result));
1616
1617 // Invoke a function which returns a closure object.
1618 retobj = Dart_InvokeStatic(lib,
1619 Dart_NewString("NativeFieldsTest"),
1620 Dart_NewString("testMain2"),
1621 0,
1622 NULL);
1623 EXPECT_VALID(retobj);
1624 result = Dart_GetNativeInstanceField(retobj, kNativeFld4, &value);
1625 EXPECT(Dart_IsError(result));
1626 result = Dart_GetNativeInstanceField(retobj, kNativeFld0, &value);
1627 EXPECT(Dart_IsError(result));
1628 result = Dart_GetNativeInstanceField(retobj, kNativeFld1, &value);
1629 EXPECT(Dart_IsError(result));
1630 result = Dart_GetNativeInstanceField(retobj, kNativeFld2, &value);
1631 EXPECT(Dart_IsError(result));
1632 result = Dart_SetNativeInstanceField(retobj, kNativeFld4, 40);
1633 EXPECT(Dart_IsError(result));
1634 result = Dart_SetNativeInstanceField(retobj, kNativeFld3, 40);
1635 EXPECT(Dart_IsError(result));
1636 result = Dart_SetNativeInstanceField(retobj, kNativeFld0, 400);
1637 EXPECT(Dart_IsError(result));
1638 }
1639 } 1571 }
1640 1572
1641 1573
1642 UNIT_TEST_CASE(GetStaticField_RunsInitializer) { 1574 TEST_CASE(GetStaticField_RunsInitializer) {
1643 const char* kScriptChars = 1575 const char* kScriptChars =
1644 "class TestClass {\n" 1576 "class TestClass {\n"
1645 " static final int fld1 = 7;\n" 1577 " static final int fld1 = 7;\n"
1646 " static int fld2 = 11;\n" 1578 " static int fld2 = 11;\n"
1647 " static void testMain() {\n" 1579 " static void testMain() {\n"
1648 " }\n" 1580 " }\n"
1649 "}\n"; 1581 "}\n";
1650 Dart_Handle result; 1582 Dart_Handle result;
1583 // Create a test library and Load up a test script in it.
1584 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1651 1585
1652 TestIsolateScope __test_isolate__; 1586 // Invoke a function which returns an object.
1653 { 1587 result = Dart_InvokeStatic(lib,
1654 // Create a test library and Load up a test script in it. 1588 Dart_NewString("TestClass"),
1655 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1589 Dart_NewString("testMain"),
1590 0,
1591 NULL);
1656 1592
1657 // Invoke a function which returns an object. 1593 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("TestClass"));
1658 result = Dart_InvokeStatic(lib, 1594 EXPECT_VALID(cls);
1659 Dart_NewString("TestClass"),
1660 Dart_NewString("testMain"),
1661 0,
1662 NULL);
1663 1595
1664 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("TestClass")); 1596 // For uninitialized fields, the getter is returned
1665 EXPECT_VALID(cls); 1597 result = Dart_GetStaticField(cls, Dart_NewString("fld1"));
1598 EXPECT_VALID(result);
1599 int64_t value = 0;
1600 result = Dart_IntegerToInt64(result, &value);
1601 EXPECT_EQ(7, value);
1666 1602
1667 // For uninitialized fields, the getter is returned 1603 result = Dart_GetStaticField(cls, Dart_NewString("fld2"));
1668 result = Dart_GetStaticField(cls, Dart_NewString("fld1")); 1604 EXPECT_VALID(result);
1669 EXPECT_VALID(result); 1605 result = Dart_IntegerToInt64(result, &value);
1670 int64_t value = 0; 1606 EXPECT_EQ(11, value);
1671 result = Dart_IntegerToInt64(result, &value);
1672 EXPECT_EQ(7, value);
1673 1607
1674 result = Dart_GetStaticField(cls, Dart_NewString("fld2")); 1608 // Overwrite fld2
1675 EXPECT_VALID(result); 1609 result = Dart_SetStaticField(cls,
1676 result = Dart_IntegerToInt64(result, &value); 1610 Dart_NewString("fld2"),
1677 EXPECT_EQ(11, value); 1611 Dart_NewInteger(13));
1612 EXPECT_VALID(result);
1678 1613
1679 // Overwrite fld2 1614 // We now get the new value for fld2, not the initializer
1680 result = Dart_SetStaticField(cls, 1615 result = Dart_GetStaticField(cls, Dart_NewString("fld2"));
1681 Dart_NewString("fld2"), 1616 EXPECT_VALID(result);
1682 Dart_NewInteger(13)); 1617 result = Dart_IntegerToInt64(result, &value);
1683 EXPECT_VALID(result); 1618 EXPECT_EQ(13, value);
1684
1685 // We now get the new value for fld2, not the initializer
1686 result = Dart_GetStaticField(cls, Dart_NewString("fld2"));
1687 EXPECT_VALID(result);
1688 result = Dart_IntegerToInt64(result, &value);
1689 EXPECT_EQ(13, value);
1690 }
1691 } 1619 }
1692 1620
1693 1621
1694 UNIT_TEST_CASE(StaticFieldNotFound) { 1622 TEST_CASE(StaticFieldNotFound) {
1695 const char* kScriptChars = 1623 const char* kScriptChars =
1696 "class TestClass {\n" 1624 "class TestClass {\n"
1697 " static void testMain() {\n" 1625 " static void testMain() {\n"
1698 " }\n" 1626 " }\n"
1699 "}\n"; 1627 "}\n";
1700 Dart_Handle result; 1628 Dart_Handle result;
1629 // Create a test library and Load up a test script in it.
1630 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1701 1631
1702 TestIsolateScope __test_isolate__; 1632 // Invoke a function.
1703 { 1633 result = Dart_InvokeStatic(lib,
1704 // Create a test library and Load up a test script in it. 1634 Dart_NewString("TestClass"),
1705 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1635 Dart_NewString("testMain"),
1636 0,
1637 NULL);
1706 1638
1707 // Invoke a function. 1639 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("TestClass"));
1708 result = Dart_InvokeStatic(lib, 1640 EXPECT_VALID(cls);
1709 Dart_NewString("TestClass"),
1710 Dart_NewString("testMain"),
1711 0,
1712 NULL);
1713 1641
1714 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("TestClass")); 1642 result = Dart_GetStaticField(cls, Dart_NewString("not_found"));
1715 EXPECT_VALID(cls); 1643 EXPECT(Dart_IsError(result));
1644 EXPECT_STREQ("Specified field is not found in the class",
1645 Dart_GetError(result));
1716 1646
1717 result = Dart_GetStaticField(cls, Dart_NewString("not_found")); 1647 result = Dart_SetStaticField(cls,
1718 EXPECT(Dart_IsError(result)); 1648 Dart_NewString("not_found"),
1719 EXPECT_STREQ("Specified field is not found in the class", 1649 Dart_NewInteger(13));
1720 Dart_GetError(result)); 1650 EXPECT(Dart_IsError(result));
1721 1651 EXPECT_STREQ("Specified field is not found in the class",
1722 result = Dart_SetStaticField(cls, 1652 Dart_GetError(result));
1723 Dart_NewString("not_found"),
1724 Dart_NewInteger(13));
1725 EXPECT(Dart_IsError(result));
1726 EXPECT_STREQ("Specified field is not found in the class",
1727 Dart_GetError(result));
1728 }
1729 } 1653 }
1730 1654
1731 1655
1732 UNIT_TEST_CASE(InvokeDynamic) { 1656 TEST_CASE(InvokeDynamic) {
1733 const char* kScriptChars = 1657 const char* kScriptChars =
1734 "class InvokeDynamic {\n" 1658 "class InvokeDynamic {\n"
1735 " InvokeDynamic(int i, int j) : fld1 = i, fld2 = j {}\n" 1659 " InvokeDynamic(int i, int j) : fld1 = i, fld2 = j {}\n"
1736 " int method1(int i) { return i + fld1 + fld2 + fld4; }\n" 1660 " int method1(int i) { return i + fld1 + fld2 + fld4; }\n"
1737 " static int method2(int i) { return i + fld4; }\n" 1661 " static int method2(int i) { return i + fld4; }\n"
1738 " int fld1;\n" 1662 " int fld1;\n"
1739 " final int fld2;\n" 1663 " final int fld2;\n"
1740 " static final int fld4 = 10;\n" 1664 " static final int fld4 = 10;\n"
1741 "}\n" 1665 "}\n"
1742 "class InvokeDynamicTest {\n" 1666 "class InvokeDynamicTest {\n"
1743 " static InvokeDynamic testMain() {\n" 1667 " static InvokeDynamic testMain() {\n"
1744 " InvokeDynamic obj = new InvokeDynamic(10, 20);\n" 1668 " InvokeDynamic obj = new InvokeDynamic(10, 20);\n"
1745 " return obj;\n" 1669 " return obj;\n"
1746 " }\n" 1670 " }\n"
1747 "}\n"; 1671 "}\n";
1748 Dart_Handle result; 1672 Dart_Handle result;
1673 DARTSCOPE_NOCHECKS(Isolate::Current());
1749 1674
1750 TestIsolateScope __test_isolate__; 1675 // Create a test library and Load up a test script in it.
1751 { 1676 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1752 DARTSCOPE_NOCHECKS(Isolate::Current());
1753 1677
1754 // Create a test library and Load up a test script in it. 1678 // Invoke a function which returns an object of type InvokeDynamic.
1755 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1679 Dart_Handle retobj = Dart_InvokeStatic(lib,
1756 1680 Dart_NewString("InvokeDynamicTest"),
1757 // Invoke a function which returns an object of type InvokeDynamic. 1681 Dart_NewString("testMain"),
1758 Dart_Handle retobj = Dart_InvokeStatic(lib, 1682 0,
1759 Dart_NewString("InvokeDynamicTest"), 1683 NULL);
1760 Dart_NewString("testMain"), 1684 EXPECT_VALID(retobj);
1761 0,
1762 NULL);
1763 EXPECT_VALID(retobj);
1764 1685
1765 1686
1766 // Now invoke a dynamic method and check the result. 1687 // Now invoke a dynamic method and check the result.
1767 Dart_Handle dart_arguments[1]; 1688 Dart_Handle dart_arguments[1];
1768 dart_arguments[0] = Dart_NewInteger(1); 1689 dart_arguments[0] = Dart_NewInteger(1);
1769 result = Dart_InvokeDynamic(retobj, 1690 result = Dart_InvokeDynamic(retobj,
1770 Dart_NewString("method1"), 1691 Dart_NewString("method1"),
1771 1, 1692 1,
1772 dart_arguments); 1693 dart_arguments);
1773 EXPECT_VALID(result); 1694 EXPECT_VALID(result);
1774 EXPECT(Dart_IsInteger(result)); 1695 EXPECT(Dart_IsInteger(result));
1775 int64_t value = 0; 1696 int64_t value = 0;
1776 result = Dart_IntegerToInt64(result, &value); 1697 result = Dart_IntegerToInt64(result, &value);
1777 EXPECT_EQ(41, value); 1698 EXPECT_EQ(41, value);
1778 1699
1779 result = Dart_InvokeDynamic(retobj, Dart_NewString("method2"), 0, NULL); 1700 result = Dart_InvokeDynamic(retobj, Dart_NewString("method2"), 0, NULL);
1780 EXPECT(Dart_IsError(result)); 1701 EXPECT(Dart_IsError(result));
1781 1702
1782 result = Dart_InvokeDynamic(retobj, Dart_NewString("method1"), 0, NULL); 1703 result = Dart_InvokeDynamic(retobj, Dart_NewString("method1"), 0, NULL);
1783 EXPECT(Dart_IsError(result)); 1704 EXPECT(Dart_IsError(result));
1784 }
1785 } 1705 }
1786 1706
1787 1707
1788 UNIT_TEST_CASE(InvokeClosure) { 1708 TEST_CASE(InvokeClosure) {
1789 const char* kScriptChars = 1709 const char* kScriptChars =
1790 "class InvokeClosure {\n" 1710 "class InvokeClosure {\n"
1791 " InvokeClosure(int i, int j) : fld1 = i, fld2 = j {}\n" 1711 " InvokeClosure(int i, int j) : fld1 = i, fld2 = j {}\n"
1792 " Function method1(int i) {\n" 1712 " Function method1(int i) {\n"
1793 " f(int j) => j + i + fld1 + fld2 + fld4; \n" 1713 " f(int j) => j + i + fld1 + fld2 + fld4; \n"
1794 " return f;\n" 1714 " return f;\n"
1795 " }\n" 1715 " }\n"
1796 " static Function method2(int i) {\n" 1716 " static Function method2(int i) {\n"
1797 " n(int j) => true + i + fld4; \n" 1717 " n(int j) => true + i + fld4; \n"
1798 " return n;\n" 1718 " return n;\n"
1799 " }\n" 1719 " }\n"
1800 " int fld1;\n" 1720 " int fld1;\n"
1801 " final int fld2;\n" 1721 " final int fld2;\n"
1802 " static final int fld4 = 10;\n" 1722 " static final int fld4 = 10;\n"
1803 "}\n" 1723 "}\n"
1804 "class InvokeClosureTest {\n" 1724 "class InvokeClosureTest {\n"
1805 " static Function testMain1() {\n" 1725 " static Function testMain1() {\n"
1806 " InvokeClosure obj = new InvokeClosure(10, 20);\n" 1726 " InvokeClosure obj = new InvokeClosure(10, 20);\n"
1807 " return obj.method1(10);\n" 1727 " return obj.method1(10);\n"
1808 " }\n" 1728 " }\n"
1809 " static Function testMain2() {\n" 1729 " static Function testMain2() {\n"
1810 " return InvokeClosure.method2(10);\n" 1730 " return InvokeClosure.method2(10);\n"
1811 " }\n" 1731 " }\n"
1812 "}\n"; 1732 "}\n";
1813 Dart_Handle result; 1733 Dart_Handle result;
1734 DARTSCOPE_NOCHECKS(Isolate::Current());
1814 1735
1815 TestIsolateScope __test_isolate__; 1736 // Create a test library and Load up a test script in it.
1816 { 1737 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1817 DARTSCOPE_NOCHECKS(Isolate::Current());
1818 1738
1819 // Create a test library and Load up a test script in it. 1739 // Invoke a function which returns a closure.
1820 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1740 Dart_Handle retobj = Dart_InvokeStatic(lib,
1741 Dart_NewString("InvokeClosureTest"),
1742 Dart_NewString("testMain1"),
1743 0,
1744 NULL);
1745 EXPECT_VALID(retobj);
1821 1746
1822 // Invoke a function which returns a closure. 1747 EXPECT(Dart_IsClosure(retobj));
1823 Dart_Handle retobj = Dart_InvokeStatic(lib, 1748 EXPECT(!Dart_IsClosure(Dart_NewInteger(101)));
1824 Dart_NewString("InvokeClosureTest"),
1825 Dart_NewString("testMain1"),
1826 0,
1827 NULL);
1828 EXPECT_VALID(retobj);
1829 1749
1830 EXPECT(Dart_IsClosure(retobj)); 1750 // Now invoke the closure and check the result.
1831 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); 1751 Dart_Handle dart_arguments[1];
1752 dart_arguments[0] = Dart_NewInteger(1);
1753 result = Dart_InvokeClosure(retobj, 1, dart_arguments);
1754 EXPECT_VALID(result);
1755 EXPECT(Dart_IsInteger(result));
1756 int64_t value = 0;
1757 result = Dart_IntegerToInt64(result, &value);
1758 EXPECT_EQ(51, value);
1832 1759
1833 // Now invoke the closure and check the result. 1760 // Invoke closure with wrong number of args, should result in exception.
1834 Dart_Handle dart_arguments[1]; 1761 result = Dart_InvokeClosure(retobj, 0, NULL);
1835 dart_arguments[0] = Dart_NewInteger(1); 1762 EXPECT(Dart_IsError(result));
1836 result = Dart_InvokeClosure(retobj, 1, dart_arguments); 1763 EXPECT(Dart_ErrorHasException(result));
1837 EXPECT_VALID(result);
1838 EXPECT(Dart_IsInteger(result));
1839 int64_t value = 0;
1840 result = Dart_IntegerToInt64(result, &value);
1841 EXPECT_EQ(51, value);
1842 1764
1843 // Invoke closure with wrong number of args, should result in exception. 1765 // Invoke a function which returns a closure.
1844 result = Dart_InvokeClosure(retobj, 0, NULL); 1766 retobj = Dart_InvokeStatic(lib,
1845 EXPECT(Dart_IsError(result)); 1767 Dart_NewString("InvokeClosureTest"),
1846 EXPECT(Dart_ErrorHasException(result)); 1768 Dart_NewString("testMain2"),
1769 0,
1770 NULL);
1771 EXPECT_VALID(retobj);
1847 1772
1848 // Invoke a function which returns a closure. 1773 EXPECT(Dart_IsClosure(retobj));
1849 retobj = Dart_InvokeStatic(lib, 1774 EXPECT(!Dart_IsClosure(Dart_NewString("abcdef")));
1850 Dart_NewString("InvokeClosureTest"),
1851 Dart_NewString("testMain2"),
1852 0,
1853 NULL);
1854 EXPECT_VALID(retobj);
1855 1775
1856 EXPECT(Dart_IsClosure(retobj)); 1776 // Now invoke the closure and check the result (should be an exception).
1857 EXPECT(!Dart_IsClosure(Dart_NewString("abcdef"))); 1777 dart_arguments[0] = Dart_NewInteger(1);
1858 1778 result = Dart_InvokeClosure(retobj, 1, dart_arguments);
1859 // Now invoke the closure and check the result (should be an exception). 1779 EXPECT(Dart_IsError(result));
1860 dart_arguments[0] = Dart_NewInteger(1); 1780 EXPECT(Dart_ErrorHasException(result));
1861 result = Dart_InvokeClosure(retobj, 1, dart_arguments);
1862 EXPECT(Dart_IsError(result));
1863 EXPECT(Dart_ErrorHasException(result));
1864 }
1865 } 1781 }
1866 1782
1867 1783
1868 void ExceptionNative(Dart_NativeArguments args) { 1784 void ExceptionNative(Dart_NativeArguments args) {
1869 Dart_Handle param = Dart_GetNativeArgument(args, 0); 1785 Dart_Handle param = Dart_GetNativeArgument(args, 0);
1870 Dart_EnterScope(); // Start a Dart API scope for invoking API functions. 1786 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1871 char* str = reinterpret_cast<char*>(Api::Allocate(1024)); 1787 char* str = reinterpret_cast<char*>(Api::Allocate(1024));
1872 str[0] = 0; 1788 str[0] = 0;
1873 Dart_ThrowException(param); 1789 Dart_ThrowException(param);
1874 UNREACHABLE(); 1790 UNREACHABLE();
1875 } 1791 }
1876 1792
1877 1793
1878 static Dart_NativeFunction native_lookup(Dart_Handle name, int argument_count) { 1794 static Dart_NativeFunction native_lookup(Dart_Handle name, int argument_count) {
1879 return reinterpret_cast<Dart_NativeFunction>(&ExceptionNative); 1795 return reinterpret_cast<Dart_NativeFunction>(&ExceptionNative);
1880 } 1796 }
1881 1797
1882 1798
1883 UNIT_TEST_CASE(ThrowException) { 1799 TEST_CASE(ThrowException) {
1884 const char* kScriptChars = 1800 const char* kScriptChars =
1885 "class ThrowException {\n" 1801 "class ThrowException {\n"
1886 " ThrowException(int i) : fld1 = i {}\n" 1802 " ThrowException(int i) : fld1 = i {}\n"
1887 " int method1(int i) native \"ThrowException_native\";" 1803 " int method1(int i) native \"ThrowException_native\";"
1888 " int method2() {\n" 1804 " int method2() {\n"
1889 " try { method1(10); } catch(var a) { return 5; } return 10;\n" 1805 " try { method1(10); } catch(var a) { return 5; } return 10;\n"
1890 " }\n" 1806 " }\n"
1891 " int fld1;\n" 1807 " int fld1;\n"
1892 "}\n" 1808 "}\n"
1893 "class ThrowExceptionTest {\n" 1809 "class ThrowExceptionTest {\n"
1894 " static ThrowException testMain() {\n" 1810 " static ThrowException testMain() {\n"
1895 " ThrowException obj = new ThrowException(10);\n" 1811 " ThrowException obj = new ThrowException(10);\n"
1896 " return obj;\n" 1812 " return obj;\n"
1897 " }\n" 1813 " }\n"
1898 "}\n"; 1814 "}\n";
1899 Dart_Handle result; 1815 Dart_Handle result;
1900
1901 TestIsolateScope __test_isolate__;
1902
1903 Isolate* isolate = Isolate::Current(); 1816 Isolate* isolate = Isolate::Current();
1904 EXPECT(isolate != NULL); 1817 EXPECT(isolate != NULL);
1905 ApiState* state = isolate->api_state(); 1818 ApiState* state = isolate->api_state();
1906 EXPECT(state != NULL); 1819 EXPECT(state != NULL);
1907 { 1820 intptr_t size = state->ZoneSizeInBytes();
1908 intptr_t size = state->ZoneSizeInBytes(); 1821 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1909 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1910 1822
1911 // Load up a test script which extends the native wrapper class. 1823 // Load up a test script which extends the native wrapper class.
1912 Dart_Handle lib = TestCase::LoadTestScript( 1824 Dart_Handle lib = TestCase::LoadTestScript(
1913 kScriptChars, 1825 kScriptChars,
1914 reinterpret_cast<Dart_NativeEntryResolver>(native_lookup)); 1826 reinterpret_cast<Dart_NativeEntryResolver>(native_lookup));
1915 1827
1916 // Invoke a function which returns an object of type ThrowException. 1828 // Invoke a function which returns an object of type ThrowException.
1917 Dart_Handle retobj = Dart_InvokeStatic(lib, 1829 Dart_Handle retobj = Dart_InvokeStatic(lib,
1918 Dart_NewString("ThrowExceptionTest"), 1830 Dart_NewString("ThrowExceptionTest"),
1919 Dart_NewString("testMain"), 1831 Dart_NewString("testMain"),
1920 0, 1832 0,
1921 NULL); 1833 NULL);
1922 EXPECT_VALID(retobj); 1834 EXPECT_VALID(retobj);
1923 1835
1924 // Throwing an exception here should result in an error. 1836 // Throwing an exception here should result in an error.
1925 result = Dart_ThrowException(retobj); 1837 result = Dart_ThrowException(retobj);
1926 EXPECT(Dart_IsError(result)); 1838 EXPECT(Dart_IsError(result));
1927 1839
1928 // Now invoke method2 which invokes a natve method where it is 1840 // Now invoke method2 which invokes a natve method where it is
1929 // ok to throw an exception, check the result which would indicate 1841 // ok to throw an exception, check the result which would indicate
1930 // if an exception was thrown or not. 1842 // if an exception was thrown or not.
1931 result = Dart_InvokeDynamic(retobj, Dart_NewString("method2"), 0, NULL); 1843 result = Dart_InvokeDynamic(retobj, Dart_NewString("method2"), 0, NULL);
1932 EXPECT_VALID(result); 1844 EXPECT_VALID(result);
1933 EXPECT(Dart_IsInteger(result)); 1845 EXPECT(Dart_IsInteger(result));
1934 int64_t value = 0; 1846 int64_t value = 0;
1935 result = Dart_IntegerToInt64(result, &value); 1847 result = Dart_IntegerToInt64(result, &value);
1936 EXPECT_EQ(5, value); 1848 EXPECT_EQ(5, value);
1937 1849
1938 Dart_ExitScope(); // Exit the Dart API scope. 1850 Dart_ExitScope(); // Exit the Dart API scope.
1939 EXPECT_EQ(size, state->ZoneSizeInBytes()); 1851 EXPECT_EQ(size, state->ZoneSizeInBytes());
1940 }
1941 } 1852 }
1942 1853
1943 1854
1944 void NativeArgumentCounter(Dart_NativeArguments args) { 1855 void NativeArgumentCounter(Dart_NativeArguments args) {
1945 Dart_EnterScope(); 1856 Dart_EnterScope();
1946 int count = Dart_GetNativeArgumentCount(args); 1857 int count = Dart_GetNativeArgumentCount(args);
1947 Dart_SetReturnValue(args, Dart_NewInteger(count)); 1858 Dart_SetReturnValue(args, Dart_NewInteger(count));
1948 Dart_ExitScope(); 1859 Dart_ExitScope();
1949 } 1860 }
1950 1861
1951 1862
1952 static Dart_NativeFunction gnac_lookup(Dart_Handle name, int argument_count) { 1863 static Dart_NativeFunction gnac_lookup(Dart_Handle name, int argument_count) {
1953 return reinterpret_cast<Dart_NativeFunction>(&NativeArgumentCounter); 1864 return reinterpret_cast<Dart_NativeFunction>(&NativeArgumentCounter);
1954 } 1865 }
1955 1866
1956 1867
1957 UNIT_TEST_CASE(GetNativeArgumentCount) { 1868 TEST_CASE(GetNativeArgumentCount) {
1958 const char* kScriptChars = 1869 const char* kScriptChars =
1959 "class MyObject {" 1870 "class MyObject {"
1960 " int method1(int i, int j) native 'Name_Does_Not_Matter';" 1871 " int method1(int i, int j) native 'Name_Does_Not_Matter';"
1961 "}" 1872 "}"
1962 "class Test {" 1873 "class Test {"
1963 " static testMain() {" 1874 " static testMain() {"
1964 " MyObject obj = new MyObject();" 1875 " MyObject obj = new MyObject();"
1965 " return obj.method1(77, 125);" 1876 " return obj.method1(77, 125);"
1966 " }" 1877 " }"
1967 "}"; 1878 "}";
1968 1879
1969 TestIsolateScope __test_isolate__; 1880 Dart_Handle lib = TestCase::LoadTestScript(
1970 { 1881 kScriptChars,
1971 Dart_Handle lib = TestCase::LoadTestScript( 1882 reinterpret_cast<Dart_NativeEntryResolver>(gnac_lookup));
1972 kScriptChars,
1973 reinterpret_cast<Dart_NativeEntryResolver>(gnac_lookup));
1974 1883
1975 Dart_Handle result = Dart_InvokeStatic(lib, 1884 Dart_Handle result = Dart_InvokeStatic(lib,
1976 Dart_NewString("Test"), 1885 Dart_NewString("Test"),
1977 Dart_NewString("testMain"), 1886 Dart_NewString("testMain"),
1978 0, 1887 0,
1979 NULL); 1888 NULL);
1980 EXPECT_VALID(result); 1889 EXPECT_VALID(result);
1981 EXPECT(Dart_IsInteger(result)); 1890 EXPECT(Dart_IsInteger(result));
1982 1891
1983 int64_t value = 0; 1892 int64_t value = 0;
1984 result = Dart_IntegerToInt64(result, &value); 1893 result = Dart_IntegerToInt64(result, &value);
1985 EXPECT_VALID(result); 1894 EXPECT_VALID(result);
1986 EXPECT_EQ(3, value); 1895 EXPECT_EQ(3, value);
1987 }
1988 } 1896 }
1989 1897
1990 1898
1991 UNIT_TEST_CASE(GetClass) { 1899 TEST_CASE(GetClass) {
1992 const char* kScriptChars = 1900 const char* kScriptChars =
1993 "class DoesExist {" 1901 "class DoesExist {"
1994 "}"; 1902 "}";
1995 1903
1996 TestIsolateScope __test_isolate__;
1997
1998 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1904 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
1999 1905
2000 // Lookup a class that does exist. 1906 // Lookup a class that does exist.
2001 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("DoesExist")); 1907 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("DoesExist"));
2002 EXPECT_VALID(cls); 1908 EXPECT_VALID(cls);
2003 1909
2004 // Lookup a class that does not exist. 1910 // Lookup a class that does not exist.
2005 cls = Dart_GetClass(lib, Dart_NewString("DoesNotExist")); 1911 cls = Dart_GetClass(lib, Dart_NewString("DoesNotExist"));
2006 EXPECT(Dart_IsError(cls)); 1912 EXPECT(Dart_IsError(cls));
2007 EXPECT_STREQ("Class 'DoesNotExist' not found in library 'dart:test-lib'.", 1913 EXPECT_STREQ("Class 'DoesNotExist' not found in library 'dart:test-lib'.",
2008 Dart_GetError(cls)); 1914 Dart_GetError(cls));
2009 } 1915 }
2010 1916
2011 1917
2012 UNIT_TEST_CASE(InstanceOf) { 1918 TEST_CASE(InstanceOf) {
2013 const char* kScriptChars = 1919 const char* kScriptChars =
2014 "class OtherClass {\n" 1920 "class OtherClass {\n"
2015 " static returnNull() { return null; }\n" 1921 " static returnNull() { return null; }\n"
2016 "}\n" 1922 "}\n"
2017 "class InstanceOfTest {\n" 1923 "class InstanceOfTest {\n"
2018 " InstanceOfTest() {}\n" 1924 " InstanceOfTest() {}\n"
2019 " static InstanceOfTest testMain() {\n" 1925 " static InstanceOfTest testMain() {\n"
2020 " return new InstanceOfTest();\n" 1926 " return new InstanceOfTest();\n"
2021 " }\n" 1927 " }\n"
2022 "}\n"; 1928 "}\n";
2023 Dart_Handle result; 1929 Dart_Handle result;
1930 // Create a test library and Load up a test script in it.
1931 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
2024 1932
2025 TestIsolateScope __test_isolate__; 1933 // Invoke a function which returns an object of type InstanceOf..
2026 { 1934 Dart_Handle instanceOfTestObj =
2027 // Create a test library and Load up a test script in it. 1935 Dart_InvokeStatic(lib,
2028 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 1936 Dart_NewString("InstanceOfTest"),
1937 Dart_NewString("testMain"),
1938 0,
1939 NULL);
1940 EXPECT_VALID(instanceOfTestObj);
2029 1941
2030 // Invoke a function which returns an object of type InstanceOf.. 1942 // Fetch InstanceOfTest class.
2031 Dart_Handle instanceOfTestObj = 1943 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("InstanceOfTest"));
2032 Dart_InvokeStatic(lib, 1944 EXPECT_VALID(cls);
2033 Dart_NewString("InstanceOfTest"),
2034 Dart_NewString("testMain"),
2035 0,
2036 NULL);
2037 EXPECT_VALID(instanceOfTestObj);
2038 1945
2039 // Fetch InstanceOfTest class. 1946 // Now check instanceOfTestObj reported as an instance of
2040 Dart_Handle cls = Dart_GetClass(lib, Dart_NewString("InstanceOfTest")); 1947 // InstanceOfTest class.
2041 EXPECT_VALID(cls); 1948 bool is_instance = false;
1949 result = Dart_ObjectIsType(instanceOfTestObj, cls, &is_instance);
1950 EXPECT_VALID(result);
1951 EXPECT(is_instance);
2042 1952
2043 // Now check instanceOfTestObj reported as an instance of 1953 // Fetch OtherClass and check if instanceOfTestObj is instance of it.
2044 // InstanceOfTest class. 1954 Dart_Handle otherClass = Dart_GetClass(lib, Dart_NewString("OtherClass"));
2045 bool is_instance = false; 1955 EXPECT_VALID(otherClass);
2046 result = Dart_ObjectIsType(instanceOfTestObj, cls, &is_instance);
2047 EXPECT_VALID(result);
2048 EXPECT(is_instance);
2049 1956
2050 // Fetch OtherClass and check if instanceOfTestObj is instance of it. 1957 result = Dart_ObjectIsType(instanceOfTestObj, otherClass, &is_instance);
2051 Dart_Handle otherClass = Dart_GetClass(lib, Dart_NewString("OtherClass")); 1958 EXPECT_VALID(result);
2052 EXPECT_VALID(otherClass); 1959 EXPECT(!is_instance);
2053 1960
2054 result = Dart_ObjectIsType(instanceOfTestObj, otherClass, &is_instance); 1961 // Check that primitives are not instances of InstanceOfTest class.
2055 EXPECT_VALID(result); 1962 result = Dart_ObjectIsType(Dart_NewString("a string"), otherClass,
2056 EXPECT(!is_instance); 1963 &is_instance);
1964 EXPECT_VALID(result);
1965 EXPECT(!is_instance);
2057 1966
2058 // Check that primitives are not instances of InstanceOfTest class. 1967 result = Dart_ObjectIsType(Dart_NewInteger(42), otherClass, &is_instance);
2059 result = Dart_ObjectIsType(Dart_NewString("a string"), otherClass, 1968 EXPECT_VALID(result);
2060 &is_instance); 1969 EXPECT(!is_instance);
2061 EXPECT_VALID(result);
2062 EXPECT(!is_instance);
2063 1970
2064 result = Dart_ObjectIsType(Dart_NewInteger(42), otherClass, &is_instance); 1971 result = Dart_ObjectIsType(Dart_NewBoolean(true), otherClass, &is_instance);
2065 EXPECT_VALID(result); 1972 EXPECT_VALID(result);
2066 EXPECT(!is_instance); 1973 EXPECT(!is_instance);
2067 1974
2068 result = Dart_ObjectIsType(Dart_NewBoolean(true), otherClass, &is_instance); 1975 // Check that null is not an instance of InstanceOfTest class.
2069 EXPECT_VALID(result); 1976 Dart_Handle null = Dart_InvokeStatic(lib,
2070 EXPECT(!is_instance); 1977 Dart_NewString("OtherClass"),
1978 Dart_NewString("returnNull"),
1979 0,
1980 NULL);
1981 EXPECT_VALID(null);
2071 1982
2072 // Check that null is not an instance of InstanceOfTest class. 1983 result = Dart_ObjectIsType(null, otherClass, &is_instance);
2073 Dart_Handle null = Dart_InvokeStatic(lib, 1984 EXPECT_VALID(result);
2074 Dart_NewString("OtherClass"), 1985 EXPECT(!is_instance);
2075 Dart_NewString("returnNull"),
2076 0,
2077 NULL);
2078 EXPECT_VALID(null);
2079 1986
2080 result = Dart_ObjectIsType(null, otherClass, &is_instance); 1987 // Check that error is returned if null is passed as a class argument.
2081 EXPECT_VALID(result); 1988 result = Dart_ObjectIsType(null, null, &is_instance);
2082 EXPECT(!is_instance); 1989 EXPECT(Dart_IsError(result));
2083
2084 // Check that error is returned if null is passed as a class argument.
2085 result = Dart_ObjectIsType(null, null, &is_instance);
2086 EXPECT(Dart_IsError(result));
2087 }
2088 } 1990 }
2089 1991
2090 1992
2091 UNIT_TEST_CASE(NullReceiver) { 1993 TEST_CASE(NullReceiver) {
2092 TestIsolateScope __test_isolate__; 1994 DARTSCOPE_NOCHECKS(Isolate::Current());
2093 {
2094 DARTSCOPE_NOCHECKS(Isolate::Current());
2095 1995
2096 Dart_Handle function_name = Dart_NewString("toString"); 1996 Dart_Handle function_name = Dart_NewString("toString");
2097 const int number_of_arguments = 0; 1997 const int number_of_arguments = 0;
2098 Dart_Handle null_receiver = Api::NewLocalHandle(Object::Handle()); 1998 Dart_Handle null_receiver = Api::NewLocalHandle(Object::Handle());
2099 Dart_Handle result = Dart_InvokeDynamic(null_receiver, 1999 Dart_Handle result = Dart_InvokeDynamic(null_receiver,
2100 function_name, 2000 function_name,
2101 number_of_arguments, 2001 number_of_arguments,
2102 NULL); 2002 NULL);
2103 EXPECT_VALID(result); 2003 EXPECT_VALID(result);
2104 EXPECT(Dart_IsString(result)); 2004 EXPECT(Dart_IsString(result));
2105 2005
2106 // Should throw a NullPointerException. Disabled due to bug 5415268. 2006 // Should throw a NullPointerException. Disabled due to bug 5415268.
2107 /* 2007 /*
2108 Dart_Handle function_name2 = Dart_NewString("NoNoNo"); 2008 Dart_Handle function_name2 = Dart_NewString("NoNoNo");
2109 result = Dart_InvokeDynamic(null_receiver, 2009 result = Dart_InvokeDynamic(null_receiver,
2110 function_name2, 2010 function_name2,
2111 number_of_arguments, 2011 number_of_arguments,
2112 dart_arguments); 2012 dart_arguments);
2113 EXPECT(Dart_IsError(result)); 2013 EXPECT(Dart_IsError(result));
2114 EXPECT(Dart_ErrorHasException(result)); */ 2014 EXPECT(Dart_ErrorHasException(result)); */
2115 }
2116 } 2015 }
2117 2016
2118 2017
2119 static Dart_Handle library_handler(Dart_LibraryTag tag, 2018 static Dart_Handle library_handler(Dart_LibraryTag tag,
2120 Dart_Handle library, 2019 Dart_Handle library,
2121 Dart_Handle url) { 2020 Dart_Handle url) {
2122 if (tag == kCanonicalizeUrl) { 2021 if (tag == kCanonicalizeUrl) {
2123 return url; 2022 return url;
2124 } 2023 }
2125 return Api::Success(); 2024 return Api::Success();
2126 } 2025 }
2127 2026
2128 2027
2129 UNIT_TEST_CASE(LoadScript) { 2028 TEST_CASE(LoadScript) {
2130 const char* kScriptChars = 2029 const char* kScriptChars =
2131 "main() {" 2030 "main() {"
2132 " return 12345;" 2031 " return 12345;"
2133 "}"; 2032 "}";
2134
2135 TestIsolateScope __test_isolate__;
2136
2137 Dart_Handle url = Dart_NewString(TestCase::url()); 2033 Dart_Handle url = Dart_NewString(TestCase::url());
2138 Dart_Handle source = Dart_NewString(kScriptChars); 2034 Dart_Handle source = Dart_NewString(kScriptChars);
2139 Dart_Handle error = Dart_Error("incoming error"); 2035 Dart_Handle error = Dart_Error("incoming error");
2140 Dart_Handle result; 2036 Dart_Handle result;
2141 2037
2142 result = Dart_LoadScript(Dart_Null(), source, library_handler); 2038 result = Dart_LoadScript(Dart_Null(), source, library_handler);
2143 EXPECT(Dart_IsError(result)); 2039 EXPECT(Dart_IsError(result));
2144 EXPECT_STREQ("Dart_LoadScript expects argument 'url' to be non-null.", 2040 EXPECT_STREQ("Dart_LoadScript expects argument 'url' to be non-null.",
2145 Dart_GetError(result)); 2041 Dart_GetError(result));
2146 2042
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
2185 2081
2186 // Further calls to LoadScript are errors. 2082 // Further calls to LoadScript are errors.
2187 result = Dart_LoadScript(url, source, library_handler); 2083 result = Dart_LoadScript(url, source, library_handler);
2188 EXPECT(Dart_IsError(result)); 2084 EXPECT(Dart_IsError(result));
2189 EXPECT_STREQ("Dart_LoadScript: " 2085 EXPECT_STREQ("Dart_LoadScript: "
2190 "A script has already been loaded from 'dart:test-lib'.", 2086 "A script has already been loaded from 'dart:test-lib'.",
2191 Dart_GetError(result)); 2087 Dart_GetError(result));
2192 } 2088 }
2193 2089
2194 2090
2195 UNIT_TEST_CASE(LoadScript_CompileError) { 2091 TEST_CASE(LoadScript_CompileError) {
2196 const char* kScriptChars = 2092 const char* kScriptChars =
2197 ")"; 2093 ")";
2198
2199 TestIsolateScope __test_isolate__;
2200
2201 Dart_Handle url = Dart_NewString(TestCase::url()); 2094 Dart_Handle url = Dart_NewString(TestCase::url());
2202 Dart_Handle source = Dart_NewString(kScriptChars); 2095 Dart_Handle source = Dart_NewString(kScriptChars);
2203 Dart_Handle result = Dart_LoadScript(url, source, library_handler); 2096 Dart_Handle result = Dart_LoadScript(url, source, library_handler);
2204 EXPECT(Dart_IsError(result)); 2097 EXPECT(Dart_IsError(result));
2205 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); 2098 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'"));
2206 } 2099 }
2207 2100
2208 2101
2209 UNIT_TEST_CASE(LookupLibrary) { 2102 TEST_CASE(LookupLibrary) {
2210 const char* kScriptChars = 2103 const char* kScriptChars =
2211 "#import('library1.dart');" 2104 "#import('library1.dart');"
2212 "main() {}"; 2105 "main() {}";
2213 const char* kLibrary1Chars = 2106 const char* kLibrary1Chars =
2214 "#library('library1.dart');" 2107 "#library('library1.dart');"
2215 "#import('library2.dart');"; 2108 "#import('library2.dart');";
2216 2109
2217 TestIsolateScope __test_isolate__;
2218
2219 // Create a test library and Load up a test script in it. 2110 // Create a test library and Load up a test script in it.
2220 Dart_Handle url = Dart_NewString(TestCase::url()); 2111 Dart_Handle url = Dart_NewString(TestCase::url());
2221 Dart_Handle source = Dart_NewString(kScriptChars); 2112 Dart_Handle source = Dart_NewString(kScriptChars);
2222 Dart_Handle result = Dart_LoadScript(url, source, library_handler); 2113 Dart_Handle result = Dart_LoadScript(url, source, library_handler);
2223 EXPECT_VALID(result); 2114 EXPECT_VALID(result);
2224 2115
2225 url = Dart_NewString("library1.dart"); 2116 url = Dart_NewString("library1.dart");
2226 source = Dart_NewString(kLibrary1Chars); 2117 source = Dart_NewString(kLibrary1Chars);
2227 result = Dart_LoadLibrary(url, source); 2118 result = Dart_LoadLibrary(url, source);
2228 EXPECT_VALID(result); 2119 EXPECT_VALID(result);
(...skipping 17 matching lines...) Expand all
2246 EXPECT_STREQ("incoming error", Dart_GetError(result)); 2137 EXPECT_STREQ("incoming error", Dart_GetError(result));
2247 2138
2248 url = Dart_NewString("noodles.dart"); 2139 url = Dart_NewString("noodles.dart");
2249 result = Dart_LookupLibrary(url); 2140 result = Dart_LookupLibrary(url);
2250 EXPECT(Dart_IsError(result)); 2141 EXPECT(Dart_IsError(result));
2251 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.", 2142 EXPECT_STREQ("Dart_LookupLibrary: library 'noodles.dart' not found.",
2252 Dart_GetError(result)); 2143 Dart_GetError(result));
2253 } 2144 }
2254 2145
2255 2146
2256 UNIT_TEST_CASE(LibraryUrl) { 2147 TEST_CASE(LibraryUrl) {
2257 const char* kLibrary1Chars = 2148 const char* kLibrary1Chars =
2258 "#library('library1_name');"; 2149 "#library('library1_name');";
2259
2260 TestIsolateScope __test_isolate__;
2261
2262 Dart_Handle url = Dart_NewString("library1_url"); 2150 Dart_Handle url = Dart_NewString("library1_url");
2263 Dart_Handle source = Dart_NewString(kLibrary1Chars); 2151 Dart_Handle source = Dart_NewString(kLibrary1Chars);
2264 Dart_Handle lib = Dart_LoadLibrary(url, source); 2152 Dart_Handle lib = Dart_LoadLibrary(url, source);
2265 Dart_Handle error = Dart_Error("incoming error"); 2153 Dart_Handle error = Dart_Error("incoming error");
2266 EXPECT_VALID(lib); 2154 EXPECT_VALID(lib);
2267 2155
2268 Dart_Handle result = Dart_LibraryUrl(Dart_Null()); 2156 Dart_Handle result = Dart_LibraryUrl(Dart_Null());
2269 EXPECT(Dart_IsError(result)); 2157 EXPECT(Dart_IsError(result));
2270 EXPECT_STREQ("Dart_LibraryUrl expects argument 'library' to be non-null.", 2158 EXPECT_STREQ("Dart_LibraryUrl expects argument 'library' to be non-null.",
2271 Dart_GetError(result)); 2159 Dart_GetError(result));
(...skipping 10 matching lines...) Expand all
2282 2170
2283 result = Dart_LibraryUrl(lib); 2171 result = Dart_LibraryUrl(lib);
2284 EXPECT_VALID(result); 2172 EXPECT_VALID(result);
2285 EXPECT(Dart_IsString(result)); 2173 EXPECT(Dart_IsString(result));
2286 const char* cstr = NULL; 2174 const char* cstr = NULL;
2287 EXPECT_VALID(Dart_StringToCString(result, &cstr)); 2175 EXPECT_VALID(Dart_StringToCString(result, &cstr));
2288 EXPECT_STREQ("library1_url", cstr); 2176 EXPECT_STREQ("library1_url", cstr);
2289 } 2177 }
2290 2178
2291 2179
2292 UNIT_TEST_CASE(LibraryImportLibrary) { 2180 TEST_CASE(LibraryImportLibrary) {
2293 const char* kLibrary1Chars = 2181 const char* kLibrary1Chars =
2294 "#library('library1_name');"; 2182 "#library('library1_name');";
2295 const char* kLibrary2Chars = 2183 const char* kLibrary2Chars =
2296 "#library('library2_name');"; 2184 "#library('library2_name');";
2297
2298 TestIsolateScope __test_isolate__;
2299
2300 Dart_Handle error = Dart_Error("incoming error"); 2185 Dart_Handle error = Dart_Error("incoming error");
2301 Dart_Handle result; 2186 Dart_Handle result;
2302 2187
2303 Dart_Handle url = Dart_NewString("library1_url"); 2188 Dart_Handle url = Dart_NewString("library1_url");
2304 Dart_Handle source = Dart_NewString(kLibrary1Chars); 2189 Dart_Handle source = Dart_NewString(kLibrary1Chars);
2305 Dart_Handle lib1 = Dart_LoadLibrary(url, source); 2190 Dart_Handle lib1 = Dart_LoadLibrary(url, source);
2306 EXPECT_VALID(lib1); 2191 EXPECT_VALID(lib1);
2307 2192
2308 url = Dart_NewString("library2_url"); 2193 url = Dart_NewString("library2_url");
2309 source = Dart_NewString(kLibrary2Chars); 2194 source = Dart_NewString(kLibrary2Chars);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2341 result = Dart_LibraryImportLibrary(lib1, error); 2226 result = Dart_LibraryImportLibrary(lib1, error);
2342 EXPECT(Dart_IsError(result)); 2227 EXPECT(Dart_IsError(result));
2343 EXPECT_STREQ("incoming error", Dart_GetError(result)); 2228 EXPECT_STREQ("incoming error", Dart_GetError(result));
2344 2229
2345 result = Dart_LibraryImportLibrary(lib1, lib2); 2230 result = Dart_LibraryImportLibrary(lib1, lib2);
2346 EXPECT_VALID(result); 2231 EXPECT_VALID(result);
2347 } 2232 }
2348 2233
2349 2234
2350 2235
2351 UNIT_TEST_CASE(LoadLibrary) { 2236 TEST_CASE(LoadLibrary) {
2352 const char* kLibrary1Chars = 2237 const char* kLibrary1Chars =
2353 "#library('library1_name');"; 2238 "#library('library1_name');";
2354
2355 TestIsolateScope __test_isolate__;
2356
2357 Dart_Handle error = Dart_Error("incoming error"); 2239 Dart_Handle error = Dart_Error("incoming error");
2358 Dart_Handle result; 2240 Dart_Handle result;
2359 2241
2360 Dart_Handle url = Dart_NewString("library1_url"); 2242 Dart_Handle url = Dart_NewString("library1_url");
2361 Dart_Handle source = Dart_NewString(kLibrary1Chars); 2243 Dart_Handle source = Dart_NewString(kLibrary1Chars);
2362 2244
2363 result = Dart_LoadLibrary(Dart_Null(), source); 2245 result = Dart_LoadLibrary(Dart_Null(), source);
2364 EXPECT(Dart_IsError(result)); 2246 EXPECT(Dart_IsError(result));
2365 EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be non-null.", 2247 EXPECT_STREQ("Dart_LoadLibrary expects argument 'url' to be non-null.",
2366 Dart_GetError(result)); 2248 Dart_GetError(result));
(...skipping 29 matching lines...) Expand all
2396 2278
2397 // Duplicate library load fails. 2279 // Duplicate library load fails.
2398 result = Dart_LoadLibrary(url, source); 2280 result = Dart_LoadLibrary(url, source);
2399 EXPECT(Dart_IsError(result)); 2281 EXPECT(Dart_IsError(result));
2400 EXPECT_STREQ( 2282 EXPECT_STREQ(
2401 "Dart_LoadLibrary: library 'library1_url' has already been loaded.", 2283 "Dart_LoadLibrary: library 'library1_url' has already been loaded.",
2402 Dart_GetError(result)); 2284 Dart_GetError(result));
2403 } 2285 }
2404 2286
2405 2287
2406 UNIT_TEST_CASE(LoadLibrary_CompileError) { 2288 TEST_CASE(LoadLibrary_CompileError) {
2407 const char* kLibrary1Chars = 2289 const char* kLibrary1Chars =
2408 "#library('library1_name');" 2290 "#library('library1_name');"
2409 ")"; 2291 ")";
2410
2411 TestIsolateScope __test_isolate__;
2412
2413 Dart_Handle url = Dart_NewString("library1_url"); 2292 Dart_Handle url = Dart_NewString("library1_url");
2414 Dart_Handle source = Dart_NewString(kLibrary1Chars); 2293 Dart_Handle source = Dart_NewString(kLibrary1Chars);
2415 Dart_Handle result = Dart_LoadLibrary(url, source); 2294 Dart_Handle result = Dart_LoadLibrary(url, source);
2416 EXPECT(Dart_IsError(result)); 2295 EXPECT(Dart_IsError(result));
2417 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); 2296 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'"));
2418 } 2297 }
2419 2298
2420 2299
2421 UNIT_TEST_CASE(LoadSource) { 2300 TEST_CASE(LoadSource) {
2422 const char* kLibrary1Chars = 2301 const char* kLibrary1Chars =
2423 "#library('library1_name');"; 2302 "#library('library1_name');";
2424 const char* kSourceChars = 2303 const char* kSourceChars =
2425 "// Something innocuous"; 2304 "// Something innocuous";
2426 const char* kBadSourceChars = 2305 const char* kBadSourceChars =
2427 ")"; 2306 ")";
2428
2429 TestIsolateScope __test_isolate__;
2430
2431 Dart_Handle error = Dart_Error("incoming error"); 2307 Dart_Handle error = Dart_Error("incoming error");
2432 Dart_Handle result; 2308 Dart_Handle result;
2433 2309
2434 // Load up a library. 2310 // Load up a library.
2435 Dart_Handle url = Dart_NewString("library1_url"); 2311 Dart_Handle url = Dart_NewString("library1_url");
2436 Dart_Handle source = Dart_NewString(kLibrary1Chars); 2312 Dart_Handle source = Dart_NewString(kLibrary1Chars);
2437 Dart_Handle lib = Dart_LoadLibrary(url, source); 2313 Dart_Handle lib = Dart_LoadLibrary(url, source);
2438 EXPECT_VALID(lib); 2314 EXPECT_VALID(lib);
2439 EXPECT(Dart_IsLibrary(lib)); 2315 EXPECT(Dart_IsLibrary(lib));
2440 2316
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
2527 return &MyNativeFunction1; 2403 return &MyNativeFunction1;
2528 } 2404 }
2529 2405
2530 2406
2531 static Dart_NativeFunction MyNativeResolver2(Dart_Handle name, 2407 static Dart_NativeFunction MyNativeResolver2(Dart_Handle name,
2532 int arg_count) { 2408 int arg_count) {
2533 return &MyNativeFunction2; 2409 return &MyNativeFunction2;
2534 } 2410 }
2535 2411
2536 2412
2537 UNIT_TEST_CASE(SetNativeResolver) { 2413 TEST_CASE(SetNativeResolver) {
2538 const char* kScriptChars = 2414 const char* kScriptChars =
2539 "class Test {" 2415 "class Test {"
2540 " static foo() native \"SomeNativeFunction\";" 2416 " static foo() native \"SomeNativeFunction\";"
2541 " static bar() native \"SomeNativeFunction2\";" 2417 " static bar() native \"SomeNativeFunction2\";"
2542 " static baz() native \"SomeNativeFunction3\";" 2418 " static baz() native \"SomeNativeFunction3\";"
2543 "}"; 2419 "}";
2544
2545 TestIsolateScope __test_isolate__;
2546
2547 Dart_Handle error = Dart_Error("incoming error"); 2420 Dart_Handle error = Dart_Error("incoming error");
2548 Dart_Handle result; 2421 Dart_Handle result;
2549 2422
2550 // Load a test script. 2423 // Load a test script.
2551 Dart_Handle url = Dart_NewString(TestCase::url()); 2424 Dart_Handle url = Dart_NewString(TestCase::url());
2552 Dart_Handle source = Dart_NewString(kScriptChars); 2425 Dart_Handle source = Dart_NewString(kScriptChars);
2553 Dart_Handle lib = Dart_LoadScript(url, source, library_handler); 2426 Dart_Handle lib = Dart_LoadScript(url, source, library_handler);
2554 EXPECT_VALID(lib); 2427 EXPECT_VALID(lib);
2555 EXPECT(Dart_IsLibrary(lib)); 2428 EXPECT(Dart_IsLibrary(lib));
2556 2429
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2621 Dart_NewString("Test"), 2494 Dart_NewString("Test"),
2622 Dart_NewString("baz"), 2495 Dart_NewString("baz"),
2623 0, 2496 0,
2624 NULL); 2497 NULL);
2625 EXPECT(Dart_IsError(result)); 2498 EXPECT(Dart_IsError(result));
2626 EXPECT(strstr(Dart_GetError(result), 2499 EXPECT(strstr(Dart_GetError(result),
2627 "native function 'SomeNativeFunction3' cannot be found")); 2500 "native function 'SomeNativeFunction3' cannot be found"));
2628 } 2501 }
2629 2502
2630 2503
2631 UNIT_TEST_CASE(ImportLibrary1) { 2504 TEST_CASE(ImportLibrary1) {
2632 const char* kScriptChars = 2505 const char* kScriptChars =
2633 "#import('library1.dart');" 2506 "#import('library1.dart');"
2634 "#import('library2.dart');" 2507 "#import('library2.dart');"
2635 "var foo; // library2 defines foo, so should be error." 2508 "var foo; // library2 defines foo, so should be error."
2636 "main() {}"; 2509 "main() {}";
2637 const char* kLibrary1Chars = 2510 const char* kLibrary1Chars =
2638 "#library('library1.dart');" 2511 "#library('library1.dart');"
2639 "#import('library2.dart');" 2512 "#import('library2.dart');"
2640 "var foo1;"; 2513 "var foo1;";
2641 const char* kLibrary2Chars = 2514 const char* kLibrary2Chars =
2642 "#library('library2.dart');" 2515 "#library('library2.dart');"
2643 "var foo;"; 2516 "var foo;";
2644 Dart_Handle result; 2517 Dart_Handle result;
2518 // Create a test library and Load up a test script in it.
2519 Dart_Handle url = Dart_NewString(TestCase::url());
2520 Dart_Handle source = Dart_NewString(kScriptChars);
2521 result = Dart_LoadScript(url, source, library_handler);
2645 2522
2646 TestIsolateScope __test_isolate__; 2523 url = Dart_NewString("library1.dart");
2647 { 2524 source = Dart_NewString(kLibrary1Chars);
2648 // Create a test library and Load up a test script in it. 2525 Dart_LoadLibrary(url, source);
2649 Dart_Handle url = Dart_NewString(TestCase::url());
2650 Dart_Handle source = Dart_NewString(kScriptChars);
2651 result = Dart_LoadScript(url, source, library_handler);
2652 2526
2653 url = Dart_NewString("library1.dart"); 2527 url = Dart_NewString("library2.dart");
2654 source = Dart_NewString(kLibrary1Chars); 2528 source = Dart_NewString(kLibrary2Chars);
2655 Dart_LoadLibrary(url, source); 2529 Dart_LoadLibrary(url, source);
2656 2530
2657 url = Dart_NewString("library2.dart"); 2531 result = Dart_InvokeStatic(result,
2658 source = Dart_NewString(kLibrary2Chars); 2532 Dart_NewString(""),
2659 Dart_LoadLibrary(url, source); 2533 Dart_NewString("main"),
2660 2534 0,
2661 result = Dart_InvokeStatic(result, 2535 NULL);
2662 Dart_NewString(""), 2536 EXPECT(Dart_IsError(result));
2663 Dart_NewString("main"), 2537 EXPECT_STREQ("Duplicate definition : 'foo' is defined in"
2664 0, 2538 " 'library2.dart' and 'dart:test-lib'\n",
2665 NULL); 2539 Dart_GetError(result));
2666 EXPECT(Dart_IsError(result));
2667 EXPECT_STREQ("Duplicate definition : 'foo' is defined in"
2668 " 'library2.dart' and 'dart:test-lib'\n",
2669 Dart_GetError(result));
2670 }
2671 } 2540 }
2672 2541
2673 2542
2674 UNIT_TEST_CASE(ImportLibrary2) { 2543 TEST_CASE(ImportLibrary2) {
2675 const char* kScriptChars = 2544 const char* kScriptChars =
2676 "#import('library1.dart');" 2545 "#import('library1.dart');"
2677 "var foo;" 2546 "var foo;"
2678 "main() {}"; 2547 "main() {}";
2679 const char* kLibrary1Chars = 2548 const char* kLibrary1Chars =
2680 "#library('library1.dart');" 2549 "#library('library1.dart');"
2681 "#import('library2.dart');" 2550 "#import('library2.dart');"
2682 "var foo1;"; 2551 "var foo1;";
2683 const char* kLibrary2Chars = 2552 const char* kLibrary2Chars =
2684 "#library('library2.dart');" 2553 "#library('library2.dart');"
2685 "#import('library1.dart');" 2554 "#import('library1.dart');"
2686 "var foo;"; 2555 "var foo;";
2687 Dart_Handle result; 2556 Dart_Handle result;
2557 // Create a test library and Load up a test script in it.
2558 Dart_Handle url = Dart_NewString(TestCase::url());
2559 Dart_Handle source = Dart_NewString(kScriptChars);
2560 result = Dart_LoadScript(url, source, library_handler);
2688 2561
2689 TestIsolateScope __test_isolate__; 2562 url = Dart_NewString("library1.dart");
2690 { 2563 source = Dart_NewString(kLibrary1Chars);
2691 // Create a test library and Load up a test script in it. 2564 Dart_LoadLibrary(url, source);
2692 Dart_Handle url = Dart_NewString(TestCase::url());
2693 Dart_Handle source = Dart_NewString(kScriptChars);
2694 result = Dart_LoadScript(url, source, library_handler);
2695 2565
2696 url = Dart_NewString("library1.dart"); 2566 url = Dart_NewString("library2.dart");
2697 source = Dart_NewString(kLibrary1Chars); 2567 source = Dart_NewString(kLibrary2Chars);
2698 Dart_LoadLibrary(url, source); 2568 Dart_LoadLibrary(url, source);
2699 2569
2700 url = Dart_NewString("library2.dart"); 2570 result = Dart_InvokeStatic(result,
2701 source = Dart_NewString(kLibrary2Chars); 2571 Dart_NewString(""),
2702 Dart_LoadLibrary(url, source); 2572 Dart_NewString("main"),
2703 2573 0,
2704 result = Dart_InvokeStatic(result, 2574 NULL);
2705 Dart_NewString(""), 2575 EXPECT_VALID(result);
2706 Dart_NewString("main"),
2707 0,
2708 NULL);
2709 EXPECT_VALID(result);
2710 }
2711 } 2576 }
2712 2577
2713 2578
2714 UNIT_TEST_CASE(ImportLibrary3) { 2579 TEST_CASE(ImportLibrary3) {
2715 const char* kScriptChars = 2580 const char* kScriptChars =
2716 "#import('library2.dart');" 2581 "#import('library2.dart');"
2717 "#import('library1.dart');" 2582 "#import('library1.dart');"
2718 "var foo_top = 10; // foo has dup def. So should be an error." 2583 "var foo_top = 10; // foo has dup def. So should be an error."
2719 "main() {}"; 2584 "main() {}";
2720 const char* kLibrary1Chars = 2585 const char* kLibrary1Chars =
2721 "#library('library1.dart');" 2586 "#library('library1.dart');"
2722 "var foo;"; 2587 "var foo;";
2723 const char* kLibrary2Chars = 2588 const char* kLibrary2Chars =
2724 "#library('library2.dart');" 2589 "#library('library2.dart');"
2725 "var foo;"; 2590 "var foo;";
2726 Dart_Handle result; 2591 Dart_Handle result;
2727 2592
2728 TestIsolateScope __test_isolate__; 2593 // Create a test library and Load up a test script in it.
2729 { 2594 Dart_Handle url = Dart_NewString(TestCase::url());
2730 // Create a test library and Load up a test script in it. 2595 Dart_Handle source = Dart_NewString(kScriptChars);
2731 Dart_Handle url = Dart_NewString(TestCase::url()); 2596 result = Dart_LoadScript(url, source, library_handler);
2732 Dart_Handle source = Dart_NewString(kScriptChars);
2733 result = Dart_LoadScript(url, source, library_handler);
2734 2597
2735 url = Dart_NewString("library2.dart"); 2598 url = Dart_NewString("library2.dart");
2736 source = Dart_NewString(kLibrary2Chars); 2599 source = Dart_NewString(kLibrary2Chars);
2737 Dart_LoadLibrary(url, source); 2600 Dart_LoadLibrary(url, source);
2738 2601
2739 url = Dart_NewString("library1.dart"); 2602 url = Dart_NewString("library1.dart");
2740 source = Dart_NewString(kLibrary1Chars); 2603 source = Dart_NewString(kLibrary1Chars);
2741 Dart_LoadLibrary(url, source); 2604 Dart_LoadLibrary(url, source);
2742 2605
2743 result = Dart_InvokeStatic(result, 2606 result = Dart_InvokeStatic(result,
2744 Dart_NewString(""), 2607 Dart_NewString(""),
2745 Dart_NewString("main"), 2608 Dart_NewString("main"),
2746 0, 2609 0,
2747 NULL); 2610 NULL);
2748 EXPECT(Dart_IsError(result)); 2611 EXPECT(Dart_IsError(result));
2749 EXPECT_STREQ("Duplicate definition : 'foo' is defined in" 2612 EXPECT_STREQ("Duplicate definition : 'foo' is defined in"
2750 " 'library1.dart' and 'library2.dart'\n", 2613 " 'library1.dart' and 'library2.dart'\n",
2751 Dart_GetError(result)); 2614 Dart_GetError(result));
2752 }
2753 } 2615 }
2754 2616
2755 2617
2756 UNIT_TEST_CASE(ImportLibrary4) { 2618 TEST_CASE(ImportLibrary4) {
2757 const char* kScriptChars = 2619 const char* kScriptChars =
2758 "#import('libraryA.dart');" 2620 "#import('libraryA.dart');"
2759 "#import('libraryB.dart');" 2621 "#import('libraryB.dart');"
2760 "#import('libraryD.dart');" 2622 "#import('libraryD.dart');"
2761 "#import('libraryE.dart');" 2623 "#import('libraryE.dart');"
2762 "var fooApp;" 2624 "var fooApp;"
2763 "main() {}"; 2625 "main() {}";
2764 const char* kLibraryAChars = 2626 const char* kLibraryAChars =
2765 "#library('libraryA.dart');" 2627 "#library('libraryA.dart');"
2766 "#import('libraryC.dart');" 2628 "#import('libraryC.dart');"
(...skipping 12 matching lines...) Expand all
2779 const char* kLibraryEChars = 2641 const char* kLibraryEChars =
2780 "#library('libraryE.dart');" 2642 "#library('libraryE.dart');"
2781 "#import('libraryC.dart');" 2643 "#import('libraryC.dart');"
2782 "#import('libraryF.dart');" 2644 "#import('libraryF.dart');"
2783 "var fooE = 10; //fooC has duplicate def. so should be an error."; 2645 "var fooE = 10; //fooC has duplicate def. so should be an error.";
2784 const char* kLibraryFChars = 2646 const char* kLibraryFChars =
2785 "#library('libraryF.dart');" 2647 "#library('libraryF.dart');"
2786 "var fooC;"; 2648 "var fooC;";
2787 Dart_Handle result; 2649 Dart_Handle result;
2788 2650
2789 TestIsolateScope __test_isolate__; 2651 // Create a test library and Load up a test script in it.
2790 { 2652 Dart_Handle url = Dart_NewString(TestCase::url());
2791 // Create a test library and Load up a test script in it. 2653 Dart_Handle source = Dart_NewString(kScriptChars);
2792 Dart_Handle url = Dart_NewString(TestCase::url()); 2654 result = Dart_LoadScript(url, source, library_handler);
2793 Dart_Handle source = Dart_NewString(kScriptChars);
2794 result = Dart_LoadScript(url, source, library_handler);
2795 2655
2796 url = Dart_NewString("libraryA.dart"); 2656 url = Dart_NewString("libraryA.dart");
2797 source = Dart_NewString(kLibraryAChars); 2657 source = Dart_NewString(kLibraryAChars);
2798 Dart_LoadLibrary(url, source); 2658 Dart_LoadLibrary(url, source);
2799 2659
2800 url = Dart_NewString("libraryC.dart"); 2660 url = Dart_NewString("libraryC.dart");
2801 source = Dart_NewString(kLibraryCChars); 2661 source = Dart_NewString(kLibraryCChars);
2802 Dart_LoadLibrary(url, source); 2662 Dart_LoadLibrary(url, source);
2803 2663
2804 url = Dart_NewString("libraryB.dart"); 2664 url = Dart_NewString("libraryB.dart");
2805 source = Dart_NewString(kLibraryBChars); 2665 source = Dart_NewString(kLibraryBChars);
2806 Dart_LoadLibrary(url, source); 2666 Dart_LoadLibrary(url, source);
2807 2667
2808 url = Dart_NewString("libraryD.dart"); 2668 url = Dart_NewString("libraryD.dart");
2809 source = Dart_NewString(kLibraryDChars); 2669 source = Dart_NewString(kLibraryDChars);
2810 Dart_LoadLibrary(url, source); 2670 Dart_LoadLibrary(url, source);
2811 2671
2812 url = Dart_NewString("libraryF.dart"); 2672 url = Dart_NewString("libraryF.dart");
2813 source = Dart_NewString(kLibraryFChars); 2673 source = Dart_NewString(kLibraryFChars);
2814 Dart_LoadLibrary(url, source); 2674 Dart_LoadLibrary(url, source);
2815 2675
2816 url = Dart_NewString("libraryE.dart"); 2676 url = Dart_NewString("libraryE.dart");
2817 source = Dart_NewString(kLibraryEChars); 2677 source = Dart_NewString(kLibraryEChars);
2818 Dart_LoadLibrary(url, source); 2678 Dart_LoadLibrary(url, source);
2819 2679
2820 result = Dart_InvokeStatic(result, 2680 result = Dart_InvokeStatic(result,
2821 Dart_NewString(""), 2681 Dart_NewString(""),
2822 Dart_NewString("main"), 2682 Dart_NewString("main"),
2823 0, 2683 0,
2824 NULL); 2684 NULL);
2825 EXPECT(Dart_IsError(result)); 2685 EXPECT(Dart_IsError(result));
2826 EXPECT_STREQ("Duplicate definition : 'fooC' is defined in" 2686 EXPECT_STREQ("Duplicate definition : 'fooC' is defined in"
2827 " 'libraryF.dart' and 'libraryC.dart'\n", 2687 " 'libraryF.dart' and 'libraryC.dart'\n",
2828 Dart_GetError(result)); 2688 Dart_GetError(result));
2829 }
2830 } 2689 }
2831 2690
2832 2691
2833 UNIT_TEST_CASE(ImportLibrary5) { 2692 TEST_CASE(ImportLibrary5) {
2834 const char* kScriptChars = 2693 const char* kScriptChars =
2835 "#import('lib.dart');" 2694 "#import('lib.dart');"
2836 "interface Y {" 2695 "interface Y {"
2837 " void set handler(void callback(List<int> x));" 2696 " void set handler(void callback(List<int> x));"
2838 "}" 2697 "}"
2839 "void main() {}"; 2698 "void main() {}";
2840 const char* kLibraryChars = 2699 const char* kLibraryChars =
2841 "#library('lib.dart');" 2700 "#library('lib.dart');"
2842 "interface X {" 2701 "interface X {"
2843 " void set handler(void callback(List<int> x));" 2702 " void set handler(void callback(List<int> x));"
2844 "}"; 2703 "}";
2845 Dart_Handle result; 2704 Dart_Handle result;
2846 2705
2847 TestIsolateScope __test_isolate__; 2706 // Create a test library and Load up a test script in it.
2848 { 2707 Dart_Handle url = Dart_NewString(TestCase::url());
2849 // Create a test library and Load up a test script in it. 2708 Dart_Handle source = Dart_NewString(kScriptChars);
2850 Dart_Handle url = Dart_NewString(TestCase::url()); 2709 result = Dart_LoadScript(url, source, library_handler);
2851 Dart_Handle source = Dart_NewString(kScriptChars);
2852 result = Dart_LoadScript(url, source, library_handler);
2853 2710
2854 url = Dart_NewString("lib.dart"); 2711 url = Dart_NewString("lib.dart");
2855 source = Dart_NewString(kLibraryChars); 2712 source = Dart_NewString(kLibraryChars);
2856 Dart_LoadLibrary(url, source); 2713 Dart_LoadLibrary(url, source);
2857 2714
2858 result = Dart_InvokeStatic(result, 2715 result = Dart_InvokeStatic(result,
2859 Dart_NewString(""), 2716 Dart_NewString(""),
2860 Dart_NewString("main"), 2717 Dart_NewString("main"),
2861 0, 2718 0,
2862 NULL); 2719 NULL);
2863 EXPECT_VALID(result); 2720 EXPECT_VALID(result);
2864 }
2865 } 2721 }
2866 2722
2867 2723
2868 static bool RunLoopTestCallback(void* data, char** error) { 2724 static bool RunLoopTestCallback(void* data, char** error) {
2869 const char* kScriptChars = 2725 const char* kScriptChars =
2870 "#import('builtin');\n" 2726 "#import('builtin');\n"
2871 "class MyIsolate extends Isolate {\n" 2727 "class MyIsolate extends Isolate {\n"
2872 " MyIsolate() : super() { }\n" 2728 " MyIsolate() : super() { }\n"
2873 " void main() {\n" 2729 " void main() {\n"
2874 " port.receive((message, replyTo) {\n" 2730 " port.receive((message, replyTo) {\n"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
3115 // We should have received the expected number of interrupts. 2971 // We should have received the expected number of interrupts.
3116 EXPECT_EQ(kInterruptCount, interrupt_count); 2972 EXPECT_EQ(kInterruptCount, interrupt_count);
3117 2973
3118 // Give the spawned thread enough time to properly exit. 2974 // Give the spawned thread enough time to properly exit.
3119 Isolate::SetInterruptCallback(saved); 2975 Isolate::SetInterruptCallback(saved);
3120 } 2976 }
3121 2977
3122 #endif // TARGET_ARCH_IA32. 2978 #endif // TARGET_ARCH_IA32.
3123 2979
3124 } // namespace dart 2980 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698