|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Write.
|
|
|
// Write.
|
|
|
std::string childInput("abc");
|
|
|
std::string childInput("abc");
|
|
|
#if 0
|
|
|
|
|
|
|
|
|
|
|
|
child.writer << childInput;
|
|
|
child.writer << childInput;
|
|
|
child.writer.flush();
|
|
|
child.writer.flush();
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
|
|
|
|
|
|
if (input != "BC") {
|
|
|
if (input != "BC") {
|
|
|
RETURN_FALSE(" reader.read() returned incorrect value");
|
|
|
RETURN_FALSE(" reader.read() returned incorrect value");
|
|
|
}
|
|
|
}
|
|
|
#else
|
|
|
|
|
|
char buf[bufSize * 2];
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Fill input buffer.
|
|
|
// Fill input buffer.
|
|
|
std::string output("abcdefghijklmnopprstuvwxyz");
|
|
|
std::string output("abcdefghijklmnopprstuvwxyz");
|
|
|
std::string expectedInput(output);
|
|
|
std::string expectedInput(output);
|
|
|
|
|
|
|
|
|
expectedInput[i] = std::toupper(output[i]);
|
|
|
expectedInput[i] = std::toupper(output[i]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
std::cout << "Writing '" << output << "', " << output.size()
|
|
|
|
|
|
<< " bytes" << std::endl;//debug
|
|
|
|
|
|
child.writer << output;
|
|
|
child.writer << output;
|
|
|
child.writer.flush();
|
|
|
child.writer.flush();
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
#if 1
|
|
|
|
|
|
char ch;
|
|
|
|
|
|
|
|
|
|
|
|
child.reader.read(&ch, 1);
|
|
|
child.reader.read(&ch, 1);
|
|
|
|
|
|
|
|
|
int index = 0;
|
|
|
int index = 0;
|
|
|
|
|
|
|
|
|
if (ch != expectedInput[index++]) {
|
|
|
if (ch != expectedInput[index++]) {
|
|
|
RETURN_FALSE(" reader.read() returned incorrect value");
|
|
|
RETURN_FALSE(" reader.read() returned incorrect value");
|
|
|
}
|
|
|
}
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
size_t nBytesRead = expectedInput.size() - 1;
|
|
|
size_t nBytesRead = expectedInput.size() - 1;
|
|
|
|
|
|
|
|
|
std::cout << "testChild. reading " << nBytesRead << " bytes..." << std::endl; // debug
|
|
|
|
|
|
child.reader.read(buf, nBytesRead);
|
|
|
child.reader.read(buf, nBytesRead);
|
|
|
std::cout << "done." << std::endl;
|
|
|
|
|
|
buf[nBytesRead] = '\0';
|
|
|
buf[nBytesRead] = '\0';
|
|
|
|
|
|
|
|
|
std::cout << "buf: '" << buf << "'" << std::endl; //debug
|
|
|
|
|
|
if (expectedInput.substr(index, nBytesRead) != std::string(buf)) {
|
|
|
if (expectedInput.substr(index, nBytesRead) != std::string(buf)) {
|
|
|
RETURN_FALSE(" reader.read() failure");
|
|
|
RETURN_FALSE(" reader.read() failure");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
EXCEPTION_TERM("Binary read test");
|
|
|
EXCEPTION_TERM("Binary read test");
|
|
|
return false;
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
std::cout << "success. returning." << std::endl;//debug
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
return true;
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// Fill input buffer.
|
|
|
// Fill input buffer.
|
|
|
std::string output("abcdefghijklmnopqrstuvwxyz");
|
|
|
|
|
|
|
|
|
std::string output("abcdefghijklmnopprstuvwxyz");
|
|
|
std::string expectedInput(output);
|
|
|
std::string expectedInput(output);
|
|
|
|
|
|
|
|
|
for (int i = 0; i < output.size(); i++) {
|
|
|
for (int i = 0; i < output.size(); i++) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t nBytesAvailable;
|
|
|
size_t nBytesAvailable;
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
|
nBytesAvailable = child.numBytesAvailable();
|
|
|
nBytesAvailable = child.numBytesAvailable();
|
|
|
if (nBytesAvailable != bufSize) {
|
|
|
if (nBytesAvailable != bufSize) {
|
|
|
RETURN_FALSE(" numBytesAvailable() did not return expected value");
|
|
|
RETURN_FALSE(" numBytesAvailable() did not return expected value");
|
|
|
}
|
|
|
}
|
|
|
#else
|
|
|
|
|
|
nBytesAvailable = 16;
|
|
|
|
|
|
#endif
|
|
|
|
|
|
std::fill_n(buf, sizeof(buf), 0);
|
|
|
std::fill_n(buf, sizeof(buf), 0);
|
|
|
std::cout << "Reading " << nBytesAvailable << " bytes..." << std::endl; // DEBUG
|
|
|
|
|
|
|
|
|
|
|
|
child.reader.read(buf, nBytesAvailable);
|
|
|
child.reader.read(buf, nBytesAvailable);
|
|
|
std::cout << "Done" << std::endl; // DEBUG
|
|
|
|
|
|
|
|
|
|
|
|
if (expectedInput.substr(index, nBytesAvailable) != std::string(buf)) {
|
|
|
if (expectedInput.substr(index, nBytesAvailable) != std::string(buf)) {
|
|
|
RETURN_FALSE(" reader.read() failure");
|
|
|
RETURN_FALSE(" reader.read() failure");
|
|
|
}
|
|
|
}
|
|
|
index += nBytesAvailable;
|
|
|
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);
|
|
|
std::fill_n(buf, sizeof(buf), 0);
|
|
|
|
|
|
|
|
|
child.reader.read(buf, nBytesAvailable);
|
|
|
child.reader.read(buf, nBytesAvailable);
|
|
|
|
|
|
|
|
|
if (expectedInput.substr(index, nBytesAvailable) != std::string(buf)) {
|
|
|
if (expectedInput.substr(index, nBytesAvailable) != std::string(buf)) {
|
|
|
RETURN_FALSE(" reader.read() failure");
|
|
|
RETURN_FALSE(" reader.read() failure");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
index += nBytesAvailable;
|
|
|
index += nBytesAvailable;
|
|
|
|
|
|
|
|
|
if (expectedInput.size() != index) {
|
|
|
if (expectedInput.size() != index) {
|
|
|
RETURN_FALSE(" not all data was read by reader.read()");
|
|
|
RETURN_FALSE(" not all data was read by reader.read()");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
EXCEPTION_TERM("Non-blocking reader test");
|
|
|
EXCEPTION_TERM("Non-blocking reader test");
|
|
|
return false;
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
std::cout << "success. returning." << std::endl;//debug
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
return true;
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CodeDweller::Child child(childName);
|
|
|
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(testBinaryRead);
|
|
|
//RUN_TEST(testNonBlockingRead);
|
|
|
|
|
|
|
|
|
RUN_TEST(testNonBlockingRead);
|
|
|
|
|
|
|
|
|
SUMMARY;
|
|
|
SUMMARY;
|
|
|
|
|
|
|