| 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 "platform/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "vm/lockers.h" | 6 #include "vm/lockers.h" |
| 7 #include "vm/message_handler.h" | 7 #include "vm/message_handler.h" |
| 8 #include "vm/os.h" | 8 #include "vm/os.h" |
| 9 #include "vm/port.h" | 9 #include "vm/port.h" |
| 10 #include "vm/unit_test.h" | 10 #include "vm/unit_test.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 EXPECT(PortMap::PostMessage(new Message( | 144 EXPECT(PortMap::PostMessage(new Message( |
| 145 port, reinterpret_cast<uint8_t*>(strdup(message)), message_len, | 145 port, reinterpret_cast<uint8_t*>(strdup(message)), message_len, |
| 146 Message::kNormalPriority))); | 146 Message::kNormalPriority))); |
| 147 | 147 |
| 148 // Check that the message notify callback was called. | 148 // Check that the message notify callback was called. |
| 149 EXPECT_EQ(1, handler.notify_count); | 149 EXPECT_EQ(1, handler.notify_count); |
| 150 PortMap::ClosePorts(&handler); | 150 PortMap::ClosePorts(&handler); |
| 151 } | 151 } |
| 152 | 152 |
| 153 | 153 |
| 154 TEST_CASE(PortMap_PostIntegerMessage) { |
| 155 PortTestMessageHandler handler; |
| 156 Dart_Port port = PortMap::CreatePort(&handler); |
| 157 EXPECT_EQ(0, handler.notify_count); |
| 158 |
| 159 EXPECT(PortMap::PostMessage(new Message( |
| 160 port, reinterpret_cast<uint8_t*>(Smi::New(42)), 0, |
| 161 Message::kNormalPriority))); |
| 162 |
| 163 // Check that the message notify callback was called. |
| 164 EXPECT_EQ(1, handler.notify_count); |
| 165 PortMap::ClosePorts(&handler); |
| 166 } |
| 167 |
| 168 |
| 169 TEST_CASE(PortMap_PostSimpleMessage) { |
| 170 PortTestMessageHandler handler; |
| 171 Dart_Port port = PortMap::CreatePort(&handler); |
| 172 EXPECT_EQ(0, handler.notify_count); |
| 173 |
| 174 EXPECT(PortMap::PostMessage(new Message( |
| 175 port, reinterpret_cast<uint8_t*>(Bool::False().raw()), 0, |
| 176 Message::kNormalPriority))); |
| 177 |
| 178 // Check that the message notify callback was called. |
| 179 EXPECT_EQ(1, handler.notify_count); |
| 180 PortMap::ClosePorts(&handler); |
| 181 } |
| 182 |
| 183 |
| 154 TEST_CASE(PortMap_PostMessageClosedPort) { | 184 TEST_CASE(PortMap_PostMessageClosedPort) { |
| 155 // Create a port id and make it invalid. | 185 // Create a port id and make it invalid. |
| 156 PortTestMessageHandler handler; | 186 PortTestMessageHandler handler; |
| 157 Dart_Port port = PortMap::CreatePort(&handler); | 187 Dart_Port port = PortMap::CreatePort(&handler); |
| 158 PortMap::ClosePort(port); | 188 PortMap::ClosePort(port); |
| 159 | 189 |
| 160 const char* message = "msg"; | 190 const char* message = "msg"; |
| 161 intptr_t message_len = strlen(message) + 1; | 191 intptr_t message_len = strlen(message) + 1; |
| 162 | 192 |
| 163 EXPECT(!PortMap::PostMessage(new Message( | 193 EXPECT(!PortMap::PostMessage(new Message( |
| 164 port, reinterpret_cast<uint8_t*>(strdup(message)), message_len, | 194 port, reinterpret_cast<uint8_t*>(strdup(message)), message_len, |
| 165 Message::kNormalPriority))); | 195 Message::kNormalPriority))); |
| 166 } | 196 } |
| 167 | 197 |
| 168 } // namespace dart | 198 } // namespace dart |
| OLD | NEW |