39 return openInternal (
pipeName,
false,
false);
44 return pimpl !=
nullptr;
58 return currentPipeName;
72 :
UnitTest (
"NamedPipe",
"Networking")
75 void runTest()
override
79 beginTest (
"Pre test cleanup");
82 expect (pipe.createNewPipe (
pipeName,
false));
85 beginTest (
"Create pipe");
88 expect (! pipe.isOpen());
90 expect (pipe.createNewPipe (
pipeName,
true));
91 expect (pipe.isOpen());
93 expect (pipe.createNewPipe (
pipeName,
false));
94 expect (pipe.isOpen());
101 beginTest (
"Existing pipe");
105 expect (! pipe.openExisting (
pipeName));
106 expect (! pipe.isOpen());
108 expect (pipe.createNewPipe (
pipeName,
true));
117 beginTest (
"Receive message created pipe");
120 expect (pipe.createNewPipe (
pipeName,
true));
137 beginTest (
"Receive message existing pipe");
143 expect (pipe.openExisting (
pipeName));
157 beginTest (
"Send message created pipe");
160 expect (pipe.createNewPipe (
pipeName,
true));
165 receiver.startThread();
171 expectEquals (bytesWritten, (
int)
sizeof (
sendData));
172 expectEquals (receiver.result, (
int)
sizeof (receiver.recvData));
173 expectEquals (receiver.recvData,
sendData);
176 beginTest (
"Send message existing pipe");
182 expect (pipe.openExisting (
pipeName));
184 receiver.startThread();
190 expectEquals (bytesWritten, (
int)
sizeof (
sendData));
191 expectEquals (receiver.result, (
int)
sizeof (receiver.recvData));
192 expectEquals (receiver.recvData,
sendData);
200 NamedPipeThread (
const String& threadName,
const String& pName,
201 bool shouldCreatePipe, WaitableEvent& completed)
202 : Thread (threadName), pipeName (pName), workCompleted (completed)
204 if (shouldCreatePipe)
205 pipe.createNewPipe (pipeName);
207 pipe.openExisting (pipeName);
211 const String& pipeName;
212 WaitableEvent& workCompleted;
220 SenderThread (
const String& pName,
bool shouldCreatePipe,
221 WaitableEvent& completed,
int sData)
222 : NamedPipeThread (
"NamePipeSender", pName, shouldCreatePipe, completed),
228 result = pipe.write (&sendData,
sizeof (sendData), 2000);
229 workCompleted.signal();
238 ReceiverThread (
const String& pName,
bool shouldCreatePipe,
239 WaitableEvent& completed)
240 : NamedPipeThread (
"NamePipeSender", pName, shouldCreatePipe, completed)
245 result = pipe.read (&recvData,
sizeof (recvData), 2000);
246 workCompleted.signal();
253static NamedPipeTests namedPipeTests;
Holds a resizable array of primitive or copy-by-value objects.
Array()=default
Creates an empty array.
String getName() const
Returns the last name that was used to try to open this pipe.
bool isOpen() const
True if the pipe is currently open.
bool createNewPipe(const String &pipeName, bool mustNotExist=false)
Tries to create a new pipe.
NamedPipe()
Creates a NamedPipe.
bool openExisting(const String &pipeName)
Tries to open a pipe that already exists.
void close()
Closes the pipe, if it's open.
Automatically locks and unlocks a ReadWriteLock object.
This is a base class for classes that perform a unit test.