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" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 static void CodeGenTestRun##name(const Function& function); \ | 71 static void CodeGenTestRun##name(const Function& function); \ |
72 TEST_CASE(name) { \ | 72 TEST_CASE(name) { \ |
73 CodeGenTest __test__(""#name); \ | 73 CodeGenTest __test__(""#name); \ |
74 CodeGenTestGenerate##name(&__test__); \ | 74 CodeGenTestGenerate##name(&__test__); \ |
75 __test__.Compile(); \ | 75 __test__.Compile(); \ |
76 CodeGenTestRun##name(__test__.function()); \ | 76 CodeGenTestRun##name(__test__.function()); \ |
77 } \ | 77 } \ |
78 static void CodeGenTestRun##name(const Function& function) { \ | 78 static void CodeGenTestRun##name(const Function& function) { \ |
79 GrowableArray<const Object*> arguments; \ | 79 GrowableArray<const Object*> arguments; \ |
80 const Array& kNoArgumentNames = Array::Handle(); \ | 80 const Array& kNoArgumentNames = Array::Handle(); \ |
81 Object& result = Object::Handle(); \ | 81 Instance& result = Instance::Handle(); \ |
82 result = DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); \ | 82 result = DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); \ |
83 EXPECT(!result.IsError()); \ | 83 EXPECT(result.Equals(Instance::Handle(expected))); \ |
84 Instance& actual = Instance::Handle(); \ | |
85 actual ^= result.raw(); \ | |
86 EXPECT(actual.Equals(Instance::Handle(expected))); \ | |
87 } | 84 } |
88 | 85 |
89 | 86 |
90 // Pass the name of test, and use the generated function to call it | 87 // Pass the name of test, and use the generated function to call it |
91 // and evaluate its result. | 88 // and evaluate its result. |
92 #define CODEGEN_TEST_RAW_RUN(name, function) \ | 89 #define CODEGEN_TEST_RAW_RUN(name, function) \ |
93 static void CodeGenTestRun##name(const Function& function); \ | 90 static void CodeGenTestRun##name(const Function& function); \ |
94 TEST_CASE(name) { \ | 91 TEST_CASE(name) { \ |
95 CodeGenTest __test__(""#name); \ | 92 CodeGenTest __test__(""#name); \ |
96 CodeGenTestGenerate##name(&__test__); \ | 93 CodeGenTestGenerate##name(&__test__); \ |
(...skipping 14 matching lines...) Expand all Loading... |
111 __test2__.Compile(); \ | 108 __test2__.Compile(); \ |
112 /* Generate code for name1, providing function2 */ \ | 109 /* Generate code for name1, providing function2 */ \ |
113 CodeGenTest __test1__(""#name1); \ | 110 CodeGenTest __test1__(""#name1); \ |
114 CodeGenTestGenerate##name1(__test2__.function(), &__test1__); \ | 111 CodeGenTestGenerate##name1(__test2__.function(), &__test1__); \ |
115 __test1__.Compile(); \ | 112 __test1__.Compile(); \ |
116 CodeGenTestRun##name1(__test1__.function()); \ | 113 CodeGenTestRun##name1(__test1__.function()); \ |
117 } \ | 114 } \ |
118 static void CodeGenTestRun##name1(const Function& function) { \ | 115 static void CodeGenTestRun##name1(const Function& function) { \ |
119 GrowableArray<const Object*> arguments; \ | 116 GrowableArray<const Object*> arguments; \ |
120 const Array& kNoArgumentNames = Array::Handle(); \ | 117 const Array& kNoArgumentNames = Array::Handle(); \ |
121 Object& result = Object::Handle(); \ | 118 Instance& result = Instance::Handle(); \ |
122 result = DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); \ | 119 result = DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); \ |
123 EXPECT(!result.IsError()); \ | 120 EXPECT(result.Equals(Instance::Handle(expected))); \ |
124 Instance& actual = Instance::Handle(); \ | |
125 actual ^= result.raw(); \ | |
126 EXPECT(actual.Equals(Instance::Handle(expected))); \ | |
127 } | 121 } |
128 | 122 |
129 | 123 |
130 namespace dart { | 124 namespace dart { |
131 | 125 |
132 // Forward declarations. | 126 // Forward declarations. |
133 class Assembler; | 127 class Assembler; |
134 class CodeGenerator; | 128 class CodeGenerator; |
135 class VirtualMemory; | 129 class VirtualMemory; |
136 | 130 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 273 |
280 #define EXPECT_VALID(handle) \ | 274 #define EXPECT_VALID(handle) \ |
281 if (Dart_IsError((handle))) { \ | 275 if (Dart_IsError((handle))) { \ |
282 dart::Expect(__FILE__, __LINE__).Fail("invalid handle '%s':\n '%s'\n", \ | 276 dart::Expect(__FILE__, __LINE__).Fail("invalid handle '%s':\n '%s'\n", \ |
283 #handle, Dart_GetError(handle)); \ | 277 #handle, Dart_GetError(handle)); \ |
284 } | 278 } |
285 | 279 |
286 } // namespace dart | 280 } // namespace dart |
287 | 281 |
288 #endif // VM_UNIT_TEST_H_ | 282 #endif // VM_UNIT_TEST_H_ |
OLD | NEW |