Browse Source

Tested Child::closeStdIn().


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

+ 29
- 1
TestChild/childProgram.cpp View File

std::ofstream log("childProgram.log"); std::ofstream log("childProgram.log");
int returnStatus = 25; // Successful return.
// Output for read test. // Output for read test.
if (argc == 2) { if (argc == 2) {
std::cout << "This is a test"; std::cout << "This is a test";
std::cout.flush(); std::cout.flush();
if (!std::cout) {
returnStatus = 10; // Unsuccessful return.
}
goto exit; goto exit;
} }
} }
// Wait for standard input to close, and exit.
if (std::string(argv[1]) == "checkStdinEOF") {
log << "Command is \"checkStdinEOF\". Checking that stdin is closed."
<< std::endl;
std::string temp;
std::cin >> temp;
if (std::cin.eof()) {
log << "stdin was closed." << std::endl;
returnStatus = 15; // Successful return.
} else {
log << "stdin was not closed." << std::endl;
returnStatus = 10; // Unsuccessful return.
}
goto exit;
}
} }
char ch; char ch;
exit: exit:
log.close(); log.close();
std::this_thread::sleep_for(std::chrono::milliseconds(50)); std::this_thread::sleep_for(std::chrono::milliseconds(50));
return 25;
return returnStatus;
} }

+ 101
- 0
TestChild/testChild.cpp View File

return true; return true;
} }
bool testChildStdInClose() {
std::string errorDescription;
// Test with no child process.
try {
CodeDweller::Child child;
child.closeStdIn();
NO_EXCEPTION_TERM("closeStdIn() with no child process");
return false;
} catch (std::exception &e) {
}
// Test with no waiting.
try {
CodeDweller::Child child(childName);
child.closeStdIn();
child.close();
} catch (std::exception &e) {
EXCEPTION_TERM("closeStdIn() with no waiting");
return false;
}
// Run child that waits for stdin to close.
std::vector<std::string> cmd;
cmd.push_back(childName);
cmd.push_back("checkStdinEOF");
try {
CodeDweller::Child child(cmd);
child.closeStdIn();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
int32_t result = child.result();
if (15 != result) {
std::cout << "closeStdIn() failure; returned " << result
<< " instead of 15." << std::endl;
return false;
}
child.close();
if (child.errorOccurred(errorDescription)) {
std::ostringstream temp;
temp << " Failure in: testChildStdInClose: " << errorDescription;
RETURN_FALSE(temp.str());
}
} catch (std::exception &e) {
EXCEPTION_TERM("closeStdIn() or close()");
return false;
}
// Test after the child exits.
cmd.clear();
cmd.push_back(childName);
cmd.push_back("quit");
try {
CodeDweller::Child child(cmd);
if (!child.write("q")) {
RETURN_FALSE(" write() failure");
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
child.closeStdIn();
} catch (std::exception &e) {
EXCEPTION_TERM("closeStdIn() after child exits");
return false;
}
// Test exception thrown for out-of-order calling.
try {
CodeDweller::Child child;
child.closeStdIn();
NO_EXCEPTION_TERM("closeStdIn() called without open()");
return false;
} catch (std::exception &e) {
}
return true;
}
bool testChildOpen() { bool testChildOpen() {
// Test with no waiting. // Test with no waiting.
RUN_TEST(testChildIsRunning); RUN_TEST(testChildIsRunning);
RUN_TEST(testChildResult); RUN_TEST(testChildResult);
RUN_TEST(testChildClose); RUN_TEST(testChildClose);
RUN_TEST(testChildStdInClose);
RUN_TEST(testChildOpen); RUN_TEST(testChildOpen);
RUN_TEST(testChildIsFinishedWriting); RUN_TEST(testChildIsFinishedWriting);
RUN_TEST(testChildRead); RUN_TEST(testChildRead);

Loading…
Cancel
Save