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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // Pass the name of test and the expected results as RawObject. | 74 // Pass the name of test and the expected results as RawObject. |
75 #define CODEGEN_TEST_RUN(name, expected) \ | 75 #define CODEGEN_TEST_RUN(name, expected) \ |
76 static void CodeGenTestRun##name(const Function& function); \ | 76 static void CodeGenTestRun##name(const Function& function); \ |
77 TEST_CASE(name) { \ | 77 TEST_CASE(name) { \ |
78 CodeGenTest __test__(""#name); \ | 78 CodeGenTest __test__(""#name); \ |
79 CodeGenTestGenerate##name(&__test__); \ | 79 CodeGenTestGenerate##name(&__test__); \ |
80 __test__.Compile(); \ | 80 __test__.Compile(); \ |
81 CodeGenTestRun##name(__test__.function()); \ | 81 CodeGenTestRun##name(__test__.function()); \ |
82 } \ | 82 } \ |
83 static void CodeGenTestRun##name(const Function& function) { \ | 83 static void CodeGenTestRun##name(const Function& function) { \ |
84 GrowableArray<const Object*> arguments; \ | 84 const Array& args = Array::Handle(Object::empty_array()); \ |
85 const Array& kNoArgumentNames = Array::Handle(); \ | |
86 Object& result = Object::Handle(); \ | 85 Object& result = Object::Handle(); \ |
87 result = DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); \ | 86 result = DartEntry::InvokeStatic(function, args); \ |
88 EXPECT(!result.IsError()); \ | 87 EXPECT(!result.IsError()); \ |
89 Instance& actual = Instance::Handle(); \ | 88 Instance& actual = Instance::Handle(); \ |
90 actual ^= result.raw(); \ | 89 actual ^= result.raw(); \ |
91 EXPECT(actual.Equals(Instance::Handle(expected))); \ | 90 EXPECT(actual.Equals(Instance::Handle(expected))); \ |
92 } | 91 } |
93 | 92 |
94 | 93 |
95 // Pass the name of test, and use the generated function to call it | 94 // Pass the name of test, and use the generated function to call it |
96 // and evaluate its result. | 95 // and evaluate its result. |
97 #define CODEGEN_TEST_RAW_RUN(name, function) \ | 96 #define CODEGEN_TEST_RAW_RUN(name, function) \ |
(...skipping 16 matching lines...) Expand all Loading... |
114 CodeGenTest __test2__(""#name2); \ | 113 CodeGenTest __test2__(""#name2); \ |
115 CodeGenTestGenerate##name2(&__test2__); \ | 114 CodeGenTestGenerate##name2(&__test2__); \ |
116 __test2__.Compile(); \ | 115 __test2__.Compile(); \ |
117 /* Generate code for name1, providing function2 */ \ | 116 /* Generate code for name1, providing function2 */ \ |
118 CodeGenTest __test1__(""#name1); \ | 117 CodeGenTest __test1__(""#name1); \ |
119 CodeGenTestGenerate##name1(__test2__.function(), &__test1__); \ | 118 CodeGenTestGenerate##name1(__test2__.function(), &__test1__); \ |
120 __test1__.Compile(); \ | 119 __test1__.Compile(); \ |
121 CodeGenTestRun##name1(__test1__.function()); \ | 120 CodeGenTestRun##name1(__test1__.function()); \ |
122 } \ | 121 } \ |
123 static void CodeGenTestRun##name1(const Function& function) { \ | 122 static void CodeGenTestRun##name1(const Function& function) { \ |
124 GrowableArray<const Object*> arguments; \ | 123 const Array& args = Array::Handle(Object::empty_array()); \ |
125 const Array& kNoArgumentNames = Array::Handle(); \ | |
126 Object& result = Object::Handle(); \ | 124 Object& result = Object::Handle(); \ |
127 result = DartEntry::InvokeStatic(function, arguments, kNoArgumentNames); \ | 125 result = DartEntry::InvokeStatic(function, args); \ |
128 EXPECT(!result.IsError()); \ | 126 EXPECT(!result.IsError()); \ |
129 Instance& actual = Instance::Handle(); \ | 127 Instance& actual = Instance::Handle(); \ |
130 actual ^= result.raw(); \ | 128 actual ^= result.raw(); \ |
131 EXPECT(actual.Equals(Instance::Handle(expected))); \ | 129 EXPECT(actual.Equals(Instance::Handle(expected))); \ |
132 } | 130 } |
133 | 131 |
134 | 132 |
135 inline Dart_Handle NewString(const char* str) { | 133 inline Dart_Handle NewString(const char* str) { |
136 return Dart_NewStringFromCString(str); | 134 return Dart_NewStringFromCString(str); |
137 } | 135 } |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 } else { \ | 307 } else { \ |
310 dart::Expect(__FILE__, __LINE__).Fail( \ | 308 dart::Expect(__FILE__, __LINE__).Fail( \ |
311 "expected '%s' to be an error handle but found a valid handle.\n", \ | 309 "expected '%s' to be an error handle but found a valid handle.\n", \ |
312 #handle); \ | 310 #handle); \ |
313 } \ | 311 } \ |
314 } while (0) | 312 } while (0) |
315 | 313 |
316 } // namespace dart | 314 } // namespace dart |
317 | 315 |
318 #endif // VM_UNIT_TEST_H_ | 316 #endif // VM_UNIT_TEST_H_ |
OLD | NEW |