Преглед на файлове

Tested inheritance of Child from std::iostream.


git-svn-id: https://svn.microneil.com/svn/CodeDweller-Tests/trunk@40 b3372362-9eaa-4a85-aa2b-6faa1ab7c995
master
adeniz преди 9 години
родител
ревизия
43ae0cac71
променени са 1 файла, в които са добавени 64 реда и са изтрити 64 реда
  1. 64
    64
      TestChild/testChild.cpp

+ 64
- 64
TestChild/testChild.cpp Целия файл

@@ -62,7 +62,7 @@ testIsDone() {
try {
CodeDweller::Child child(childName);
CodeDweller::ChildStream child(childName);
// Test exception if called out-of-order.
try {
@@ -79,8 +79,8 @@ testIsDone() {
}
// Command the child to exit.
child.childStream << 'q';
child.childStream.flush();
child << 'q';
child.flush();
// Sleep to let the child exit.
std::this_thread::sleep_for(std::chrono::milliseconds(100));
@@ -107,7 +107,7 @@ testResult() {
cmd.push_back(childName);
cmd.push_back("quit");
CodeDweller::Child child(cmd);
CodeDweller::ChildStream child(cmd);
// Test exception if called out-of-order.
try {
@@ -148,7 +148,7 @@ testTerminate() {
// Test with no waiting.
try {
CodeDweller::Child child(childName);
CodeDweller::ChildStream child(childName);
child.run();
child.terminate();
} catch (std::exception &e) {
@@ -158,7 +158,7 @@ testTerminate() {
// Test with waiting.
try {
CodeDweller::Child child(childName);
CodeDweller::ChildStream child(childName);
child.run();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
child.terminate();
@@ -174,7 +174,7 @@ testTerminate() {
cmd.push_back("quit");
try {
CodeDweller::Child child(cmd);
CodeDweller::ChildStream child(cmd);
child.run();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
child.terminate();
@@ -185,7 +185,7 @@ testTerminate() {
// Test exception thrown for out-of-order calling.
try {
CodeDweller::Child child(cmd);
CodeDweller::ChildStream child(cmd);
child.terminate();
NO_EXCEPTION_TERM("terminate() called without run()");
return false;
@@ -200,7 +200,7 @@ testReaderWriter() {
try {
size_t bufSize = 15;
CodeDweller::Child child(childName, bufSize);
CodeDweller::ChildStream child(childName, bufSize);
std::ostringstream childOutput;
std::vector<std::string> expectedChildOutput;
char readChar;
@@ -220,9 +220,9 @@ testReaderWriter() {
// Test exception.
try {
child.childStream.exceptions(std::ostream::failbit | std::ostream::badbit);
child.childStream << bufSize;
child.childStream.flush();
child.exceptions(std::ostream::failbit | std::ostream::badbit);
child << bufSize;
child.flush();
NO_EXCEPTION_TERM(" writer called without run()");
return false;
} catch (std::exception &e) {
@@ -230,7 +230,7 @@ testReaderWriter() {
// Clear the writer stream.
try {
child.childStream.clear();
child.clear();
} catch (std::exception &e) {
}
@@ -244,13 +244,13 @@ testReaderWriter() {
ptr = line.data();
for (std::string::size_type i = 0; i < line.length(); i++) {
child.childStream << ptr[i];
if (!child.childStream) {
child << ptr[i];
if (!child) {
RETURN_FALSE(" Failure in testReaderWriter: writer stream is bad");
}
}
child.childStream.flush();
if (!child.childStream) {
child.flush();
if (!child) {
RETURN_FALSE(" Failure in testReaderWriter: writer stream is bad");
}
@@ -259,8 +259,8 @@ testReaderWriter() {
readLine.erase();
for (std::string::size_type i = 0; i < line.length(); i++) {
child.childStream >> readChar;
if (!child.childStream) {
child >> readChar;
if (!child) {
RETURN_FALSE(" Failure in testReaderWriter: reader stream is bad");
}
readLine.push_back(readChar);
@@ -288,9 +288,9 @@ testReaderWriter() {
}
// Send exit message.
child.childStream << 'q';
child.childStream.flush();
if (!child.childStream) {
child << 'q';
child.flush();
if (!child) {
RETURN_FALSE(" Failure in testReaderWriter: writer stream is bad");
}
@@ -322,49 +322,49 @@ testReader() {
cmd.push_back("write");
size_t bufSize = 32;
CodeDweller::Child child(cmd, bufSize);
CodeDweller::ChildStream child(cmd, bufSize);
// Test exception.
try {
int temp;
child.childStream.exceptions(std::istream::failbit | std::istream::badbit);
child.childStream >> temp;
child.exceptions(std::istream::failbit | std::istream::badbit);
child >> temp;
NO_EXCEPTION_TERM(" reader called without run()");
return false;
} catch (std::exception &e) {
}
child.childStream.clear();
child.childStream.clear();
child.clear();
child.clear();
std::ostringstream childOutput;
std::string expectedChildOutput("This is a test");
char readChar;
child.run();
child.childStream.exceptions(std::istream::badbit);
child.childStream >> std::noskipws;
if (!child.childStream) {
child.exceptions(std::istream::badbit);
child >> std::noskipws;
if (!child) {
RETURN_FALSE(" Failure in testReader: reader stream is bad");
}
while (child.childStream >> readChar) {
while (child >> readChar) {
if (!child.childStream) {
if (!child) {
RETURN_FALSE(" Failure in testReader: reader stream is bad");
}
child.childStream.putback(readChar);
if (!child.childStream) {
child.putback(readChar);
if (!child) {
RETURN_FALSE(" Failure in testReader: reader stream is bad");
}
child.childStream >> readChar;
if (!child.childStream) {
child >> readChar;
if (!child) {
RETURN_FALSE(" Failure in testReader: reader stream is bad");
}
childOutput << readChar;
}
if (!child.childStream.eof()) {
if (!child.eof()) {
RETURN_FALSE(" Failure in testReader: Error occured before "
"EOF was reached while reading");
}
@@ -409,21 +409,21 @@ testBinaryRead() {
cmd.push_back(childName);
size_t bufSize = 164;
CodeDweller::Child child(cmd, bufSize);
CodeDweller::ChildStream child(cmd, bufSize);
child.run();
// Write.
std::string childInput("abc");
child.childStream << childInput;
child.childStream.flush();
child << childInput;
child.flush();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
// Read one character.
char ch;
child.childStream.read(&ch, 1);
child.read(&ch, 1);
if (ch != 'A') {
RETURN_FALSE(" reader.read() returned incorrect value");
@@ -432,7 +432,7 @@ testBinaryRead() {
// Read.
char buf[bufSize * 2];
child.childStream.read(buf, 2);
child.read(buf, 2);
buf[2] = '\0';
std::string input(buf);
@@ -449,11 +449,11 @@ testBinaryRead() {
expectedInput[i] = std::toupper(output[i]);
}
child.childStream << output;
child.childStream.flush();
child << output;
child.flush();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
child.childStream.read(&ch, 1);
child.read(&ch, 1);
int index = 0;
@@ -463,7 +463,7 @@ testBinaryRead() {
size_t nBytesRead = expectedInput.size() - 1;
child.childStream.read(buf, nBytesRead);
child.read(buf, nBytesRead);
buf[nBytesRead] = '\0';
if (expectedInput.substr(index, nBytesRead) != std::string(buf)) {
@@ -471,9 +471,9 @@ testBinaryRead() {
}
// Send exit message.
child.childStream << 'q';
child.childStream.flush();
if (!child.childStream) {
child << 'q';
child.flush();
if (!child) {
RETURN_FALSE(" Failure in testNonblockingReader: writer stream is bad");
}
@@ -504,7 +504,7 @@ testNonBlockingRead() {
cmd.push_back(childName);
size_t bufSize = 16;
CodeDweller::Child child(cmd, bufSize);
CodeDweller::ChildStream child(cmd, bufSize);
child.run();
@@ -516,8 +516,8 @@ testNonBlockingRead() {
// Check for available input with input.
std::string childInput("abc");
child.childStream << childInput;
child.childStream.flush();
child << childInput;
child.flush();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
// Check that input is available.
@@ -528,7 +528,7 @@ testNonBlockingRead() {
// Read one character.
char ch;
child.childStream.read(&ch, 1);
child.read(&ch, 1);
if (ch != 'A') {
RETURN_FALSE(" reader.read() returned incorrect value");
@@ -542,7 +542,7 @@ testNonBlockingRead() {
// Read.
char buf[bufSize * 2];
child.childStream.read(buf, 2);
child.read(buf, 2);
buf[2] = '\0';
std::string input(buf);
@@ -565,15 +565,15 @@ testNonBlockingRead() {
expectedInput[i] = std::toupper(output[i]);
}
child.childStream << output;
child.childStream.flush();
child << output;
child.flush();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
if (child.numBytesAvailable() != 1) {
RETURN_FALSE(" numBytesAvailable() did not return expected 1");
}
child.childStream.read(&ch, 1);
child.read(&ch, 1);
int index = 0;
@@ -589,7 +589,7 @@ testNonBlockingRead() {
}
std::fill_n(buf, sizeof(buf), 0);
child.childStream.read(buf, nBytesAvailable);
child.read(buf, nBytesAvailable);
if (expectedInput.substr(index, nBytesAvailable) != std::string(buf)) {
RETURN_FALSE(" reader.read() failure");
@@ -602,7 +602,7 @@ testNonBlockingRead() {
}
std::fill_n(buf, sizeof(buf), 0);
child.childStream.read(buf, nBytesAvailable);
child.read(buf, nBytesAvailable);
if (expectedInput.substr(index, nBytesAvailable) != std::string(buf)) {
RETURN_FALSE(" reader.read() failure");
@@ -618,9 +618,9 @@ testNonBlockingRead() {
}
// Send exit message.
child.childStream << 'q';
child.childStream.flush();
if (!child.childStream) {
child << 'q';
child.flush();
if (!child) {
RETURN_FALSE(" Failure in testNonblockingReader: writer stream is bad");
}
@@ -648,9 +648,9 @@ testNonBlockingRead() {
int main()
{
std::cout << "CodeDweller::Child unit tests" << std::endl << std::endl;
std::cout << "CodeDweller::ChildStream unit tests" << std::endl << std::endl;
CodeDweller::Child child(childName);
CodeDweller::ChildStream child(childName);
RUN_TEST(testIsDone);
RUN_TEST(testResult);

Loading…
Отказ
Запис