aboutsummaryrefslogtreecommitdiffstats
path: root/searchsummary/src/tests/docsumformat/docsum-pack.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'searchsummary/src/tests/docsumformat/docsum-pack.cpp')
-rw-r--r--searchsummary/src/tests/docsumformat/docsum-pack.cpp306
1 files changed, 56 insertions, 250 deletions
diff --git a/searchsummary/src/tests/docsumformat/docsum-pack.cpp b/searchsummary/src/tests/docsumformat/docsum-pack.cpp
index 7a9834e3fd8..18b38db3fa1 100644
--- a/searchsummary/src/tests/docsumformat/docsum-pack.cpp
+++ b/searchsummary/src/tests/docsumformat/docsum-pack.cpp
@@ -10,7 +10,6 @@ LOG_SETUP("docsum-pack");
using namespace search::docsummary;
-
// needed to resolve external symbol from httpd.h on AIX
void FastS_block_usr2() {}
@@ -20,8 +19,8 @@ class MyApp : public FastOS_Application
private:
bool _rc;
uint32_t _cnt;
- search::docsummary::ResultConfig _config;
- search::docsummary::ResultPacker _packer;
+ ResultConfig _config;
+ ResultPacker _packer;
public:
MyApp();
@@ -33,33 +32,18 @@ public:
{ ReportTestResult(line, rc); return rc; }
// compare runtime info (,but ignore result class)
- bool Equal(search::docsummary::ResEntry *a, search::docsummary::ResEntry *b);
- bool Equal(search::docsummary::GeneralResult *a, search::docsummary::GeneralResult *b);
-
- void TestFieldIndex(uint32_t line, search::docsummary::GeneralResult *gres,
- const char *field, int idx);
-
- void TestIntValue(uint32_t line, search::docsummary::GeneralResult *gres,
- const char *field, uint32_t value);
-
- void TestDoubleValue(uint32_t line, search::docsummary::GeneralResult *gres,
- const char *field, double value);
+ bool Equal(ResEntry *a, ResEntry *b);
+ bool Equal(GeneralResult *a, GeneralResult *b);
- void TestInt64Value(uint32_t line, search::docsummary::GeneralResult *gres,
- const char *field, uint64_t value);
+ void TestIntValue(uint32_t line, GeneralResult *gres, const char *field, uint32_t value);
+ void TestDoubleValue(uint32_t line, GeneralResult *gres, const char *field, double value);
+ void TestInt64Value(uint32_t line, GeneralResult *gres, const char *field, uint64_t value);
+ void TestStringValue(uint32_t line, GeneralResult *gres, const char *field, const char *value);
+ void TestDataValue(uint32_t line, GeneralResult *gres, const char *field, const char *value);
- void TestStringValue(uint32_t line, search::docsummary::GeneralResult *gres,
- const char *field, const char *value);
-
- void TestDataValue(uint32_t line, search::docsummary::GeneralResult *gres,
- const char *field, const char *value);
-
- void TestBasic();
void TestFailLong();
void TestFailShort();
void TestFailOrder();
- void TestCompress();
- void TestCompat();
void TestBasicInplace();
void TestCompressInplace();
@@ -72,7 +56,8 @@ MyApp::MyApp()
_config(),
_packer(&_config)
{}
-MyApp::~MyApp() {}
+
+MyApp::~MyApp() = default;
void
MyApp::ReportTestResult(uint32_t line, bool rc)
@@ -89,7 +74,7 @@ MyApp::ReportTestResult(uint32_t line, bool rc)
bool
-MyApp::Equal(search::docsummary::ResEntry *a, search::docsummary::ResEntry *b)
+MyApp::Equal(ResEntry *a, ResEntry *b)
{
if (a->_type != b->_type)
return false;
@@ -106,7 +91,7 @@ MyApp::Equal(search::docsummary::ResEntry *a, search::docsummary::ResEntry *b)
bool
-MyApp::Equal(search::docsummary::GeneralResult *a, search::docsummary::GeneralResult *b)
+MyApp::Equal(GeneralResult *a, GeneralResult *b)
{
uint32_t numEntries = a->GetClass()->GetNumEntries();
@@ -125,56 +110,36 @@ MyApp::Equal(search::docsummary::GeneralResult *a, search::docsummary::GeneralRe
return true;
}
-
-void
-MyApp::TestFieldIndex(uint32_t line, search::docsummary::GeneralResult *gres,
- const char *field, int idx)
-{
- bool rc = (gres != NULL &&
- gres->GetClass()->GetIndexFromName(field) == idx);
-
- RTR(line, rc);
-}
-
-
void
-MyApp::TestIntValue(uint32_t line, search::docsummary::GeneralResult *gres,
- const char *field, uint32_t value)
+MyApp::TestIntValue(uint32_t line, GeneralResult *gres, const char *field, uint32_t value)
{
- search::docsummary::ResEntry *entry
- = (gres != NULL) ? gres->GetEntry(field) : NULL;
+ ResEntry *entry = (gres != nullptr) ? gres->GetEntry(field) : nullptr;
- bool rc = (entry != NULL &&
+ bool rc = (entry != nullptr &&
entry->_type == RES_INT &&
entry->_intval == value);
RTR(line, rc);
}
-
void
-MyApp::TestDoubleValue(uint32_t line, search::docsummary::GeneralResult *gres,
- const char *field, double value)
+MyApp::TestDoubleValue(uint32_t line, GeneralResult *gres, const char *field, double value)
{
- search::docsummary::ResEntry *entry
- = (gres != NULL) ? gres->GetEntry(field) : NULL;
+ ResEntry *entry = (gres != nullptr) ? gres->GetEntry(field) : nullptr;
- bool rc = (entry != NULL &&
+ bool rc = (entry != nullptr &&
entry->_type == RES_DOUBLE &&
entry->_doubleval == value);
RTR(line, rc);
}
-
void
-MyApp::TestInt64Value(uint32_t line, search::docsummary::GeneralResult *gres,
- const char *field, uint64_t value)
+MyApp::TestInt64Value(uint32_t line, GeneralResult *gres, const char *field, uint64_t value)
{
- search::docsummary::ResEntry *entry
- = (gres != NULL) ? gres->GetEntry(field) : NULL;
+ ResEntry *entry = (gres != nullptr) ? gres->GetEntry(field) : nullptr;
- bool rc = (entry != NULL &&
+ bool rc = (entry != nullptr &&
entry->_type == RES_INT64 &&
entry->_int64val == value);
@@ -183,36 +148,29 @@ MyApp::TestInt64Value(uint32_t line, search::docsummary::GeneralResult *gres,
void
-MyApp::TestStringValue(uint32_t line, search::docsummary::GeneralResult *gres,
- const char *field, const char *value)
+MyApp::TestStringValue(uint32_t line, GeneralResult *gres, const char *field, const char *value)
{
- search::docsummary::ResEntry *entry
- = (gres != NULL) ? gres->GetEntry(field) : NULL;
+ ResEntry *entry = (gres != nullptr) ? gres->GetEntry(field) : nullptr;
- bool rc = (entry != NULL &&
+ bool rc = (entry != nullptr &&
entry->_type == RES_STRING &&
entry->_stringlen == strlen(value) &&
strncmp(entry->_stringval, value, entry->_stringlen) == 0);
- if (!rc && entry != NULL) {
- LOG(warning,
- "string value '%.*s' != '%s'",
- (int) entry->_stringlen,
- entry->_stringval, value);
+ if (!rc && entry != nullptr) {
+ LOG(warning,"string value '%.*s' != '%s'",
+ (int) entry->_stringlen, entry->_stringval, value);
}
RTR(line, rc);
}
-
void
-MyApp::TestDataValue(uint32_t line, search::docsummary::GeneralResult *gres,
- const char *field, const char *value)
+MyApp::TestDataValue(uint32_t line, GeneralResult *gres, const char *field, const char *value)
{
- search::docsummary::ResEntry *entry
- = (gres != NULL) ? gres->GetEntry(field) : NULL;
+ ResEntry *entry = (gres != nullptr) ? gres->GetEntry(field) : nullptr;
- bool rc = (entry != NULL &&
+ bool rc = (entry != nullptr &&
entry->_type == RES_DATA &&
entry->_datalen == strlen(value) &&
strncmp(entry->_dataval, value, entry->_datalen) == 0);
@@ -220,62 +178,6 @@ MyApp::TestDataValue(uint32_t line, search::docsummary::GeneralResult *gres,
RTR(line, rc);
}
-
-void
-MyApp::TestBasic()
-{
- const char *buf;
- uint32_t buflen;
-
- search::docsummary::urlresult *res;
- search::docsummary::GeneralResult *gres;
-
- uint32_t intval = 4;
- uint16_t shortval = 2;
- uint8_t byteval = 1;
- float floatval = 4.5;
- double doubleval = 8.75;
- uint64_t int64val = 8;
- const char *strval = "This is a string";
- const char *datval = "This is data";
- const char *lstrval = "This is a long string";
- const char *ldatval = "This is long data";
-
- RTR(__LINE__, _packer.Init(0));
- RTR(__LINE__, _packer.AddInteger(intval));
- RTR(__LINE__, _packer.AddShort(shortval));
- RTR(__LINE__, _packer.AddByte(byteval));
- RTR(__LINE__, _packer.AddFloat(floatval));
- RTR(__LINE__, _packer.AddDouble(doubleval));
- RTR(__LINE__, _packer.AddInt64(int64val));
- RTR(__LINE__, _packer.AddString(strval, strlen(strval)));
- RTR(__LINE__, _packer.AddData(datval, strlen(datval)));
- RTR(__LINE__, _packer.AddLongString(lstrval, strlen(lstrval)));
- RTR(__LINE__, _packer.AddLongData(ldatval, strlen(ldatval)));
- RTR(__LINE__, _packer.GetDocsumBlob(&buf, &buflen));
-
- res = _config.Unpack(0, 0, 0, buf, buflen);
- gres = res->IsGeneral() ? (search::docsummary::GeneralResult *) res : NULL;
-
- RTR(__LINE__, gres != NULL);
- TestIntValue (__LINE__, gres, "integer", 4);
- TestIntValue (__LINE__, gres, "short", 2);
- TestIntValue (__LINE__, gres, "byte", 1);
- TestDoubleValue(__LINE__, gres, "float", floatval);
- TestDoubleValue(__LINE__, gres, "double", doubleval);
- TestInt64Value (__LINE__, gres, "int64", int64val);
- TestStringValue(__LINE__, gres, "string", strval);
- TestDataValue (__LINE__, gres, "data", datval);
- TestStringValue(__LINE__, gres, "longstring", lstrval);
- TestDataValue (__LINE__, gres, "longdata", ldatval);
- RTR(__LINE__, (gres != NULL &&
- gres->GetClass()->GetNumEntries() == 10));
- RTR(__LINE__, (gres != NULL &&
- gres->GetClass()->GetClassID() == 0));
- delete res;
-}
-
-
void
MyApp::TestFailLong()
{
@@ -308,7 +210,6 @@ MyApp::TestFailLong()
RTR(__LINE__, !_packer.GetDocsumBlob(&buf, &buflen));
}
-
void
MyApp::TestFailShort()
{
@@ -371,95 +272,6 @@ MyApp::TestFailOrder()
}
-void
-MyApp::TestCompress()
-{
- const char *buf;
- uint32_t buflen;
-
- search::docsummary::urlresult *res;
- search::docsummary::GeneralResult *gres;
-
- const char *lstrval = "string string string";
- const char *ldatval = "data data data";
-
- RTR(__LINE__, _packer.Init(2));
- RTR(__LINE__, _packer.AddLongString(lstrval, strlen(lstrval)));
- RTR(__LINE__, _packer.AddLongData(ldatval, strlen(ldatval)));
- RTR(__LINE__, _packer.GetDocsumBlob(&buf, &buflen));
-
- res = _config.Unpack(0, 0, 0, buf, buflen);
- gres = res->IsGeneral() ? (search::docsummary::GeneralResult *) res : NULL;
-
- RTR(__LINE__, gres != NULL);
- TestStringValue(__LINE__, gres, "text", lstrval);
- TestDataValue (__LINE__, gres, "data", ldatval);
- RTR(__LINE__, (gres != NULL &&
- gres->GetClass()->GetNumEntries() == 2));
- RTR(__LINE__, (gres != NULL &&
- gres->GetClass()->GetClassID() == 2));
- delete res;
-}
-
-
-void
-MyApp::TestCompat()
-{
- const char *buf;
- uint32_t buflen;
-
- search::docsummary::urlresult *res1;
- search::docsummary::GeneralResult *gres1;
-
- search::docsummary::urlresult *res2;
- search::docsummary::GeneralResult *gres2;
-
- const char *strval = "string string string string";
- const char *datval = "data data data data";
-
- RTR(__LINE__, _packer.Init(1));
- RTR(__LINE__, _packer.AddData(strval, strlen(strval)));
- RTR(__LINE__, _packer.AddString(datval, strlen(datval)));
- RTR(__LINE__, _packer.GetDocsumBlob(&buf, &buflen));
- res1 = _config.Unpack(0, 0, 0, buf, buflen);
- gres1 = res1->IsGeneral() ? (search::docsummary::GeneralResult *) res1 : NULL;
-
- RTR(__LINE__, _packer.Init(2));
- RTR(__LINE__, _packer.AddLongData(strval, strlen(strval)));
- RTR(__LINE__, _packer.AddLongString(datval, strlen(datval)));
- RTR(__LINE__, _packer.GetDocsumBlob(&buf, &buflen));
- res2 = _config.Unpack(0, 0, 0, buf, buflen);
- gres2 = res2->IsGeneral() ? (search::docsummary::GeneralResult *) res2 : NULL;
-
- RTR(__LINE__, gres1 != NULL);
- RTR(__LINE__, gres2 != NULL);
-
- TestStringValue(__LINE__, gres1, "text", strval);
- TestDataValue (__LINE__, gres1, "data", datval);
- TestFieldIndex (__LINE__, gres1, "text", 0);
- TestFieldIndex (__LINE__, gres1, "data", 1);
- RTR(__LINE__, (gres1 != NULL &&
- gres1->GetClass()->GetNumEntries() == 2));
-
- TestStringValue(__LINE__, gres2, "text", strval);
- TestDataValue (__LINE__, gres2, "data", datval);
- TestFieldIndex (__LINE__, gres2, "text", 0);
- TestFieldIndex (__LINE__, gres2, "data", 1);
- RTR(__LINE__, (gres2 != NULL &&
- gres2->GetClass()->GetNumEntries() == 2));
-
- RTR(__LINE__, (gres1 != NULL &&
- gres1->GetClass()->GetClassID() == 1));
- RTR(__LINE__, (gres2 != NULL &&
- gres2->GetClass()->GetClassID() == 2));
-
- RTR(__LINE__, (gres1 != NULL && gres2 != NULL &&
- Equal(gres1, gres2)));
-
- delete res1;
- delete res2;
-}
-
void
MyApp::TestBasicInplace()
@@ -467,8 +279,8 @@ MyApp::TestBasicInplace()
const char *buf;
uint32_t buflen;
- const search::docsummary::ResultClass *resClass;
- search::docsummary::GeneralResult *gres;
+ const ResultClass *resClass;
+ GeneralResult *gres;
uint32_t intval = 4;
uint16_t shortval = 2;
@@ -495,18 +307,18 @@ MyApp::TestBasicInplace()
RTR(__LINE__, _packer.GetDocsumBlob(&buf, &buflen));
resClass = _config.LookupResultClass(_config.GetClassID(buf, buflen));
- if (resClass == NULL) {
- gres = NULL;
+ if (resClass == nullptr) {
+ gres = nullptr;
} else {
DocsumStoreValue value(buf, buflen);
- gres = new search::docsummary::GeneralResult(resClass, 0, 0, 0);
+ gres = new GeneralResult(resClass);
if (!gres->inplaceUnpack(value)) {
delete gres;
- gres = NULL;
+ gres = nullptr;
}
}
- RTR(__LINE__, gres != NULL);
+ RTR(__LINE__, gres != nullptr);
TestIntValue (__LINE__, gres, "integer", 4);
TestIntValue (__LINE__, gres, "short", 2);
TestIntValue (__LINE__, gres, "byte", 1);
@@ -517,9 +329,9 @@ MyApp::TestBasicInplace()
TestDataValue (__LINE__, gres, "data", datval);
TestStringValue(__LINE__, gres, "longstring", lstrval);
TestDataValue (__LINE__, gres, "longdata", ldatval);
- RTR(__LINE__, (gres != NULL &&
+ RTR(__LINE__, (gres != nullptr &&
gres->GetClass()->GetNumEntries() == 10));
- RTR(__LINE__, (gres != NULL &&
+ RTR(__LINE__, (gres != nullptr &&
gres->GetClass()->GetClassID() == 0));
delete gres;
}
@@ -533,8 +345,8 @@ MyApp::TestCompressInplace()
search::RawBuf field1(32768);
search::RawBuf field2(32768);
- const search::docsummary::ResultClass *resClass;
- search::docsummary::GeneralResult *gres;
+ const ResultClass *resClass;
+ GeneralResult *gres;
const char *lstrval = "string string string";
const char *ldatval = "data data data";
@@ -545,48 +357,46 @@ MyApp::TestCompressInplace()
RTR(__LINE__, _packer.GetDocsumBlob(&buf, &buflen));
resClass = _config.LookupResultClass(_config.GetClassID(buf, buflen));
- if (resClass == NULL) {
- gres = NULL;
+ if (resClass == nullptr) {
+ gres = nullptr;
} else {
DocsumStoreValue value(buf, buflen);
- gres = new search::docsummary::GeneralResult(resClass, 0, 0, 0);
+ gres = new GeneralResult(resClass);
if (!gres->inplaceUnpack(value)) {
delete gres;
- gres = NULL;
+ gres = nullptr;
}
}
- search::docsummary::ResEntry *e1 = (gres == NULL) ? NULL : gres->GetEntry("text");
- search::docsummary::ResEntry *e2 = (gres == NULL) ? NULL : gres->GetEntry("data");
+ ResEntry *e1 = (gres == nullptr) ? nullptr : gres->GetEntry("text");
+ ResEntry *e2 = (gres == nullptr) ? nullptr : gres->GetEntry("data");
- if (e1 != NULL)
+ if (e1 != nullptr)
e1->_extract_field(&field1);
- if (e2 != NULL)
+ if (e2 != nullptr)
e2->_extract_field(&field2);
- RTR(__LINE__, gres != NULL);
- RTR(__LINE__, e1 != NULL);
- RTR(__LINE__, e2 != NULL);
+ RTR(__LINE__, gres != nullptr);
+ RTR(__LINE__, e1 != nullptr);
+ RTR(__LINE__, e2 != nullptr);
RTR(__LINE__, strcmp(field1.GetDrainPos(), lstrval) == 0);
RTR(__LINE__, strcmp(field2.GetDrainPos(), ldatval) == 0);
RTR(__LINE__, strlen(lstrval) == field1.GetUsedLen());
RTR(__LINE__, strlen(ldatval) == field2.GetUsedLen());
- RTR(__LINE__, (gres != NULL &&
+ RTR(__LINE__, (gres != nullptr &&
gres->GetClass()->GetNumEntries() == 2));
- RTR(__LINE__, (gres != NULL &&
+ RTR(__LINE__, (gres != nullptr &&
gres->GetClass()->GetClassID() == 2));
delete gres;
}
-
-
int
MyApp::Main()
{
_rc = true;
_cnt = 0;
- search::docsummary::ResultClass *resClass;
+ ResultClass *resClass;
resClass = _config.AddResultClass("c0", 0);
resClass->AddConfigEntry("integer", RES_INT);
@@ -608,12 +418,9 @@ MyApp::Main()
resClass->AddConfigEntry("text", RES_LONG_STRING);
resClass->AddConfigEntry("data", RES_LONG_DATA);
- TestBasic();
TestFailLong();
TestFailShort();
TestFailOrder();
- TestCompress();
- TestCompat();
TestBasicInplace();
TestCompressInplace();
@@ -621,7 +428,6 @@ MyApp::Main()
return (_rc ? 0 : 1);
}
-
int
main(int argc, char **argv)
{