Browse Source

Updated test for Windows.


git-svn-id: https://svn.microneil.com/svn/CodeDweller-Tests/trunk@44 b3372362-9eaa-4a85-aa2b-6faa1ab7c995
master
adeniz 9 years ago
parent
commit
b63e90ee95
2 changed files with 18 additions and 11 deletions
  1. 1
    0
      TestChild/childProgram.cpp
  2. 17
    11
      TestChild/testChild.cpp

+ 1
- 0
TestChild/childProgram.cpp View File

exit: exit:
log.close(); log.close();
std::this_thread::sleep_for(std::chrono::milliseconds(50));
return 25; return 25;
} }

+ 17
- 11
TestChild/testChild.cpp View File

#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);

Loading…
Cancel
Save