OLD | NEW |
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/unit_test.h" | 7 #include "vm/unit_test.h" |
8 | 8 |
9 // Custom Isolate Test. | 9 // Custom Isolate Test. |
10 // | 10 // |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 EXPECT(Dart_IsString(param)); | 349 EXPECT(Dart_IsString(param)); |
350 const char* isolate_main = NULL; | 350 const char* isolate_main = NULL; |
351 EXPECT_VALID(Dart_StringToCString(param, &isolate_main)); | 351 EXPECT_VALID(Dart_StringToCString(param, &isolate_main)); |
352 isolate_main = strdup(isolate_main); | 352 isolate_main = strdup(isolate_main); |
353 | 353 |
354 // Save current isolate. | 354 // Save current isolate. |
355 Dart_Isolate saved_isolate = Dart_CurrentIsolate(); | 355 Dart_Isolate saved_isolate = Dart_CurrentIsolate(); |
356 Dart_ExitIsolate(); | 356 Dart_ExitIsolate(); |
357 | 357 |
358 // Create a new Dart_Isolate. | 358 // Create a new Dart_Isolate. |
359 Dart_Isolate new_isolate = Dart_CreateIsolate(NULL, NULL); | 359 Dart_Isolate new_isolate = TestCase::CreateTestIsolate(); |
| 360 EXPECT(new_isolate != NULL); |
360 Dart_SetMessageCallbacks(&PostMessage, &ClosePort); | 361 Dart_SetMessageCallbacks(&PostMessage, &ClosePort); |
361 Dart_Port new_port = Dart_GetMainPortId(); | 362 Dart_Port new_port = Dart_GetMainPortId(); |
362 | 363 |
363 OS::Print("-- Adding StartEvent to queue --\n"); | 364 OS::Print("-- Adding StartEvent to queue --\n"); |
364 event_queue->Add(new StartEvent(new_isolate, isolate_main)); | 365 event_queue->Add(new StartEvent(new_isolate, isolate_main)); |
365 | 366 |
366 // Restore the original isolate. | 367 // Restore the original isolate. |
367 Dart_ExitIsolate(); | 368 Dart_ExitIsolate(); |
368 Dart_EnterIsolate(saved_isolate); | 369 Dart_EnterIsolate(saved_isolate); |
369 Dart_EnterScope(); | 370 Dart_EnterScope(); |
370 | 371 |
371 Dart_Handle send_port = Dart_NewSendPort(new_port); | 372 Dart_Handle send_port = Dart_NewSendPort(new_port); |
372 EXPECT_VALID(send_port); | 373 EXPECT_VALID(send_port); |
373 Dart_SetReturnValue(args, send_port); | 374 Dart_SetReturnValue(args, send_port); |
374 | 375 |
375 OS::Print("-- Exit: CustomIsolateImpl_start --\n"); | 376 OS::Print("-- Exit: CustomIsolateImpl_start --\n"); |
376 Dart_ExitScope(); | 377 Dart_ExitScope(); |
377 } | 378 } |
378 | 379 |
379 | 380 |
380 UNIT_TEST_CASE(CustomIsolates) { | 381 UNIT_TEST_CASE(CustomIsolates) { |
381 event_queue = new EventQueue(); | 382 event_queue = new EventQueue(); |
382 current_event = NULL; | 383 current_event = NULL; |
383 | 384 |
384 Dart_CreateIsolate(NULL, NULL); | 385 Dart_Isolate dart_isolate = TestCase::CreateTestIsolate(); |
| 386 EXPECT(dart_isolate != NULL); |
385 Dart_SetMessageCallbacks(&PostMessage, &ClosePort); | 387 Dart_SetMessageCallbacks(&PostMessage, &ClosePort); |
386 Dart_EnterScope(); | 388 Dart_EnterScope(); |
387 Dart_Handle result; | 389 Dart_Handle result; |
388 | 390 |
389 // Create a test library. | 391 // Create a test library. |
390 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars, | 392 Dart_Handle lib = TestCase::LoadTestScript(kCustomIsolateScriptChars, |
391 NativeLookup); | 393 NativeLookup); |
392 EXPECT_VALID(lib); | 394 EXPECT_VALID(lib); |
393 | 395 |
394 // Run main. | 396 // Run main. |
(...skipping 23 matching lines...) Expand all Loading... |
418 OS::Print("-- Finished event loop --\n"); | 420 OS::Print("-- Finished event loop --\n"); |
419 EXPECT_STREQ("Received: 43", saved_echo); | 421 EXPECT_STREQ("Received: 43", saved_echo); |
420 free(const_cast<char*>(saved_echo)); | 422 free(const_cast<char*>(saved_echo)); |
421 | 423 |
422 delete event_queue; | 424 delete event_queue; |
423 } | 425 } |
424 | 426 |
425 #endif // TARGET_ARCH_IA32. | 427 #endif // TARGET_ARCH_IA32. |
426 | 428 |
427 } // namespace dart | 429 } // namespace dart |
OLD | NEW |