| 
				
			 | 
			
			 | 
			@@ -1,10 +1,9 @@ | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			#include <cstdlib>
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			#include <iostream>
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			#include <chrono>
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			#include <thread>
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			#include <sstream>
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			#include <algorithm>
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			#include <random>
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			#include "CodeDweller/child.hpp"
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
	
		
			
			| 
				
			 | 
			
			 | 
			@@ -87,6 +86,9 @@ bool doReadWrite(size_t bufSize, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    while (nChar < maxChar) {
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			      std::uniform_int_distribution<int> randomChunk(1, bufSize * 4);
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			      std::default_random_engine generator(4828943);
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			      nChunks++;
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			      if (nChunks % outputEveryChunk == 0) {
 | 
		
		
	
	
		
			
			| 
				
			 | 
			
			 | 
			@@ -98,7 +100,7 @@ bool doReadWrite(size_t bufSize, | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			      std::string sentChunk, expectedChunk;
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			      // Get a random chunk size for sending.
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			      chunkSize = std::rand() % (bufSize * 4);
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			      chunkSize = randomChunk(generator);
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			      if (chunkSize + nChar > maxChar) {
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			        chunkSize = maxChar - nChar;
 | 
		
		
	
	
		
			
			| 
				
			 | 
			
			 | 
			@@ -306,7 +308,7 @@ bool testChildStreamIsRunning() { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    }
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			  } catch (std::exception &e) {
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    EXCEPTION_TERM("isRunning()");
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    EXCEPTION_TERM("testChildStreamIsRunning");
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    return false;
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			  }
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
	
		
			
			| 
				
			 | 
			
			 | 
			@@ -320,7 +322,7 @@ bool testChildStreamResult() { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    std::vector<std::string> cmd;
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    cmd.push_back(childName);
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    cmd.push_back("quit");
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    cmd.push_back("quit"); // Child sleeps for 50 ms and then exits.
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    CodeDweller::ChildStream child(cmd);
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
	
		
			
			| 
				
			 | 
			
			 | 
			@@ -1013,6 +1015,7 @@ bool testChildClose() { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			  // Test with waiting.
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			  try {
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    CodeDweller::Child child(childName);
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    std::this_thread::sleep_for(std::chrono::milliseconds(100));
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    child.close();
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			  } catch (std::exception &e) {
 | 
		
		
	
	
		
			
			| 
				
			 | 
			
			 | 
			@@ -1044,7 +1047,6 @@ bool testChildClose() { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			  // Test exception thrown for out-of-order calling.
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			  try {
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    CodeDweller::Child child;
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    child.close();
 | 
		
		
	
	
		
			
			| 
				
			 | 
			
			 | 
			@@ -1361,16 +1363,21 @@ bool testChildRead() { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    child.open(cmd);
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    int nTries = 100;
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    size_t nRead = 0;
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			    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)) {
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			        std::ostringstream temp;
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			        temp << "  Failure in testReader:  " << readBuf;
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			        temp << "  Failure in testReader on try " << i << ":  " << readBuf;
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			        RETURN_FALSE(temp.str());
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			      }
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
	
		
			
			| 
				
			 | 
			
			 | 
			@@ -1588,7 +1595,6 @@ bool testChildNonBlockingReadWrite2() { | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			int main()
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			{
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			  std::cout << "\nCodeDweller::ChildStream unit tests\n" << std::endl;
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			  RUN_TEST(testChildStreamIsDone);
 | 
		
		
	
	
		
			
			| 
				
			 | 
			
			 | 
			@@ -1602,7 +1608,7 @@ int main() | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			  std::cout << "\nCodeDweller::Child unit tests\n" << std::endl;
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			  //RUN_TEST(testChildIsDone);
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			  RUN_TEST(testChildIsDone);
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			  RUN_TEST(testChildIsRunning);
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			  RUN_TEST(testChildResult);
 | 
		
		
	
		
			
			 | 
			 | 
			
			 | 
			  RUN_TEST(testChildClose);
 |