-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTest.mq5
65 lines (56 loc) · 2.34 KB
/
Test.mq5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
//+------------------------------------------------------------------+
//| ProjectName |
//| Copyright 2020, CompanyName |
//| http://www.companyname.net |
//+------------------------------------------------------------------+
#property strict
#include <Nng\Sockets.mqh>
#include <Nng\Message.mqh>
#include "TestRunner.mqh"
TestRunner testRunner;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Socket_Open_Close() {
Pair0Socket s;
Assert(s.IsOpen());
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Socket_Listen_Dial() {
string endpoint = "inproc://" + __FUNCTION__;
Pair0Socket server;
Assert(server.Listen(endpoint));
Pair0Socket client;
Assert(client.Dial(endpoint));
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void Socket_SendReceiveMessage() {
string endpoint = "inproc://" + __FUNCTION__;
Pair0Socket server;
server.Listen(endpoint);
Pair0Socket client;
client.Dial(endpoint);
Message msg;
Assert(msg.SetData("hello"));
Assert(client.SendMessage(msg));
Message receivedMessage;
Assert(server.ReceiveMessage(receivedMessage));
size_t size = receivedMessage.GetSize();
Assert(6 == size);
string receivedString;
Assert(receivedMessage.GetData(receivedString));
Assert("hello" == receivedString);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnStart() {
Socket_Open_Close();
Socket_Listen_Dial();
Socket_SendReceiveMessage();
}
//+------------------------------------------------------------------+