25 #include "boost/thread/thread.hpp" 26 #include "boost/thread/barrier.hpp" 37 if (
os_) cout <<
"Testing BinaryIndexStream (single thread)" << endl;
39 shared_ptr<stringstream> indexStreamPtr(
new stringstream);
43 vector<Index::Entry> entries;
44 for (
size_t i=0; i < 10; ++i)
50 entries.push_back(entry);
61 for (
size_t i=0; i < 10; ++i)
65 unit_assert(entryPtr->id == lexical_cast<string>(i));
69 entryPtr = index.
find(entryPtr->id);
71 unit_assert(entryPtr->id == lexical_cast<string>(i));
87 for (
size_t i=0; i < 10; ++i)
91 unit_assert(entryPtr->id == lexical_cast<string>(i));
95 entryPtr = index.
find(entryPtr->id);
97 unit_assert(entryPtr->id == lexical_cast<string>(i));
108 vector<Index::Entry> entries;
109 for (
size_t i=0; i < 5; ++i)
115 entries.push_back(entry);
124 for (
size_t i=0; i < 5; ++i)
128 unit_assert(entryPtr->id == lexical_cast<string>(i));
132 entryPtr = index.
find(entryPtr->id);
134 unit_assert(entryPtr->id == lexical_cast<string>(i));
152 for (
size_t i=0; i < 10; ++i)
156 unit_assert(entryPtr->id == lexical_cast<string>(i));
160 entryPtr = index.
find(entryPtr->id);
162 unit_assert(entryPtr->id == lexical_cast<string>(i));
172 cerr << e.what() << endl;
176 cerr <<
"Caught unknown exception." << endl;
182 if (
os_) cout <<
"Testing BinaryIndexStream (multithreaded)" << endl;
184 shared_ptr<stringstream> indexStreamPtr(
new stringstream);
187 vector<Index::Entry> entries;
188 for (
size_t i=0; i < 10; ++i)
194 entries.push_back(entry);
202 const int testThreadCount = 100;
203 boost::barrier testBarrier(testThreadCount);
204 boost::thread_group testThreadGroup;
205 for (
int i=0; i < testThreadCount; ++i)
207 testThreadGroup.join_all();
211 int main(
int argc,
char* argv[])
217 if (argc>1 && !strcmp(argv[1],
"-v"))
os_ = &cout;
virtual size_t size() const
returns the number of entries in the index
boost::shared_ptr< Entry > EntryPtr
float lexical_cast(const std::string &str)
index implementation in a stream (intended for fstreams but any iostream works); find(string id) is O...
int main(int argc, char *argv[])
virtual EntryPtr find(const std::string &id) const
returns the entry for the specified string id, or null if the id is not in the index ...
virtual void create(std::vector< Entry > &entries)
create the index from specified list of entries; the list is non-const because the index implementati...
boost::iostreams::stream_offset stream_offset
#define TEST_PROLOG(argc, argv)
generic type identifying an indexed item by string id, ordinal index, and stream offset ...
void testThreadSafetyWorker(boost::barrier *testBarrier, BinaryIndexStream *testIndex)