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 #ifndef VM_UNIT_TEST_H_ | 5 #ifndef VM_UNIT_TEST_H_ |
6 #define VM_UNIT_TEST_H_ | 6 #define VM_UNIT_TEST_H_ |
7 | 7 |
8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 | 9 |
10 #include "platform/globals.h" | 10 #include "platform/globals.h" |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 class TestCase : TestCaseBase { | 279 class TestCase : TestCaseBase { |
280 public: | 280 public: |
281 typedef void (RunEntry)(); | 281 typedef void (RunEntry)(); |
282 | 282 |
283 TestCase(RunEntry* run, const char* name) : TestCaseBase(name), run_(run) { } | 283 TestCase(RunEntry* run, const char* name) : TestCaseBase(name), run_(run) { } |
284 | 284 |
285 static Dart_Handle LoadTestScript(const char* script, | 285 static Dart_Handle LoadTestScript(const char* script, |
286 Dart_NativeEntryResolver resolver, | 286 Dart_NativeEntryResolver resolver, |
287 const char* lib_uri = USER_TEST_URI, | 287 const char* lib_uri = USER_TEST_URI, |
288 bool finalize = true); | 288 bool finalize = true); |
289 | |
290 static Dart_Handle LoadCoreTestScript(const char* script, | 289 static Dart_Handle LoadCoreTestScript(const char* script, |
291 Dart_NativeEntryResolver resolver); | 290 Dart_NativeEntryResolver resolver); |
292 static Dart_Handle lib(); | 291 static Dart_Handle lib(); |
293 static const char* url() { return USER_TEST_URI; } | 292 static const char* url() { return USER_TEST_URI; } |
294 static Dart_Isolate CreateTestIsolateFromSnapshot( | 293 static Dart_Isolate CreateTestIsolateFromSnapshot( |
295 uint8_t* buffer, const char* name = NULL) { | 294 uint8_t* buffer, const char* name = NULL) { |
296 return CreateIsolate(buffer, name); | 295 return CreateIsolate(buffer, name); |
297 } | 296 } |
298 static Dart_Isolate CreateTestIsolate(const char* name = NULL) { | 297 static Dart_Isolate CreateTestIsolate(const char* name = NULL) { |
299 return CreateIsolate(bin::isolate_snapshot_buffer, name); | 298 return CreateIsolate(bin::isolate_snapshot_buffer, name); |
300 } | 299 } |
301 static Dart_Handle library_handler(Dart_LibraryTag tag, | 300 static Dart_Handle library_handler(Dart_LibraryTag tag, |
302 Dart_Handle library, | 301 Dart_Handle library, |
303 Dart_Handle url); | 302 Dart_Handle url); |
304 static char* BigintToHexValue(Dart_CObject* bigint); | 303 static char* BigintToHexValue(Dart_CObject* bigint); |
305 | 304 |
306 virtual void Run(); | 305 virtual void Run(); |
307 | 306 |
| 307 // Sets |script| to be the source used at next reload. |
| 308 static void SetReloadTestScript(const char* script); |
| 309 // Initiates the reload. |
| 310 static Dart_Handle TriggerReload(); |
| 311 // Gets the result of a reload. |
| 312 static Dart_Handle GetReloadErrorOrRootLibrary(); |
| 313 |
| 314 // Helper function which reloads the current isolate using |script|. |
| 315 static Dart_Handle ReloadTestScript(const char* script); |
| 316 |
308 private: | 317 private: |
309 static Dart_Isolate CreateIsolate(const uint8_t* buffer, const char* name); | 318 static Dart_Isolate CreateIsolate(const uint8_t* buffer, const char* name); |
310 | 319 |
311 RunEntry* const run_; | 320 RunEntry* const run_; |
312 }; | 321 }; |
313 | 322 |
314 | 323 |
315 class TestIsolateScope { | 324 class TestIsolateScope { |
316 public: | 325 public: |
317 TestIsolateScope() { | 326 TestIsolateScope() { |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 // prefix = "classes" | 588 // prefix = "classes" |
580 // in = "\"id\":\"classes/46\"" | 589 // in = "\"id\":\"classes/46\"" |
581 // | 590 // |
582 // Yields: | 591 // Yields: |
583 // | 592 // |
584 // out = "\"id\":\"\"" | 593 // out = "\"id\":\"\"" |
585 // | 594 // |
586 void ElideJSONSubstring(const char* prefix, const char* in, char* out); | 595 void ElideJSONSubstring(const char* prefix, const char* in, char* out); |
587 | 596 |
588 | 597 |
| 598 template<typename T> |
| 599 class SetFlagScope : public ValueObject { |
| 600 public: |
| 601 SetFlagScope(T* flag, T value) |
| 602 : flag_(flag), |
| 603 original_value_(*flag) { |
| 604 *flag_ = value; |
| 605 } |
| 606 |
| 607 ~SetFlagScope() { |
| 608 *flag_ = original_value_; |
| 609 } |
| 610 |
| 611 private: |
| 612 T* flag_; |
| 613 T original_value_; |
| 614 }; |
| 615 |
589 } // namespace dart | 616 } // namespace dart |
590 | 617 |
591 #endif // VM_UNIT_TEST_H_ | 618 #endif // VM_UNIT_TEST_H_ |
OLD | NEW |