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

Unified Diff: runtime/vm/port_test.cc

Issue 9169063: Add support for native ports in the vm. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Patch Set Four Rules Created 8 years, 11 months 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/port_test.cc
===================================================================
--- runtime/vm/port_test.cc (revision 3603)
+++ runtime/vm/port_test.cc (working copy)
@@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
#include "platform/assert.h"
-#include "vm/message_queue.h"
+#include "vm/message.h"
#include "vm/os.h"
#include "vm/port.h"
#include "vm/unit_test.h"
@@ -29,22 +29,21 @@
};
-// Intercept the post message callback and just store a copy of the message.
-static int notify_count = 0;
-static void MyMessageNotifyCallback(Dart_Isolate dest_isolate) {
- notify_count++;
-}
+class TestMessageHandler : public MessageHandler {
+ public:
+ TestMessageHandler() : notify_count(0) {}
+ void MessageNotify(Message::Priority priority) {
+ notify_count++;
+ }
-static void InitPortMapTest() {
- Dart_SetMessageNotifyCallback(&MyMessageNotifyCallback);
- notify_count = 0;
-}
+ int notify_count;
+};
TEST_CASE(PortMap_CreateAndCloseOnePort) {
- InitPortMapTest();
- intptr_t port = PortMap::CreatePort();
+ TestMessageHandler handler;
+ intptr_t port = PortMap::CreatePort(&handler);
EXPECT_NE(0, port);
EXPECT(PortMapTestPeer::IsActivePort(port));
@@ -54,9 +53,9 @@
TEST_CASE(PortMap_CreateAndCloseTwoPorts) {
- InitPortMapTest();
- Dart_Port port1 = PortMap::CreatePort();
- Dart_Port port2 = PortMap::CreatePort();
+ TestMessageHandler handler;
+ Dart_Port port1 = PortMap::CreatePort(&handler);
+ Dart_Port port2 = PortMap::CreatePort(&handler);
EXPECT(PortMapTestPeer::IsActivePort(port1));
EXPECT(PortMapTestPeer::IsActivePort(port2));
@@ -74,23 +73,23 @@
TEST_CASE(PortMap_ClosePorts) {
- InitPortMapTest();
- Dart_Port port1 = PortMap::CreatePort();
- Dart_Port port2 = PortMap::CreatePort();
+ TestMessageHandler handler;
+ Dart_Port port1 = PortMap::CreatePort(&handler);
+ Dart_Port port2 = PortMap::CreatePort(&handler);
EXPECT(PortMapTestPeer::IsActivePort(port1));
EXPECT(PortMapTestPeer::IsActivePort(port2));
// Close all ports at once.
- PortMap::ClosePorts();
+ PortMap::ClosePorts(&handler);
EXPECT(!PortMapTestPeer::IsActivePort(port1));
EXPECT(!PortMapTestPeer::IsActivePort(port2));
}
TEST_CASE(PortMap_CreateManyPorts) {
- InitPortMapTest();
+ TestMessageHandler handler;
for (int i = 0; i < 32; i++) {
- Dart_Port port = PortMap::CreatePort();
+ Dart_Port port = PortMap::CreatePort(&handler);
EXPECT(PortMapTestPeer::IsActivePort(port));
PortMap::ClosePort(port);
EXPECT(!PortMapTestPeer::IsActivePort(port));
@@ -99,8 +98,8 @@
TEST_CASE(PortMap_SetLive) {
- InitPortMapTest();
- intptr_t port = PortMap::CreatePort();
+ TestMessageHandler handler;
+ intptr_t port = PortMap::CreatePort(&handler);
EXPECT_NE(0, port);
EXPECT(PortMapTestPeer::IsActivePort(port));
EXPECT(!PortMapTestPeer::IsLivePort(port));
@@ -116,26 +115,24 @@
TEST_CASE(PortMap_PostMessage) {
- InitPortMapTest();
- Dart_Port port = PortMap::CreatePort();
+ TestMessageHandler handler;
+ Dart_Port port = PortMap::CreatePort(&handler);
+ EXPECT_STREQ(0, handler.notify_count);
siva 2012/01/28 00:21:05 EXPECT(0, handler.notify_count)? They are not stri
turnidge 2012/01/31 20:04:31 Woops.
+
EXPECT(PortMap::PostMessage(new Message(
port, 0, reinterpret_cast<uint8_t*>(strdup("msg")),
Message::kNormalPriority)));
// Check that the message notify callback was called.
- EXPECT_EQ(1, notify_count);
- PortMap::ClosePorts();
+ EXPECT_EQ(1, handler.notify_count);
+ PortMap::ClosePorts(&handler);
}
TEST_CASE(PortMap_PostMessageInvalidPort) {
- InitPortMapTest();
EXPECT(!PortMap::PostMessage(new Message(
0, 0, reinterpret_cast<uint8_t*>(strdup("msg")),
Message::kNormalPriority)));
-
- // Check that the message notifycallback was not called.
- EXPECT_STREQ(0, notify_count);
}
@@ -157,7 +154,7 @@
static Message* NextMessage() {
Isolate* isolate = Isolate::Current();
- Message* result = isolate->message_queue()->Dequeue(0);
+ Message* result = isolate->message_handler()->queue()->Dequeue(0);
return result;
}
@@ -169,7 +166,7 @@
Dart::CreateIsolate(NULL);
siva 2012/01/28 00:21:05 Isolate* isolate = Dart::CreateIsolate(NULL);
turnidge 2012/01/31 20:04:31 Done.
intptr_t remote = parameter;
- intptr_t local = PortMap::CreatePort();
+ intptr_t local = PortMap::CreatePort(Isolate::Current()->message_handler());
siva 2012/01/28 00:21:05 isolate->message_handler();
turnidge 2012/01/31 20:04:31 Done.
PortMap::PostMessage(new Message(
remote, 0, AllocIntData(local), Message::kNormalPriority));
@@ -194,7 +191,7 @@
TEST_CASE(ThreadedPort) {
- intptr_t local = PortMap::CreatePort();
+ intptr_t local = PortMap::CreatePort(Isolate::Current()->message_handler());
Thread* thr = new Thread(ThreadedPort_start, local);
EXPECT(thr != NULL);
« runtime/vm/port.cc ('K') | « runtime/vm/port.cc ('k') | runtime/vm/vm_sources.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698