void testRead() { if (os_) *os_ << "testRead()\n"; ReaderList readers; readers.push_back(ReaderPtr(new Reader1)); readers.push_back(ReaderPtr(new Reader2)); TraData td; // note: composite pattern with accept/read will cause two calls // to accept(); the alternative is to maintain state between accept() // and read(), which opens possibility for misuse. unit_assert(readers.get<Reader1>()->config.done == false); if (readers.accept("1", "head")) readers.read("1", "head", td); unit_assert(readers.get<Reader1>()->config.done == true); readers.get<Reader1>()->config.done = false; unit_assert(readers.get<Reader2>()->config.done == false); if (readers.accept("2", "head")) readers.read("2", "head", td); unit_assert(readers.get<Reader1>()->config.done == false); unit_assert(readers.get<Reader2>()->config.done == true); if (os_) *os_ << endl; }
void testAccept() { if (os_) *os_ << "testAccept()\n"; ReaderList readers; readers.push_back(ReaderPtr(new Reader1)); readers.push_back(ReaderPtr(new Reader2)); if (os_) *os_ << "accept 1:\n"; unit_assert(readers.accept("1", "head")); if (os_) *os_ << "accept 2:\n"; unit_assert(readers.accept("2", "head")); if (os_) *os_ << "accept 3:\n"; unit_assert(!readers.accept("3", "head")); if (os_) *os_ << endl; }