OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include "bin/builtin.h" | 5 #include "bin/builtin.h" |
6 #include "include/dart_api.h" | 6 #include "include/dart_api.h" |
7 #include "include/dart_mirrors_api.h" | 7 #include "include/dart_mirrors_api.h" |
8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
9 #include "include/dart_tools_api.h" | 9 #include "include/dart_tools_api.h" |
10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
(...skipping 6974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6985 // Post integer value. | 6985 // Post integer value. |
6986 Dart_CObject* response = | 6986 Dart_CObject* response = |
6987 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject))); | 6987 reinterpret_cast<Dart_CObject*>(Dart_ScopeAllocate(sizeof(Dart_CObject))); |
6988 response->type = Dart_CObject_kInt32; | 6988 response->type = Dart_CObject_kInt32; |
6989 response->value.as_int32 = 321; | 6989 response->value.as_int32 = 321; |
6990 Dart_PostCObject( | 6990 Dart_PostCObject( |
6991 message->value.as_array.values[0]->value.as_send_port.id, response); | 6991 message->value.as_array.values[0]->value.as_send_port.id, response); |
6992 } | 6992 } |
6993 | 6993 |
6994 | 6994 |
| 6995 void NewNativePort_sendInteger123(Dart_Port dest_port_id, |
| 6996 Dart_CObject *message) { |
| 6997 // Gets a send port message. |
| 6998 EXPECT_NOTNULL(message); |
| 6999 EXPECT_EQ(Dart_CObject_kArray, message->type); |
| 7000 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); |
| 7001 |
| 7002 // Post integer value. |
| 7003 Dart_PostInteger( |
| 7004 message->value.as_array.values[0]->value.as_send_port.id, 123); |
| 7005 } |
| 7006 |
| 7007 |
| 7008 void NewNativePort_sendInteger321(Dart_Port dest_port_id, |
| 7009 Dart_CObject* message) { |
| 7010 // Gets a null message. |
| 7011 EXPECT_NOTNULL(message); |
| 7012 EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type); |
| 7013 |
| 7014 // Post integer value. |
| 7015 Dart_PostInteger( |
| 7016 message->value.as_array.values[0]->value.as_send_port.id, 321); |
| 7017 } |
| 7018 |
| 7019 |
6995 TEST_CASE(IllegalNewSendPort) { | 7020 TEST_CASE(IllegalNewSendPort) { |
6996 Dart_Handle error = Dart_NewSendPort(ILLEGAL_PORT); | 7021 Dart_Handle error = Dart_NewSendPort(ILLEGAL_PORT); |
6997 EXPECT(Dart_IsError(error)); | 7022 EXPECT(Dart_IsError(error)); |
6998 EXPECT(Dart_IsApiError(error)); | 7023 EXPECT(Dart_IsApiError(error)); |
6999 } | 7024 } |
7000 | 7025 |
7001 | 7026 |
7002 TEST_CASE(IllegalPost) { | 7027 TEST_CASE(IllegalPost) { |
7003 Dart_Handle message = Dart_True(); | 7028 Dart_Handle message = Dart_True(); |
7004 bool success = Dart_Post(ILLEGAL_PORT, message); | 7029 bool success = Dart_Post(ILLEGAL_PORT, message); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7060 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result)); | 7085 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result)); |
7061 | 7086 |
7062 Dart_ExitScope(); | 7087 Dart_ExitScope(); |
7063 | 7088 |
7064 // Delete the native ports. | 7089 // Delete the native ports. |
7065 EXPECT(Dart_CloseNativePort(port_id1)); | 7090 EXPECT(Dart_CloseNativePort(port_id1)); |
7066 EXPECT(Dart_CloseNativePort(port_id2)); | 7091 EXPECT(Dart_CloseNativePort(port_id2)); |
7067 } | 7092 } |
7068 | 7093 |
7069 | 7094 |
| 7095 UNIT_TEST_CASE(NewNativePortPostInteger) { |
| 7096 // Create a port with a bogus handler. |
| 7097 Dart_Port error_port = Dart_NewNativePort("Foo", NULL, true); |
| 7098 EXPECT_EQ(ILLEGAL_PORT, error_port); |
| 7099 |
| 7100 // Create the port w/o a current isolate, just to make sure that works. |
| 7101 Dart_Port port_id1 = |
| 7102 Dart_NewNativePort("Port123", NewNativePort_sendInteger123, true); |
| 7103 |
| 7104 TestIsolateScope __test_isolate__; |
| 7105 const char* kScriptChars = |
| 7106 "import 'dart:isolate';\n" |
| 7107 "void callPort(SendPort port) {\n" |
| 7108 " var receivePort = new RawReceivePort();\n" |
| 7109 " var replyPort = receivePort.sendPort;\n" |
| 7110 " port.send([replyPort]);\n" |
| 7111 " receivePort.handler = (message) {\n" |
| 7112 " receivePort.close();\n" |
| 7113 " throw new Exception(message);\n" |
| 7114 " };\n" |
| 7115 "}\n"; |
| 7116 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 7117 Dart_EnterScope(); |
| 7118 |
| 7119 // Create a port w/ a current isolate, to make sure that works too. |
| 7120 Dart_Port port_id2 = |
| 7121 Dart_NewNativePort("Port321", NewNativePort_sendInteger321, true); |
| 7122 |
| 7123 Dart_Handle send_port1 = Dart_NewSendPort(port_id1); |
| 7124 EXPECT_VALID(send_port1); |
| 7125 Dart_Handle send_port2 = Dart_NewSendPort(port_id2); |
| 7126 EXPECT_VALID(send_port2); |
| 7127 |
| 7128 // Test first port. |
| 7129 Dart_Handle dart_args[1]; |
| 7130 dart_args[0] = send_port1; |
| 7131 Dart_Handle result = |
| 7132 Dart_Invoke(lib, NewString("callPort"), 1, dart_args); |
| 7133 EXPECT_VALID(result); |
| 7134 result = Dart_RunLoop(); |
| 7135 EXPECT(Dart_IsError(result)); |
| 7136 EXPECT(Dart_ErrorHasException(result)); |
| 7137 EXPECT_SUBSTRING("Exception: 123\n", Dart_GetError(result)); |
| 7138 |
| 7139 // result second port. |
| 7140 dart_args[0] = send_port2; |
| 7141 result = Dart_Invoke(lib, NewString("callPort"), 1, dart_args); |
| 7142 EXPECT_VALID(result); |
| 7143 result = Dart_RunLoop(); |
| 7144 EXPECT(Dart_IsError(result)); |
| 7145 EXPECT(Dart_ErrorHasException(result)); |
| 7146 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result)); |
| 7147 |
| 7148 Dart_ExitScope(); |
| 7149 |
| 7150 // Delete the native ports. |
| 7151 EXPECT(Dart_CloseNativePort(port_id1)); |
| 7152 EXPECT(Dart_CloseNativePort(port_id2)); |
| 7153 } |
| 7154 |
| 7155 |
7070 static Dart_Isolate RunLoopTestCallback(const char* script_name, | 7156 static Dart_Isolate RunLoopTestCallback(const char* script_name, |
7071 const char* main, | 7157 const char* main, |
7072 const char* package_root, | 7158 const char* package_root, |
7073 const char** package_map, | 7159 const char** package_map, |
7074 Dart_IsolateFlags* flags, | 7160 Dart_IsolateFlags* flags, |
7075 void* data, | 7161 void* data, |
7076 char** error) { | 7162 char** error) { |
7077 const char* kScriptChars = | 7163 const char* kScriptChars = |
7078 "import 'builtin';\n" | 7164 "import 'builtin';\n" |
7079 "import 'dart:isolate';\n" | 7165 "import 'dart:isolate';\n" |
(...skipping 2291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9371 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); | 9457 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); |
9372 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); | 9458 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); |
9373 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); | 9459 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); |
9374 | 9460 |
9375 // Heartbeat test for new events. | 9461 // Heartbeat test for new events. |
9376 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); | 9462 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); |
9377 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); | 9463 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); |
9378 } | 9464 } |
9379 | 9465 |
9380 } // namespace dart | 9466 } // namespace dart |
OLD | NEW |