Example #1
0
static void OutputTestData(const TestData &v)
{
	for (TestData::const_iterator i = v.begin(); i != v.end(); ++i)
	{
		cerr << i->first << ": " << i->second << endl;
	}
}
Example #2
0
void TestBtreeIteratorString()
{
  SmiKey leftBoundary("c");
  SmiKey leftBoundaryE("e");
  SmiKey rightBoundary("f");
  SmiKey farLeftBoundary("_");
  SmiKey farRightBoundary("zzz");
  
  TestData::iterator beginIter;
  TestData::iterator endIter;

  EnterTestFun();

  SmiKeyedFile* file = new SmiKeyedFile(SmiKey::String, false);
  tassert(file != 0);
  tassert(file->Create());
  
  PrefetchingIterator* piter;
  string str;  
  
  TestData testData;
  TestData::iterator iter;
  
  GenerateTestData(testData);
  
  for(iter = testData.begin(); iter != testData.end(); ++iter)
  {
    SmiKey key(iter->first);
    SmiRecord record;
    string s = iter->second;
    
    tassert(file->InsertRecord(key, record));
    tassert(record.Write(s.c_str(), s.size()) == s.size());
  }
    
  piter = file->SelectAllPrefetched();
  tassert(piter != 0);
  AssertIteratorsEqualString(piter, testData.begin(), testData.end());
  delete piter;  
    
  endIter = testData.lower_bound("ff");
  piter = file->SelectLeftRangePrefetched(rightBoundary);
  tassert(piter != 0);
  AssertIteratorsEqualString(piter, testData.begin(), endIter);
  delete piter;  

  beginIter = testData.find("c");
  piter = file->SelectRightRangePrefetched(leftBoundary);
  tassert(piter != 0);
  AssertIteratorsEqualString(piter, beginIter, testData.end());
  delete piter;  

  beginIter = testData.find("e");
  piter = file->SelectRightRangePrefetched(leftBoundaryE);
  tassert(piter != 0);
  AssertIteratorsEqualString(piter, beginIter, testData.end());
  delete piter;  

  beginIter = testData.find("c");
  endIter = testData.lower_bound("ff");
  piter = file->SelectRangePrefetched(leftBoundary, rightBoundary);
  tassert(piter != 0);
  AssertIteratorsEqualString(piter, beginIter, endIter);
  delete piter;  

  piter = file->SelectRangePrefetched(farLeftBoundary, farRightBoundary);
  tassert(piter != 0);
  AssertIteratorsEqualString(piter, testData.begin(), testData.end());
  delete piter;  

  beginIter = testData.find("c");
  piter = file->SelectRangePrefetched(leftBoundary, farRightBoundary);
  tassert(piter != 0);
  AssertIteratorsEqualString(piter, beginIter, testData.end());
  delete piter;  

  endIter = testData.lower_bound("ff");
  piter = file->SelectRangePrefetched(farLeftBoundary, rightBoundary);
  tassert(piter != 0);
  AssertIteratorsEqualString(piter, testData.begin(), endIter);
  delete piter;  

  piter = file->SelectRangePrefetched(SmiKey("__"), SmiKey("_____"));
  tassert(piter != 0);
  tassert(!piter->Next());
  delete piter;  
  
  piter = file->SelectRangePrefetched(SmiKey("yyy"), SmiKey("zzz"));
  tassert(piter != 0);
  tassert(!piter->Next());
  delete piter;  
    
  tassert(file->Close());
  tassert(file->Drop());
  delete file;
  file = 0;

  /* Test wether iterator also works correctly for empty files */
  file = new SmiKeyedFile(SmiKey::String, false);
  tassert(file != 0);
  tassert(file->Create());
  
  piter = file->SelectAllPrefetched();
  tassert(piter != 0);
  tassert(!piter->Next());
  delete piter;  
  tassert(file->Close());
  tassert(file->Drop());
  delete file;

  ExitTestFun(__PRETTY_FUNCTION__);
}
Example #3
0
void TestRecnoIterator()
{
  EnterTestFun();

  SmiRecordFile* file = new SmiRecordFile(false);
  tassert(file != 0);
  tassert(file->Create());
  
  PrefetchingIterator* piter;
  SmiRecordId id;
  string str;  
  set<SmiRecordId> createdIds;
  
  TestData testData;
  TestData::iterator iter;
  
  GenerateTestData(testData);
  
  for(iter = testData.begin(); iter != testData.end(); ++iter)
  {
    SmiRecord record;
    string s = iter->second;
    
    tassert(file->AppendRecord(id, record));
    tassert(record.Write(s.c_str(), s.size()) == s.size());
    createdIds.insert(id);
  }
  
  tassert(createdIds.size() == testData.size());
  
  piter = file->SelectAllPrefetched();
  tassert(piter != 0);
  AssertIteratorsEqualRecno(piter, testData.begin(), testData.end(), createdIds);
  delete piter;  
  
  tassert(file->DeleteRecord(*(createdIds.begin())));
  createdIds.erase(createdIds.begin());
  testData.erase(testData.begin());
  
  piter = file->SelectAllPrefetched();
  tassert(piter != 0);
  AssertIteratorsEqualRecno(piter, testData.begin(), testData.end(), createdIds);
  delete piter;  
  
  tassert(file->Close());
  tassert(file->Drop());
  delete file;
  file = 0;

  /* Test wether iterator also works correctly for empty files */
  file = new SmiRecordFile(false);
  tassert(file != 0);
  tassert(file->Create());
  
  piter = file->SelectAllPrefetched();
  tassert(piter != 0);
  tassert(!piter->Next());
  delete piter;  
  tassert(file->Close());
  tassert(file->Drop());
  delete file;

  ExitTestFun(__PRETTY_FUNCTION__);
}