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

Unified Diff: runtime/vm/port_test.cc

Issue 8588040: Add a mid-sized integration test for the Dart Embedding Api which (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 1 month 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
« no previous file with comments | « runtime/vm/port.cc ('k') | runtime/vm/unit_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/port_test.cc
===================================================================
--- runtime/vm/port_test.cc (revision 1904)
+++ runtime/vm/port_test.cc (working copy)
@@ -10,7 +10,25 @@
namespace dart {
+// Provides private access to PortMap for testing.
+class PortMapTestPeer {
+ public:
+ static bool IsActivePort(Dart_Port port) {
+ MutexLocker ml(PortMap::mutex_);
+ return (PortMap::FindPort(port) >= 0);
+ }
+ static bool IsLivePort(Dart_Port port) {
+ MutexLocker ml(PortMap::mutex_);
+ intptr_t index = PortMap::FindPort(port);
+ if (index < 0) {
+ return false;
+ }
+ return PortMap::map_[index].live;
+ }
+};
+
+
// Intercept the post message callback and just store a copy of the message.
static const int kMaxSavedMsg = 80;
static char saved_msg[kMaxSavedMsg];
@@ -45,10 +63,10 @@
InitPortMapTest();
intptr_t port = PortMap::CreatePort();
EXPECT_NE(0, port);
- EXPECT(PortMap::IsActivePort(port));
+ EXPECT(PortMapTestPeer::IsActivePort(port));
PortMap::ClosePort(port);
- EXPECT(!PortMap::IsActivePort(port));
+ EXPECT(!PortMapTestPeer::IsActivePort(port));
// Embedder was notified of port closure.
EXPECT_EQ(port, saved_port);
@@ -59,20 +77,20 @@
InitPortMapTest();
Dart_Port port1 = PortMap::CreatePort();
Dart_Port port2 = PortMap::CreatePort();
- EXPECT(PortMap::IsActivePort(port1));
- EXPECT(PortMap::IsActivePort(port2));
+ EXPECT(PortMapTestPeer::IsActivePort(port1));
+ EXPECT(PortMapTestPeer::IsActivePort(port2));
// Uniqueness.
EXPECT_NE(port1, port2);
PortMap::ClosePort(port1);
- EXPECT(!PortMap::IsActivePort(port1));
- EXPECT(PortMap::IsActivePort(port2));
+ EXPECT(!PortMapTestPeer::IsActivePort(port1));
+ EXPECT(PortMapTestPeer::IsActivePort(port2));
EXPECT_EQ(port1, saved_port);
PortMap::ClosePort(port2);
- EXPECT(!PortMap::IsActivePort(port1));
- EXPECT(!PortMap::IsActivePort(port2));
+ EXPECT(!PortMapTestPeer::IsActivePort(port1));
+ EXPECT(!PortMapTestPeer::IsActivePort(port2));
EXPECT_EQ(port2, saved_port);
}
@@ -81,13 +99,13 @@
InitPortMapTest();
Dart_Port port1 = PortMap::CreatePort();
Dart_Port port2 = PortMap::CreatePort();
- EXPECT(PortMap::IsActivePort(port1));
- EXPECT(PortMap::IsActivePort(port2));
+ EXPECT(PortMapTestPeer::IsActivePort(port1));
+ EXPECT(PortMapTestPeer::IsActivePort(port2));
// Close all ports at once.
PortMap::ClosePorts();
- EXPECT(!PortMap::IsActivePort(port1));
- EXPECT(!PortMap::IsActivePort(port2));
+ EXPECT(!PortMapTestPeer::IsActivePort(port1));
+ EXPECT(!PortMapTestPeer::IsActivePort(port2));
// Embedder is notified to close all ports as well.
EXPECT_EQ(kCloseAllPorts, saved_port);
@@ -98,13 +116,33 @@
InitPortMapTest();
for (int i = 0; i < 32; i++) {
Dart_Port port = PortMap::CreatePort();
- EXPECT(PortMap::IsActivePort(port));
+ EXPECT(PortMapTestPeer::IsActivePort(port));
PortMap::ClosePort(port);
- EXPECT(!PortMap::IsActivePort(port));
+ EXPECT(!PortMapTestPeer::IsActivePort(port));
}
}
+TEST_CASE(PortMap_SetLive) {
+ InitPortMapTest();
+ intptr_t port = PortMap::CreatePort();
+ EXPECT_NE(0, port);
+ EXPECT(PortMapTestPeer::IsActivePort(port));
+ EXPECT(!PortMapTestPeer::IsLivePort(port));
+
+ PortMap::SetLive(port);
+ EXPECT(PortMapTestPeer::IsActivePort(port));
+ EXPECT(PortMapTestPeer::IsLivePort(port));
+
+ PortMap::ClosePort(port);
+ EXPECT(!PortMapTestPeer::IsActivePort(port));
+ EXPECT(!PortMapTestPeer::IsLivePort(port));
+
+ // Embedder was notified of port closure.
+ EXPECT_EQ(port, saved_port);
+}
+
+
TEST_CASE(PortMap_PostMessage) {
InitPortMapTest();
Dart_Port port = PortMap::CreatePort();
« no previous file with comments | « runtime/vm/port.cc ('k') | runtime/vm/unit_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698