Index: runtime/vm/service_test.cc |
=================================================================== |
--- runtime/vm/service_test.cc (revision 34138) |
+++ runtime/vm/service_test.cc (working copy) |
@@ -744,6 +744,95 @@ |
} |
+TEST_CASE(Service_Types) { |
+ const char* kScript = |
+ "var port;\n" // Set to our mock port by C++. |
+ "\n" |
+ "class A<T> { }\n" |
+ "\n" |
+ "main() {\n" |
+ " new A<A<bool>>();\n" |
+ "}"; |
+ |
+ Isolate* isolate = Isolate::Current(); |
+ Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); |
+ EXPECT_VALID(h_lib); |
+ Library& lib = Library::Handle(); |
+ lib ^= Api::UnwrapHandle(h_lib); |
+ EXPECT(!lib.IsNull()); |
+ Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); |
+ EXPECT_VALID(result); |
+ const Class& class_a = Class::Handle(GetClass(lib, "A")); |
+ EXPECT(!class_a.IsNull()); |
+ intptr_t cid = class_a.id(); |
+ |
+ // Build a mock message handler and wrap it in a dart port. |
+ ServiceTestMessageHandler handler; |
+ Dart_Port port_id = PortMap::CreatePort(&handler); |
+ Dart_Handle port = |
+ Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id)); |
+ EXPECT_VALID(port); |
+ EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); |
+ |
+ Instance& service_msg = Instance::Handle(); |
+ |
+ // Request the class A over the service. |
+ service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "'], [], []]", cid); |
+ Service::HandleIsolateMessage(isolate, service_msg); |
+ handler.HandleNextMessage(); |
+ EXPECT_SUBSTRING("\"type\":\"Class\"", handler.msg()); |
+ ExpectSubstringF(handler.msg(), |
+ "\"id\":\"classes\\/%" Pd "\",\"name\":\"A\",", cid); |
+ |
+ // Request canonical type 0 from class A. |
+ service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'types', '0']," |
+ "[], []]", cid); |
+ Service::HandleIsolateMessage(isolate, service_msg); |
+ handler.HandleNextMessage(); |
+ EXPECT_SUBSTRING("\"type\":\"Type\"", handler.msg()); |
+ ExpectSubstringF(handler.msg(), |
+ "\"id\":\"classes\\/%" Pd "\\/types\\/0\"," |
+ "\"name\":\"A<bool>\",", cid); |
+ |
+ // Request canonical type 1 from class A. |
+ service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'types', '1']," |
+ "[], []]", cid); |
+ Service::HandleIsolateMessage(isolate, service_msg); |
+ handler.HandleNextMessage(); |
+ EXPECT_SUBSTRING("\"type\":\"Type\"", handler.msg()); |
+ ExpectSubstringF(handler.msg(), |
+ "\"id\":\"classes\\/%" Pd "\\/types\\/1\"," |
+ "\"name\":\"A<A<bool>>\",", cid); |
+ |
+ // Request for non-existent canonical type from class A. |
+ service_msg = EvalF(h_lib, "[port, ['classes', '%" Pd "', 'types', '42']," |
+ "[], []]", cid); |
+ Service::HandleIsolateMessage(isolate, service_msg); |
+ handler.HandleNextMessage(); |
+ ExpectSubstringF(handler.msg(), |
+ "{\"type\":\"Error\",\"id\":\"\"," |
+ "\"message\":\"Canonical type 42 not found\"" |
+ ",\"request\":" |
+ "{\"arguments\":[\"classes\",\"%" Pd "\",\"types\",\"42\"]," |
+ "\"option_keys\":[],\"option_values\":[]}}", cid); |
+ |
+ // Request canonical type arguments. Expect <A<bool>> to be listed. |
+ service_msg = EvalF(h_lib, "[port, ['typearguments']," |
+ "[], []]"); |
+ Service::HandleIsolateMessage(isolate, service_msg); |
+ handler.HandleNextMessage(); |
+ EXPECT_SUBSTRING("\"type\":\"TypeArgumentsList\"", handler.msg()); |
+ ExpectSubstringF(handler.msg(), "\"name\":\"<A<bool>>\","); |
+ |
+ // Request canonical type arguments with instantiations. |
+ service_msg = EvalF(h_lib, "[port, ['typearguments', 'withinstantiations']," |
+ "[], []]"); |
+ Service::HandleIsolateMessage(isolate, service_msg); |
+ handler.HandleNextMessage(); |
+ EXPECT_SUBSTRING("\"type\":\"TypeArgumentsList\"", handler.msg()); |
+} |
+ |
+ |
TEST_CASE(Service_Code) { |
const char* kScript = |
"var port;\n" // Set to our mock port by C++. |