39 return openInternal (
pipeName,
false,
false);
44 return pimpl !=
nullptr;
58 return currentPipeName;
73 :
UnitTest (
"NamedPipe", UnitTestCategories::networking)
76 void runTest()
override
80 beginTest (
"Pre test cleanup");
83 expect (pipe.createNewPipe (
pipeName,
false));
86 beginTest (
"Create pipe");
89 expect (! pipe.isOpen());
91 expect (pipe.createNewPipe (
pipeName,
true));
92 expect (pipe.isOpen());
94 expect (pipe.createNewPipe (
pipeName,
false));
95 expect (pipe.isOpen());
102 beginTest (
"Existing pipe");
106 expect (! pipe.openExisting (
pipeName));
107 expect (! pipe.isOpen());
109 expect (pipe.createNewPipe (
pipeName,
true));
118 beginTest (
"Receive message created pipe");
121 expect (pipe.createNewPipe (
pipeName,
true));
138 beginTest (
"Receive message existing pipe");
144 expect (pipe.openExisting (
pipeName));
158 beginTest (
"Send message created pipe");
161 expect (pipe.createNewPipe (
pipeName,
true));
166 receiver.startThread();
172 expectEquals (bytesWritten, (
int)
sizeof (
sendData));
173 expectEquals (receiver.result, (
int)
sizeof (receiver.recvData));
174 expectEquals (receiver.recvData,
sendData);
177 beginTest (
"Send message existing pipe");
183 expect (pipe.openExisting (
pipeName));
185 receiver.startThread();
191 expectEquals (bytesWritten, (
int)
sizeof (
sendData));
192 expectEquals (receiver.result, (
int)
sizeof (receiver.recvData));
193 expectEquals (receiver.recvData,
sendData);
201 NamedPipeThread (
const String& tName,
const String& pName,
202 bool shouldCreatePipe, WaitableEvent& completed)
203 : Thread (tName), pipeName (pName), workCompleted (completed)
205 if (shouldCreatePipe)
206 pipe.createNewPipe (pipeName);
208 pipe.openExisting (pipeName);
217 const String& pipeName;
218 WaitableEvent& workCompleted;
226 SenderThread (
const String& pName,
bool shouldCreatePipe,
227 WaitableEvent& completed,
int sData)
228 : NamedPipeThread (
"NamePipeSender", pName, shouldCreatePipe, completed),
234 result = pipe.write (&sendData,
sizeof (sendData), 2000);
235 workCompleted.signal();
244 ReceiverThread (
const String& pName,
bool shouldCreatePipe,
245 WaitableEvent& completed)
246 : NamedPipeThread (
"NamePipeSender", pName, shouldCreatePipe, completed)
251 result = pipe.read (&recvData,
sizeof (recvData), 2000);
252 workCompleted.signal();
259static NamedPipeTests namedPipeTests;
bool createNewPipe(const String &pipeName, bool mustNotExist=false)
bool openExisting(const String &pipeName)