|
|
@@ -1059,6 +1059,106 @@ bool testChildClose() { |
|
|
|
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() {
|
|
|
|
|
|
|
|
// Test with no waiting.
|
|
|
@@ -1937,6 +2037,7 @@ int main() |
|
|
|
RUN_TEST(testChildIsRunning);
|
|
|
|
RUN_TEST(testChildResult);
|
|
|
|
RUN_TEST(testChildClose);
|
|
|
|
RUN_TEST(testChildStdInClose);
|
|
|
|
RUN_TEST(testChildOpen);
|
|
|
|
RUN_TEST(testChildIsFinishedWriting);
|
|
|
|
RUN_TEST(testChildRead);
|