Explorar el Código

Tested Child::closeStdIn().


git-svn-id: https://svn.microneil.com/svn/CodeDweller-Tests/trunk@51 b3372362-9eaa-4a85-aa2b-6faa1ab7c995
master
adeniz hace 9 años
padre
commit
f76eafce3c
Se han modificado 2 ficheros con 130 adiciones y 1 borrados
  1. 29
    1
      TestChild/childProgram.cpp
  2. 101
    0
      TestChild/testChild.cpp

+ 29
- 1
TestChild/childProgram.cpp Ver fichero

@@ -9,6 +9,8 @@ main(int argc, char *argv[]) {
std::ofstream log("childProgram.log");
int returnStatus = 25; // Successful return.
// Output for read test.
if (argc == 2) {
@@ -18,6 +20,10 @@ main(int argc, char *argv[]) {
std::cout << "This is a test";
std::cout.flush();
if (!std::cout) {
returnStatus = 10; // Unsuccessful return.
}
goto exit;
}
@@ -30,6 +36,28 @@ main(int argc, char *argv[]) {
}
// 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;
@@ -53,6 +81,6 @@ main(int argc, char *argv[]) {
exit:
log.close();
std::this_thread::sleep_for(std::chrono::milliseconds(50));
return 25;
return returnStatus;
}

+ 101
- 0
TestChild/testChild.cpp Ver fichero

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

Cargando…
Cancelar
Guardar