#include <orderedlist_test.h>
Protected Member Functions | |
void | append (const Object::Info *type) |
void | insertingAndRemoving (const Object::Info *type) |
There are no actual unit tests in OrderedList_test that the googletest framework will recognize and execute automatically. The googletest framework doesn't provide an elegant solution for testing the compliance of derived classes. This class is sub-classed by OrderedLinkedList_test and OrderedArrayList_test in order to re-use common unit test code.
void container_test::OrderedList_test::append | ( | const Object::Info * | type | ) | [protected] |
00051 { 00052 // Null check, probably not necessary, but I'm just trying to figure 00053 // out this new framework. 00054 OrderedList* a = orderedListFactory(type); 00055 00056 cout << "List a is empty" << endl; 00057 cout << " " << a << endl; 00058 EXPECT_TRUE(a->isEmpty()); 00059 00060 Entity* e1 = new Entity(); 00061 a->append(e1); 00062 cout << "List a has one item." << endl; 00063 cout << " " << a << endl; 00064 EXPECT_FALSE(a->isEmpty()); 00065 00066 delete a; 00067 }
void container_test::OrderedList_test::insertingAndRemoving | ( | const Object::Info * | type | ) | [protected] |
00069 { 00070 OrderedList* a = orderedListFactory(type); 00071 00072 const int LIST_SIZE = 5; 00073 Entity ** data; 00074 generateDataAndPopulateList(data, a, LIST_SIZE, true); 00075 00076 EXPECT_TRUE(a->toFirst()); 00077 cout << "Iterating from first to last." << endl; 00078 for (int i = 0; !a->isTail(); i++ + a->toNext()) { 00079 cout << " node[" << i << "] contains: " << *a->currentEntity() << endl; 00080 EXPECT_EQ(data[i], a->currentEntity()); 00081 EXPECT_TRUE(data[i] == a->currentEntity()); 00082 verifyNonEmptyStateCoherence_notTail(*a, LIST_SIZE); 00083 } 00084 verifyNonEmptyStateCoherence_tail(*a, LIST_SIZE); 00085 00086 cout << "Iterating from last to first." << endl; 00087 for (int i = (LIST_SIZE - 1); a->toPrev(); i--) { 00088 cout << " node[" << i << "] contains: " << *a->currentEntity() << endl; 00089 EXPECT_EQ(data[i], a->currentEntity()); 00090 EXPECT_TRUE(data[i]->compareKeyTo(*a->currentEntity()) == 0); 00091 verifyNonEmptyStateCoherence_notTail(*a, LIST_SIZE); 00092 } 00093 EXPECT_TRUE(a->isFirst()); 00094 verifyNonEmptyStateCoherence_notTail(*a, LIST_SIZE); 00095 00096 cout << "Extracting from first to last." << endl; 00097 int index = 0; 00098 do { 00099 Entity *e = a->extractCurrentEntity(); 00100 cout << " extracted " << *e << endl; 00101 cout << " " << a << endl; 00102 EXPECT_EQ(data[index], e); 00103 EXPECT_TRUE(data[index]->compareKeyTo(*e) == 0); 00104 if (index < (LIST_SIZE - 1)) { 00105 verifyNonEmptyStateCoherence_notTail(*a, LIST_SIZE - index - 1); 00106 } else { 00107 verifyEmptyStateCoherence(*a); 00108 } 00109 index++; 00110 } while (!a->isTail()); 00111 00112 cout << "Repopulating same list with extracted Entities" << endl; 00113 cout << " " << a << endl; 00114 for (int i = 0; i < LIST_SIZE; i++) { 00115 a->insertBefore(data[i]); // should work the same as append() in this case 00116 cout << " After insertBefore() " << *data[i] << endl; 00117 cout << " " << a << endl; 00118 verifyNonEmptyStateCoherence_tail(*a, i + 1); 00119 } 00120 00121 cout << "Deleting from first to last." << endl; 00122 index = 0; 00123 a->toFirst(); 00124 do { 00125 EXPECT_EQ(data[index], a->currentEntity()); 00126 EXPECT_TRUE(a->deleteCurrent()); 00127 cout << " deleteCurrent()" << endl; 00128 cout << " " << a << endl; 00129 if (index < (LIST_SIZE - 1)) { 00130 verifyNonEmptyStateCoherence_notTail(*a, LIST_SIZE - index - 1); 00131 } else { 00132 verifyEmptyStateCoherence(*a); 00133 } 00134 index++; 00135 } while (!a->isTail()); 00136 00137 delete a; 00138 delete data; 00139 }