Chromium Code Reviews| 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_api.h" | 8 #include "include/dart_api.h" |
| 9 | 9 |
| 10 #include "vm/ast.h" | 10 #include "vm/ast.h" |
| 11 #include "vm/dart.h" | 11 #include "vm/dart.h" |
| 12 #include "vm/globals.h" | 12 #include "vm/globals.h" |
| 13 #include "vm/heap.h" | 13 #include "vm/heap.h" |
| 14 #include "vm/isolate.h" | 14 #include "vm/isolate.h" |
| 15 #include "vm/longjump.h" | |
| 15 #include "vm/object.h" | 16 #include "vm/object.h" |
| 16 #include "vm/object_store.h" | 17 #include "vm/object_store.h" |
| 17 #include "vm/zone.h" | 18 #include "vm/zone.h" |
| 18 | 19 |
| 19 // The UNIT_TEST_CASE macro is used for tests that do not need any | 20 // The UNIT_TEST_CASE macro is used for tests that do not need any |
| 20 // default isolate or zone functionality. | 21 // default isolate or zone functionality. |
| 21 #define UNIT_TEST_CASE(name) \ | 22 #define UNIT_TEST_CASE(name) \ |
| 22 void Dart_Test##name(); \ | 23 void Dart_Test##name(); \ |
| 23 static const dart::TestCase kRegister##name(Dart_Test##name, #name); \ | 24 static const dart::TestCase kRegister##name(Dart_Test##name, #name); \ |
| 24 void Dart_Test##name() | 25 void Dart_Test##name() |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 virtual void Run(); | 166 virtual void Run(); |
| 166 | 167 |
| 167 private: | 168 private: |
| 168 RunEntry* const run_; | 169 RunEntry* const run_; |
| 169 }; | 170 }; |
| 170 | 171 |
| 171 | 172 |
| 172 class TestIsolateScope { | 173 class TestIsolateScope { |
| 173 public: | 174 public: |
| 174 TestIsolateScope() { | 175 TestIsolateScope() { |
| 175 isolate_ = Dart::CreateIsolate(NULL, NULL); | 176 isolate_ = Dart::CreateIsolate(); |
|
Ivan Posva
2011/11/04 17:24:42
Why not just use the Dart_CreateIsolate call here
siva
2011/11/04 22:01:57
Good point, simplifies stuff a lot.
On 2011/11/04
| |
| 177 LongJump jump; | |
| 178 isolate_->set_long_jump_base(&jump); | |
| 179 if (setjmp(*jump.Set()) == 0) { | |
| 180 Dart::InitializeIsolate(NULL, NULL); | |
| 181 isolate_->set_long_jump_base(NULL); | |
| 182 } else { | |
| 183 Dart::ShutdownIsolate(); | |
| 184 isolate_ = NULL; | |
| 185 EXPECT(false); // The test fails here. | |
| 186 } | |
| 176 Dart_EnterScope(); // Create a Dart API scope for unit tests. | 187 Dart_EnterScope(); // Create a Dart API scope for unit tests. |
| 177 } | 188 } |
| 178 ~TestIsolateScope() { | 189 ~TestIsolateScope() { |
| 179 Dart_ExitScope(); // Exit the Dart API scope created for unit tests. | 190 Dart_ExitScope(); // Exit the Dart API scope created for unit tests. |
| 180 ASSERT(isolate_ == Isolate::Current()); | 191 ASSERT(isolate_ == Isolate::Current()); |
| 181 Dart::ShutdownIsolate(); | 192 Dart::ShutdownIsolate(); |
|
Ivan Posva
2011/11/04 17:24:42
In the same way we should just call the Dart API e
siva
2011/11/04 22:01:57
Done.
| |
| 182 isolate_ = NULL; | 193 isolate_ = NULL; |
| 183 } | 194 } |
| 184 | 195 |
| 185 private: | 196 private: |
| 186 Isolate* isolate_; | 197 Isolate* isolate_; |
| 187 | 198 |
| 188 DISALLOW_COPY_AND_ASSIGN(TestIsolateScope); | 199 DISALLOW_COPY_AND_ASSIGN(TestIsolateScope); |
| 189 }; | 200 }; |
| 190 | 201 |
| 191 | 202 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 251 | 262 |
| 252 #define EXPECT_VALID(handle) \ | 263 #define EXPECT_VALID(handle) \ |
| 253 if (!Dart_IsValid((handle))) { \ | 264 if (!Dart_IsValid((handle))) { \ |
| 254 dart::Expect(__FILE__, __LINE__).Fail("invalid handle '%s':\n '%s'\n", \ | 265 dart::Expect(__FILE__, __LINE__).Fail("invalid handle '%s':\n '%s'\n", \ |
| 255 #handle, Dart_GetError(handle)); \ | 266 #handle, Dart_GetError(handle)); \ |
| 256 } | 267 } |
| 257 | 268 |
| 258 } // namespace dart | 269 } // namespace dart |
| 259 | 270 |
| 260 #endif // VM_UNIT_TEST_H_ | 271 #endif // VM_UNIT_TEST_H_ |
| OLD | NEW |