Browse Source

Tested merging of input and output streambuf and stream.


git-svn-id: https://svn.microneil.com/svn/CodeDweller-Tests/trunk@39 b3372362-9eaa-4a85-aa2b-6faa1ab7c995
master
adeniz 9 years ago
parent
commit
4fdfa912bd
1 changed files with 52 additions and 52 deletions
  1. 52
    52
      TestChild/testChild.cpp

+ 52
- 52
TestChild/testChild.cpp View File

@@ -79,8 +79,8 @@ testIsDone() {
}
// Command the child to exit.
child.writer << 'q';
child.writer.flush();
child.childStream << 'q';
child.childStream.flush();
// Sleep to let the child exit.
std::this_thread::sleep_for(std::chrono::milliseconds(100));
@@ -220,9 +220,9 @@ testReaderWriter() {
// Test exception.
try {
child.writer.exceptions(std::ostream::failbit | std::ostream::badbit);
child.writer << bufSize;
child.writer.flush();
child.childStream.exceptions(std::ostream::failbit | std::ostream::badbit);
child.childStream << bufSize;
child.childStream.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.writer.clear();
child.childStream.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.writer << ptr[i];
if (!child.writer) {
child.childStream << ptr[i];
if (!child.childStream) {
RETURN_FALSE(" Failure in testReaderWriter: writer stream is bad");
}
}
child.writer.flush();
if (!child.writer) {
child.childStream.flush();
if (!child.childStream) {
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.reader >> readChar;
if (!child.reader) {
child.childStream >> readChar;
if (!child.childStream) {
RETURN_FALSE(" Failure in testReaderWriter: reader stream is bad");
}
readLine.push_back(readChar);
@@ -288,9 +288,9 @@ testReaderWriter() {
}
// Send exit message.
child.writer << 'q';
child.writer.flush();
if (!child.writer) {
child.childStream << 'q';
child.childStream.flush();
if (!child.childStream) {
RETURN_FALSE(" Failure in testReaderWriter: writer stream is bad");
}
@@ -327,44 +327,44 @@ testReader() {
// Test exception.
try {
int temp;
child.reader.exceptions(std::istream::failbit | std::istream::badbit);
child.reader >> temp;
child.childStream.exceptions(std::istream::failbit | std::istream::badbit);
child.childStream >> temp;
NO_EXCEPTION_TERM(" reader called without run()");
return false;
} catch (std::exception &e) {
}
child.reader.clear();
child.writer.clear();
child.childStream.clear();
child.childStream.clear();
std::ostringstream childOutput;
std::string expectedChildOutput("This is a test");
char readChar;
child.run();
child.reader.exceptions(std::istream::badbit);
child.reader >> std::noskipws;
if (!child.reader) {
child.childStream.exceptions(std::istream::badbit);
child.childStream >> std::noskipws;
if (!child.childStream) {
RETURN_FALSE(" Failure in testReader: reader stream is bad");
}
while (child.reader >> readChar) {
while (child.childStream >> readChar) {
if (!child.reader) {
if (!child.childStream) {
RETURN_FALSE(" Failure in testReader: reader stream is bad");
}
child.reader.putback(readChar);
if (!child.reader) {
child.childStream.putback(readChar);
if (!child.childStream) {
RETURN_FALSE(" Failure in testReader: reader stream is bad");
}
child.reader >> readChar;
if (!child.reader) {
child.childStream >> readChar;
if (!child.childStream) {
RETURN_FALSE(" Failure in testReader: reader stream is bad");
}
childOutput << readChar;
}
if (!child.reader.eof()) {
if (!child.childStream.eof()) {
RETURN_FALSE(" Failure in testReader: Error occured before "
"EOF was reached while reading");
}
@@ -416,14 +416,14 @@ testBinaryRead() {
// Write.
std::string childInput("abc");
child.writer << childInput;
child.writer.flush();
child.childStream << childInput;
child.childStream.flush();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
// Read one character.
char ch;
child.reader.read(&ch, 1);
child.childStream.read(&ch, 1);
if (ch != 'A') {
RETURN_FALSE(" reader.read() returned incorrect value");
@@ -432,7 +432,7 @@ testBinaryRead() {
// Read.
char buf[bufSize * 2];
child.reader.read(buf, 2);
child.childStream.read(buf, 2);
buf[2] = '\0';
std::string input(buf);
@@ -449,11 +449,11 @@ testBinaryRead() {
expectedInput[i] = std::toupper(output[i]);
}
child.writer << output;
child.writer.flush();
child.childStream << output;
child.childStream.flush();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
child.reader.read(&ch, 1);
child.childStream.read(&ch, 1);
int index = 0;
@@ -463,7 +463,7 @@ testBinaryRead() {
size_t nBytesRead = expectedInput.size() - 1;
child.reader.read(buf, nBytesRead);
child.childStream.read(buf, nBytesRead);
buf[nBytesRead] = '\0';
if (expectedInput.substr(index, nBytesRead) != std::string(buf)) {
@@ -471,9 +471,9 @@ testBinaryRead() {
}
// Send exit message.
child.writer << 'q';
child.writer.flush();
if (!child.writer) {
child.childStream << 'q';
child.childStream.flush();
if (!child.childStream) {
RETURN_FALSE(" Failure in testNonblockingReader: writer stream is bad");
}
@@ -516,8 +516,8 @@ testNonBlockingRead() {
// Check for available input with input.
std::string childInput("abc");
child.writer << childInput;
child.writer.flush();
child.childStream << childInput;
child.childStream.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.reader.read(&ch, 1);
child.childStream.read(&ch, 1);
if (ch != 'A') {
RETURN_FALSE(" reader.read() returned incorrect value");
@@ -542,7 +542,7 @@ testNonBlockingRead() {
// Read.
char buf[bufSize * 2];
child.reader.read(buf, 2);
child.childStream.read(buf, 2);
buf[2] = '\0';
std::string input(buf);
@@ -565,15 +565,15 @@ testNonBlockingRead() {
expectedInput[i] = std::toupper(output[i]);
}
child.writer << output;
child.writer.flush();
child.childStream << output;
child.childStream.flush();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
if (child.numBytesAvailable() != 1) {
RETURN_FALSE(" numBytesAvailable() did not return expected 1");
}
child.reader.read(&ch, 1);
child.childStream.read(&ch, 1);
int index = 0;
@@ -589,7 +589,7 @@ testNonBlockingRead() {
}
std::fill_n(buf, sizeof(buf), 0);
child.reader.read(buf, nBytesAvailable);
child.childStream.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.reader.read(buf, nBytesAvailable);
child.childStream.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.writer << 'q';
child.writer.flush();
if (!child.writer) {
child.childStream << 'q';
child.childStream.flush();
if (!child.childStream) {
RETURN_FALSE(" Failure in testNonblockingReader: writer stream is bad");
}

Loading…
Cancel
Save