Browse Source

Tested non-blocking read on Linux.


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

+ 20
- 28
TestChild/testChild.cpp View File

@@ -413,7 +413,7 @@ testBinaryRead() {
// Write.
std::string childInput("abc");
#if 0
child.writer << childInput;
child.writer.flush();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
@@ -438,9 +438,7 @@ testBinaryRead() {
if (input != "BC") {
RETURN_FALSE(" reader.read() returned incorrect value");
}
#else
char buf[bufSize * 2];
#endif
// Fill input buffer.
std::string output("abcdefghijklmnopprstuvwxyz");
std::string expectedInput(output);
@@ -449,13 +447,10 @@ testBinaryRead() {
expectedInput[i] = std::toupper(output[i]);
}
std::cout << "Writing '" << output << "', " << output.size()
<< " bytes" << std::endl;//debug
child.writer << output;
child.writer.flush();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
#if 1
char ch;
child.reader.read(&ch, 1);
int index = 0;
@@ -463,15 +458,12 @@ testBinaryRead() {
if (ch != expectedInput[index++]) {
RETURN_FALSE(" reader.read() returned incorrect value");
}
#endif
size_t nBytesRead = expectedInput.size() - 1;
std::cout << "testChild. reading " << nBytesRead << " bytes..." << std::endl; // debug
child.reader.read(buf, nBytesRead);
std::cout << "done." << std::endl;
buf[nBytesRead] = '\0';
std::cout << "buf: '" << buf << "'" << std::endl; //debug
if (expectedInput.substr(index, nBytesRead) != std::string(buf)) {
RETURN_FALSE(" reader.read() failure");
}
@@ -496,7 +488,7 @@ testBinaryRead() {
EXCEPTION_TERM("Binary read test");
return false;
}
std::cout << "success. returning." << std::endl;//debug
return true;
}
@@ -565,7 +557,7 @@ testNonBlockingRead() {
}
// Fill input buffer.
std::string output("abcdefghijklmnopqrstuvwxyz");
std::string output("abcdefghijklmnopprstuvwxyz");
std::string expectedInput(output);
for (int i = 0; i < output.size(); i++) {
@@ -590,32 +582,32 @@ testNonBlockingRead() {
size_t nBytesAvailable;
#if 0
nBytesAvailable = child.numBytesAvailable();
if (nBytesAvailable != bufSize) {
RETURN_FALSE(" numBytesAvailable() did not return expected value");
}
#else
nBytesAvailable = 16;
#endif
std::fill_n(buf, sizeof(buf), 0);
std::cout << "Reading " << nBytesAvailable << " bytes..." << std::endl; // DEBUG
child.reader.read(buf, nBytesAvailable);
std::cout << "Done" << std::endl; // DEBUG
if (expectedInput.substr(index, nBytesAvailable) != std::string(buf)) {
RETURN_FALSE(" reader.read() failure");
}
index += nBytesAvailable;
nBytesAvailable = child.numBytesAvailable();
if (nBytesAvailable != expectedInput.size() - 1 - bufSize) {
RETURN_FALSE(" numBytesAvailable() did not return expected value");
}
std::fill_n(buf, sizeof(buf), 0);
child.reader.read(buf, nBytesAvailable);
if (expectedInput.substr(index, nBytesAvailable) != std::string(buf)) {
RETURN_FALSE(" reader.read() failure");
}
index += nBytesAvailable;
if (expectedInput.size() != index) {
RETURN_FALSE(" not all data was read by reader.read()");
}
@@ -644,7 +636,7 @@ testNonBlockingRead() {
EXCEPTION_TERM("Non-blocking reader test");
return false;
}
std::cout << "success. returning." << std::endl;//debug
return true;
}
@@ -659,13 +651,13 @@ int main()
CodeDweller::Child child(childName);
//RUN_TEST(testIsDone);
//RUN_TEST(testResult);
//RUN_TEST(testTerminate);
//RUN_TEST(testReader);
//RUN_TEST(testReaderWriter);
RUN_TEST(testIsDone);
RUN_TEST(testResult);
RUN_TEST(testTerminate);
RUN_TEST(testReader);
RUN_TEST(testReaderWriter);
RUN_TEST(testBinaryRead);
//RUN_TEST(testNonBlockingRead);
RUN_TEST(testNonBlockingRead);
SUMMARY;

Loading…
Cancel
Save