|
|
|
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
#include <iostream>
|
|
|
#include <chrono>
|
|
|
#include <chrono>
|
|
|
#include <thread>
|
|
|
#include <thread>
|
|
|
#include <sstream>
|
|
|
#include <sstream>
|
|
|
#include <algorithm>
|
|
|
#include <algorithm>
|
|
|
|
|
|
#include <random>
|
|
|
|
|
|
|
|
|
#include "CodeDweller/child.hpp"
|
|
|
#include "CodeDweller/child.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (nChar < maxChar) {
|
|
|
while (nChar < maxChar) {
|
|
|
|
|
|
|
|
|
|
|
|
std::uniform_int_distribution<int> randomChunk(1, bufSize * 4);
|
|
|
|
|
|
std::default_random_engine generator(4828943);
|
|
|
|
|
|
|
|
|
nChunks++;
|
|
|
nChunks++;
|
|
|
|
|
|
|
|
|
if (nChunks % outputEveryChunk == 0) {
|
|
|
if (nChunks % outputEveryChunk == 0) {
|
|
|
|
|
|
|
|
|
std::string sentChunk, expectedChunk;
|
|
|
std::string sentChunk, expectedChunk;
|
|
|
|
|
|
|
|
|
// Get a random chunk size for sending.
|
|
|
// Get a random chunk size for sending.
|
|
|
chunkSize = std::rand() % (bufSize * 4);
|
|
|
|
|
|
|
|
|
chunkSize = randomChunk(generator);
|
|
|
|
|
|
|
|
|
if (chunkSize + nChar > maxChar) {
|
|
|
if (chunkSize + nChar > maxChar) {
|
|
|
chunkSize = maxChar - nChar;
|
|
|
chunkSize = maxChar - nChar;
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
} catch (std::exception &e) {
|
|
|
} catch (std::exception &e) {
|
|
|
EXCEPTION_TERM("isRunning()");
|
|
|
|
|
|
|
|
|
EXCEPTION_TERM("testChildStreamIsRunning");
|
|
|
return false;
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> cmd;
|
|
|
std::vector<std::string> cmd;
|
|
|
|
|
|
|
|
|
cmd.push_back(childName);
|
|
|
cmd.push_back(childName);
|
|
|
cmd.push_back("quit");
|
|
|
|
|
|
|
|
|
cmd.push_back("quit"); // Child sleeps for 50 ms and then exits.
|
|
|
|
|
|
|
|
|
CodeDweller::ChildStream child(cmd);
|
|
|
CodeDweller::ChildStream child(cmd);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Test with waiting.
|
|
|
// Test with waiting.
|
|
|
try {
|
|
|
try {
|
|
|
CodeDweller::Child child(childName);
|
|
|
CodeDweller::Child child(childName);
|
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
child.close();
|
|
|
child.close();
|
|
|
} catch (std::exception &e) {
|
|
|
} catch (std::exception &e) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Test exception thrown for out-of-order calling.
|
|
|
// Test exception thrown for out-of-order calling.
|
|
|
try {
|
|
|
try {
|
|
|
|
|
|
|
|
|
CodeDweller::Child child;
|
|
|
CodeDweller::Child child;
|
|
|
|
|
|
|
|
|
child.close();
|
|
|
child.close();
|
|
|
|
|
|
|
|
|
child.open(cmd);
|
|
|
child.open(cmd);
|
|
|
|
|
|
|
|
|
int nTries = 100;
|
|
|
int nTries = 100;
|
|
|
|
|
|
size_t nRead = 0;
|
|
|
|
|
|
|
|
|
for (int i = 0; i < nTries; i++) {
|
|
|
for (int i = 0; i < nTries; i++) {
|
|
|
|
|
|
|
|
|
if (child.read(readBuf) > 0) {
|
|
|
|
|
|
childOutput << readBuf;
|
|
|
|
|
|
|
|
|
nRead += child.read(readBuf);
|
|
|
|
|
|
childOutput << readBuf;
|
|
|
|
|
|
|
|
|
|
|
|
if (expectedChildOutput.size() == nRead) {
|
|
|
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
if (child.errorOccurred(readBuf)) {
|
|
|
if (child.errorOccurred(readBuf)) {
|
|
|
std::ostringstream temp;
|
|
|
std::ostringstream temp;
|
|
|
|
|
|
|
|
|
temp << " Failure in testReader: " << readBuf;
|
|
|
|
|
|
|
|
|
temp << " Failure in testReader on try " << i << ": " << readBuf;
|
|
|
RETURN_FALSE(temp.str());
|
|
|
RETURN_FALSE(temp.str());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
int main()
|
|
|
{
|
|
|
{
|
|
|
|
|
|
|
|
|
std::cout << "\nCodeDweller::ChildStream unit tests\n" << std::endl;
|
|
|
std::cout << "\nCodeDweller::ChildStream unit tests\n" << std::endl;
|
|
|
|
|
|
|
|
|
RUN_TEST(testChildStreamIsDone);
|
|
|
RUN_TEST(testChildStreamIsDone);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::cout << "\nCodeDweller::Child unit tests\n" << std::endl;
|
|
|
std::cout << "\nCodeDweller::Child unit tests\n" << std::endl;
|
|
|
|
|
|
|
|
|
//RUN_TEST(testChildIsDone);
|
|
|
|
|
|
|
|
|
RUN_TEST(testChildIsDone);
|
|
|
RUN_TEST(testChildIsRunning);
|
|
|
RUN_TEST(testChildIsRunning);
|
|
|
RUN_TEST(testChildResult);
|
|
|
RUN_TEST(testChildResult);
|
|
|
RUN_TEST(testChildClose);
|
|
|
RUN_TEST(testChildClose);
|