1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
#include "M6Lib.h"
#include <iostream>
#include <boost/test/unit_test.hpp>
#include <boost/format.hpp>
#include <boost/algorithm/string.hpp>
#include "M6Builder.h"
#include "M6Databank.h"
#include "M6Document.h"
using namespace std;
namespace ba = boost::algorithm;
BOOST_AUTO_TEST_CASE(test_build_1)
{
cout << "test building databanks - 1" << endl;
unique_ptr<M6Databank> databank(M6Databank::CreateNew("test/test-db.m6"));
M6Lexicon lexicon;
databank->StartBatchImport(lexicon);
boost::format idFmt("ID_%05.5d");
for (uint32 i = 1; i <= 1000; ++i)
{
string id = (idFmt % i).str();
M6InputDocument* doc = new M6InputDocument(*databank, id);
doc->SetAttribute("id", id);
ba::to_lower(id);
doc->IndexText("id", eM6ValueIndex, id, false);
doc->Tokenize(lexicon, 0);
databank->Store(doc);
}
databank->CommitBatchImport();
}
BOOST_AUTO_TEST_CASE(test_build_2)
{
cout << "test building databanks - 2" << endl;
M6Databank databank("test/test-db.m6", eReadOnly);
BOOST_CHECK_EQUAL(databank.size(), 1000);
boost::format idFmt("ID_%05.5d");
for (uint32 i = 1; i <= databank.size(); ++i)
{
string id = (idFmt % i).str();
M6Document* doc = databank.Fetch(i);
BOOST_CHECK(doc != nullptr);
if (doc == nullptr)
continue;
BOOST_CHECK_EQUAL(doc->GetAttribute("id"), id);
BOOST_CHECK_EQUAL(doc->GetText(), id);
delete doc;
}
}
BOOST_AUTO_TEST_CASE(test_build_3)
{
cout << "test building databanks - 3" << endl;
M6Databank databank("test/test-db.m6", eReadOnly);
BOOST_CHECK_EQUAL(databank.size(), 1000);
boost::format idFmt("ID_%05.5d");
for (uint32 i = 1; i <= databank.size(); ++i)
{
string id = (idFmt % i).str();
M6Document* doc = databank.FindDocument("id", id);
BOOST_CHECK(doc != nullptr);
if (doc == nullptr)
continue;
BOOST_CHECK_EQUAL(doc->GetAttribute("id"), id);
BOOST_CHECK_EQUAL(doc->GetText(), id);
delete doc;
}
}
BOOST_AUTO_TEST_CASE(test_build_4)
{
cout << "testing builder (pdbfinder 1)" << endl;
M6Builder builder("pdbfinder");
builder.Build();
}
|