void OW_EnumerationTestCases::testAllBig() { try { Enumeration<String> e; for (unsigned int i = 1; i <= bigLoopVal; i++) { e.addElement(String(i)); } for (unsigned int i = 0; i < bigLoopVal; ++i) { unitAssert(e.hasMoreElements()); unitAssert(e.numberOfElements() == bigLoopVal - i); String foo = e.nextElement(); unitAssert(foo == String(i + 1)); } unitAssert(!e.hasMoreElements()); unitAssert(e.numberOfElements() == 0); unitAssertThrows(e.nextElement()); } catch(Exception& e) { cerr << e << endl; throw; } }
void OW_EnumerationTestCases::testInsertIterator() { try { std::vector<String> as; for (unsigned int i = 1; i <= loopVal; i++) { as.push_back(String(i)); } Enumeration<String> e; std::copy(as.begin(), as.end(), Enumeration_insert_iterator<String>(e)); for (unsigned int i = 0; i < loopVal; ++i) { unitAssert(e.hasMoreElements()); unitAssert(e.numberOfElements() == loopVal - i); unitAssert(e.nextElement() == String(i + 1)); } unitAssert(!e.hasMoreElements()); unitAssert(e.numberOfElements() == 0); unitAssertThrows(e.nextElement()); } catch (Exception& e) { cout << e << endl; throw; } }
void OW_EnumerationTestCases::testQueueBig() { try { Enumeration<String> e; // now test it's queue like capabilities e.addElement("9"); for (unsigned int i = 10; i <= bigLoopVal; ++i) { e.addElement(String(i)); unitAssert(e.hasMoreElements()); unitAssert(e.numberOfElements() == 2); String foo = e.nextElement(); unitAssert(foo == String(i - 1)); } unitAssert(e.hasMoreElements()); unitAssert(e.numberOfElements() == 1); unitAssert(e.nextElement() == String(bigLoopVal)); unitAssert(!e.hasMoreElements()); unitAssert(e.numberOfElements() == 0); unitAssertThrows(e.nextElement()); } catch (Exception& e) { cout << e; throw; } }
void OW_EnumerationTestCases::testInputIterator() { try { Enumeration<String> e; for (unsigned int i = 1; i <= loopVal; i++) { e.addElement(String(i)); } std::vector<String> vec; std::copy(Enumeration_input_iterator<String>(e), // start of source Enumeration_input_iterator<String>(), // end of source std::back_inserter(vec)); // destination for (unsigned int i = 0; i < loopVal; ++i) { unitAssert(vec[i] == String(i + 1)); } unitAssert(!e.hasMoreElements()); unitAssert(e.numberOfElements() == 0); unitAssertThrows(e.nextElement()); } catch (Exception& e) { cout << e << endl; throw; } }
void OW_EnumerationTestCases::testReleaseFile() { String file; { Enumeration<String> e; e.addElement("5"); unitAssert(e.numberOfElements() == 1); e.addElement("a"); unitAssert(e.numberOfElements() == 2); unitAssert(!e.usingTempFile()); file = e.releaseFile(); unitAssert(file.length() > 0); unitAssert(e.numberOfElements() == 0); } Enumeration<String> e2(file); unitAssert(e2.numberOfElements() == 2); unitAssert(e2.nextElement() == String("5")); unitAssert(e2.numberOfElements() == 1); unitAssert(e2.nextElement() == String("a")); unitAssert(e2.numberOfElements() == 0); }
void OW_EnumerationTestCases::testCreation() { Enumeration<String> e; e.addElement("5"); unitAssert(e.numberOfElements() == 1); }