Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1394)

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 1499853004: Adds a special case for sending an int over a port with the native API. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 TEST_CASE(NewNativePortPostInteger) {
7096 const char* kScriptChars =
7097 "import 'dart:isolate';\n"
7098 "void callPort(SendPort port) {\n"
7099 " var receivePort = new RawReceivePort();\n"
7100 " var replyPort = receivePort.sendPort;\n"
7101 " port.send([replyPort]);\n"
7102 " receivePort.handler = (message) {\n"
7103 " receivePort.close();\n"
7104 " throw new Exception(message);\n"
7105 " };\n"
7106 "}\n";
7107 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
7108 Dart_EnterScope();
7109
7110 Dart_Port port_id1 =
7111 Dart_NewNativePort("Port123", NewNativePort_sendInteger123, true);
7112 Dart_Port port_id2 =
7113 Dart_NewNativePort("Port321", NewNativePort_sendInteger321, true);
7114
7115 Dart_Handle send_port1 = Dart_NewSendPort(port_id1);
7116 EXPECT_VALID(send_port1);
7117 Dart_Handle send_port2 = Dart_NewSendPort(port_id2);
7118 EXPECT_VALID(send_port2);
7119
7120 // Test first port.
7121 Dart_Handle dart_args[1];
7122 dart_args[0] = send_port1;
7123 Dart_Handle result =
7124 Dart_Invoke(lib, NewString("callPort"), 1, dart_args);
7125 EXPECT_VALID(result);
7126 result = Dart_RunLoop();
7127 EXPECT(Dart_IsError(result));
7128 EXPECT(Dart_ErrorHasException(result));
7129 EXPECT_SUBSTRING("Exception: 123\n", Dart_GetError(result));
7130
7131 // result second port.
7132 dart_args[0] = send_port2;
7133 result = Dart_Invoke(lib, NewString("callPort"), 1, dart_args);
7134 EXPECT_VALID(result);
7135 result = Dart_RunLoop();
7136 EXPECT(Dart_IsError(result));
7137 EXPECT(Dart_ErrorHasException(result));
7138 EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result));
7139
7140 Dart_ExitScope();
7141
7142 // Delete the native ports.
7143 EXPECT(Dart_CloseNativePort(port_id1));
7144 EXPECT(Dart_CloseNativePort(port_id2));
7145 }
7146
7147
7070 static Dart_Isolate RunLoopTestCallback(const char* script_name, 7148 static Dart_Isolate RunLoopTestCallback(const char* script_name,
7071 const char* main, 7149 const char* main,
7072 const char* package_root, 7150 const char* package_root,
7073 const char** package_map, 7151 const char** package_map,
7074 Dart_IsolateFlags* flags, 7152 Dart_IsolateFlags* flags,
7075 void* data, 7153 void* data,
7076 char** error) { 7154 char** error) {
7077 const char* kScriptChars = 7155 const char* kScriptChars =
7078 "import 'builtin';\n" 7156 "import 'builtin';\n"
7079 "import 'dart:isolate';\n" 7157 "import 'dart:isolate';\n"
(...skipping 2291 matching lines...) Expand 10 before | Expand all | Expand 10 after
9371 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer); 9449 EXPECT_SUBSTRING("\"cat\":\"Compiler\"", buffer);
9372 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer); 9450 EXPECT_SUBSTRING("\"name\":\"CompileFunction\"", buffer);
9373 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer); 9451 EXPECT_SUBSTRING("\"function\":\"::_main\"", buffer);
9374 9452
9375 // Heartbeat test for new events. 9453 // Heartbeat test for new events.
9376 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer); 9454 EXPECT_SUBSTRING("\"name\":\"TestVMDuration2\"", buffer);
9377 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer); 9455 EXPECT_SUBSTRING("\"function\":\"::_bar\"", buffer);
9378 } 9456 }
9379 9457
9380 } // namespace dart 9458 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698