Flutter Engine
The Flutter Engine
port_test.cc
Go to the documentation of this 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
3// BSD-style license that can be found in the LICENSE file.
4
5#include "vm/port.h"
6#include "platform/assert.h"
7#include "vm/lockers.h"
9#include "vm/os.h"
10#include "vm/unit_test.h"
11
12namespace dart {
13
15 public:
17
19
20 MessageStatus HandleMessage(std::unique_ptr<Message> message) { return kOK; }
21
23};
24
25TEST_CASE(PortMap_CreateAndCloseOnePort) {
28 EXPECT_NE(0, port);
29 EXPECT(PortMap::PortExists(port));
30
32 EXPECT(!PortMap::PortExists(port));
33}
34
35TEST_CASE(PortMap_CreateAndCloseTwoPorts) {
37 Dart_Port port1 = PortMap::CreatePort(&handler);
38 Dart_Port port2 = PortMap::CreatePort(&handler);
39 EXPECT(PortMap::PortExists(port1));
40 EXPECT(PortMap::PortExists(port2));
41
42 // Uniqueness.
43 EXPECT_NE(port1, port2);
44
45 PortMap::ClosePort(port1);
46 EXPECT(!PortMap::PortExists(port1));
47 EXPECT(PortMap::PortExists(port2));
48
49 PortMap::ClosePort(port2);
50 EXPECT(!PortMap::PortExists(port1));
51 EXPECT(!PortMap::PortExists(port2));
52}
53
54TEST_CASE(PortMap_ClosePorts) {
56 Dart_Port port1 = PortMap::CreatePort(&handler);
57 Dart_Port port2 = PortMap::CreatePort(&handler);
58 EXPECT(PortMap::PortExists(port1));
59 EXPECT(PortMap::PortExists(port2));
60
61 // Close all ports at once.
62 PortMap::ClosePorts(&handler);
63 EXPECT(!PortMap::PortExists(port1));
64 EXPECT(!PortMap::PortExists(port2));
65}
66
67TEST_CASE(PortMap_CreateManyPorts) {
69 for (int i = 0; i < 32; i++) {
71 EXPECT(PortMap::PortExists(port));
73 EXPECT(!PortMap::PortExists(port));
74 }
75}
76
77TEST_CASE(PortMap_PostMessage) {
80 EXPECT_EQ(0, handler.notify_count);
81
82 const char* message = "msg";
83 intptr_t message_len = strlen(message) + 1;
84
86 Message::New(port, reinterpret_cast<uint8_t*>(Utils::StrDup(message)),
87 message_len, nullptr, Message::kNormalPriority)));
88
89 // Check that the message notify callback was called.
90 EXPECT_EQ(1, handler.notify_count);
91 PortMap::ClosePorts(&handler);
92}
93
94TEST_CASE(PortMap_PostIntegerMessage) {
97 EXPECT_EQ(0, handler.notify_count);
98
101
102 // Check that the message notify callback was called.
103 EXPECT_EQ(1, handler.notify_count);
104 PortMap::ClosePorts(&handler);
105}
106
107TEST_CASE(PortMap_PostNullMessage) {
110 EXPECT_EQ(0, handler.notify_count);
111
114
115 // Check that the message notify callback was called.
116 EXPECT_EQ(1, handler.notify_count);
117 PortMap::ClosePorts(&handler);
118}
119
120TEST_CASE(PortMap_PostMessageClosedPort) {
121 // Create a port id and make it invalid.
125
126 const char* message = "msg";
127 intptr_t message_len = strlen(message) + 1;
128
130 Message::New(port, reinterpret_cast<uint8_t*>(Utils::StrDup(message)),
131 message_len, nullptr, Message::kNormalPriority)));
132}
133
134} // namespace dart
#define EXPECT(type, expectedAlignment, expectedSize)
static std::unique_ptr< Message > New(Args &&... args)
Definition: message.h:72
@ kNormalPriority
Definition: message.h:28
static ObjectPtr null()
Definition: object.h:433
static bool PostMessage(std::unique_ptr< Message > message, bool before_events=false)
Definition: port.cc:152
static bool ClosePort(Dart_Port id, MessageHandler **message_handler=nullptr)
Definition: port.cc:90
static void ClosePorts(MessageHandler *handler)
Definition: port.cc:128
static Dart_Port CreatePort(MessageHandler *handler)
Definition: port.cc:55
void MessageNotify(Message::Priority priority)
Definition: port_test.cc:18
MessageStatus HandleMessage(std::unique_ptr< Message > message)
Definition: port_test.cc:20
static SmiPtr New(intptr_t value)
Definition: object.h:10006
static char * StrDup(const char *s)
int64_t Dart_Port
Definition: dart_api.h:1525
Win32Message message
Definition: dart_vm.cc:33
TEST_CASE(DirectoryCurrent)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service port
Definition: switches.h:87