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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: runtime/vm/dart_api_impl_test.cc
diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc
index 1499f37fc348dddb403295350128816bc2e1d913..7c5051e303151c0d3d43ce3c7a195d59bea26449 100644
--- a/runtime/vm/dart_api_impl_test.cc
+++ b/runtime/vm/dart_api_impl_test.cc
@@ -6992,6 +6992,31 @@ void NewNativePort_send321(Dart_Port dest_port_id,
}
+void NewNativePort_sendInteger123(Dart_Port dest_port_id,
+ Dart_CObject *message) {
+ // Gets a send port message.
+ EXPECT_NOTNULL(message);
+ EXPECT_EQ(Dart_CObject_kArray, message->type);
+ EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type);
+
+ // Post integer value.
+ Dart_PostInteger(
+ message->value.as_array.values[0]->value.as_send_port.id, 123);
+}
+
+
+void NewNativePort_sendInteger321(Dart_Port dest_port_id,
+ Dart_CObject* message) {
+ // Gets a null message.
+ EXPECT_NOTNULL(message);
+ EXPECT_EQ(Dart_CObject_kSendPort, message->value.as_array.values[0]->type);
+
+ // Post integer value.
+ Dart_PostInteger(
+ message->value.as_array.values[0]->value.as_send_port.id, 321);
+}
+
+
TEST_CASE(IllegalNewSendPort) {
Dart_Handle error = Dart_NewSendPort(ILLEGAL_PORT);
EXPECT(Dart_IsError(error));
@@ -7067,6 +7092,59 @@ UNIT_TEST_CASE(NewNativePort) {
}
+TEST_CASE(NewNativePortPostInteger) {
+ const char* kScriptChars =
+ "import 'dart:isolate';\n"
+ "void callPort(SendPort port) {\n"
+ " var receivePort = new RawReceivePort();\n"
+ " var replyPort = receivePort.sendPort;\n"
+ " port.send([replyPort]);\n"
+ " receivePort.handler = (message) {\n"
+ " receivePort.close();\n"
+ " throw new Exception(message);\n"
+ " };\n"
+ "}\n";
+ Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
+ Dart_EnterScope();
+
+ Dart_Port port_id1 =
+ Dart_NewNativePort("Port123", NewNativePort_sendInteger123, true);
+ Dart_Port port_id2 =
+ Dart_NewNativePort("Port321", NewNativePort_sendInteger321, true);
+
+ Dart_Handle send_port1 = Dart_NewSendPort(port_id1);
+ EXPECT_VALID(send_port1);
+ Dart_Handle send_port2 = Dart_NewSendPort(port_id2);
+ EXPECT_VALID(send_port2);
+
+ // Test first port.
+ Dart_Handle dart_args[1];
+ dart_args[0] = send_port1;
+ Dart_Handle result =
+ Dart_Invoke(lib, NewString("callPort"), 1, dart_args);
+ EXPECT_VALID(result);
+ result = Dart_RunLoop();
+ EXPECT(Dart_IsError(result));
+ EXPECT(Dart_ErrorHasException(result));
+ EXPECT_SUBSTRING("Exception: 123\n", Dart_GetError(result));
+
+ // result second port.
+ dart_args[0] = send_port2;
+ result = Dart_Invoke(lib, NewString("callPort"), 1, dart_args);
+ EXPECT_VALID(result);
+ result = Dart_RunLoop();
+ EXPECT(Dart_IsError(result));
+ EXPECT(Dart_ErrorHasException(result));
+ EXPECT_SUBSTRING("Exception: 321\n", Dart_GetError(result));
+
+ Dart_ExitScope();
+
+ // Delete the native ports.
+ EXPECT(Dart_CloseNativePort(port_id1));
+ EXPECT(Dart_CloseNativePort(port_id2));
+}
+
+
static Dart_Isolate RunLoopTestCallback(const char* script_name,
const char* main,
const char* package_root,

Powered by Google App Engine
This is Rietveld 408576698