summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/common/Configuration.cpp16
-rw-r--r--lib/common/Configuration.h9
-rw-r--r--lib/common/ExcludeList.cpp11
-rw-r--r--test/common/testcommon.cpp164
4 files changed, 118 insertions, 82 deletions
diff --git a/lib/common/Configuration.cpp b/lib/common/Configuration.cpp
index f49f3c6e..8ce8d389 100644
--- a/lib/common/Configuration.cpp
+++ b/lib/common/Configuration.cpp
@@ -34,6 +34,8 @@ inline bool iw(int c)
static const char *sValueBooleanStrings[] = {"yes", "true", "no", "false", 0};
static const bool sValueBooleanValue[] = {true, true, false, false};
+const ConfigurationCategory ConfigurationVerify::VERIFY_ERROR("VerifyError");
+
ConfigurationVerifyKey::ConfigurationVerifyKey
(
std::string name,
@@ -212,8 +214,8 @@ std::auto_ptr<Configuration> Configuration::LoadAndVerify(
if(!rErrorMsg.empty())
{
// An error occured, return now
- BOX_ERROR("Error in Configuration::LoadInto: " <<
- rErrorMsg);
+ BOX_LOG_CATEGORY(Log::ERROR, ConfigurationVerify::VERIFY_ERROR,
+ "Error in Configuration::LoadInto: " << rErrorMsg);
return std::auto_ptr<Configuration>(0);
}
@@ -222,8 +224,11 @@ std::auto_ptr<Configuration> Configuration::LoadAndVerify(
{
if(!apConfig->Verify(*pVerify, std::string(), rErrorMsg))
{
- BOX_ERROR("Error verifying configuration: " <<
- rErrorMsg);
+ BOX_LOG_CATEGORY(Log::ERROR,
+ ConfigurationVerify::VERIFY_ERROR,
+ "Error verifying configuration: " <<
+ rErrorMsg.substr(0, rErrorMsg.size() > 0
+ ? rErrorMsg.size() - 1 : 0));
return std::auto_ptr<Configuration>(0);
}
}
@@ -425,7 +430,8 @@ const std::string &Configuration::GetKeyValue(const std::string& rKeyName) const
if(i == mKeys.end())
{
- BOX_ERROR("Missing configuration key: " << rKeyName);
+ BOX_LOG_CATEGORY(Log::ERROR, ConfigurationVerify::VERIFY_ERROR,
+ "Missing configuration key: " << rKeyName);
THROW_EXCEPTION(CommonException, ConfigNoKey)
}
else
diff --git a/lib/common/Configuration.h b/lib/common/Configuration.h
index 4828b315..e6498e80 100644
--- a/lib/common/Configuration.h
+++ b/lib/common/Configuration.h
@@ -27,6 +27,14 @@ enum
ConfigTest_IsBool = 32
};
+class ConfigurationCategory : public Log::Category
+{
+ public:
+ ConfigurationCategory(const std::string& name)
+ : Log::Category(std::string("Configuration/") + name)
+ { }
+};
+
class ConfigurationVerifyKey
{
public:
@@ -75,6 +83,7 @@ public:
const ConfigurationVerifyKey *mpKeys;
int Tests;
void *TestFunction; // set to zero for now, will implement later
+ static const ConfigurationCategory VERIFY_ERROR;
};
class FdGetLine;
diff --git a/lib/common/ExcludeList.cpp b/lib/common/ExcludeList.cpp
index 213c4f8e..f101782a 100644
--- a/lib/common/ExcludeList.cpp
+++ b/lib/common/ExcludeList.cpp
@@ -139,9 +139,10 @@ void ExcludeList::AddDefiniteEntries(const std::string &rEntries)
if (entry.size() > 0 && entry[entry.size() - 1] ==
DIRECTORY_SEPARATOR_ASCHAR)
{
- BOX_WARNING("Exclude entry ends in path "
- "separator, will never match: "
- << entry);
+ BOX_LOG_CATEGORY(Log::WARNING,
+ ConfigurationVerify::VERIFY_ERROR,
+ "Exclude entry ends in path separator, "
+ "will never match: " << entry);
}
mDefinite.insert(entry);
@@ -198,7 +199,9 @@ void ExcludeList::AddRegexEntries(const std::string &rEntries)
{
char buf[1024];
regerror(errcode, pregex, buf, sizeof(buf));
- BOX_ERROR("Invalid regular expression: " <<
+ BOX_LOG_CATEGORY(Log::ERROR,
+ ConfigurationVerify::VERIFY_ERROR,
+ "Invalid regular expression: " <<
entry << ": " << buf);
THROW_EXCEPTION(CommonException, BadRegularExpression)
}
diff --git a/test/common/testcommon.cpp b/test/common/testcommon.cpp
index 2f97b4e0..076099ad 100644
--- a/test/common/testcommon.cpp
+++ b/test/common/testcommon.cpp
@@ -160,8 +160,9 @@ class TestLogger : public Logger
bool IsTriggered() { return mTriggered; }
void Reset() { mTriggered = false; }
- virtual bool Log(Log::Level level, const std::string& rFile,
- int line, std::string& rMessage)
+ virtual bool Log(Log::Level level, const std::string& file, int line,
+ const std::string& function, const Log::Category& category,
+ const std::string& message)
{
if (level == mTargetLevel)
{
@@ -407,20 +408,18 @@ int test(int argc, const char *argv[])
DIRECTORY_SEPARATOR "fdgetlinetest.txt");
FdGetLine getline(file);
- int l = 0;
- while(testfilelines[l] != 0)
- {
- TEST_THAT(!getline.IsEOF());
- std::string line = getline.GetLine(true);
- printf("expected |%s| got |%s|\n", testfilelines[l],
- line.c_str());
- TEST_LINE(strcmp(testfilelines[l], line.c_str()) == 0,
- line);
- l++;
- }
- TEST_THAT(getline.IsEOF());
- TEST_CHECK_THROWS(getline.GetLine(true), CommonException, GetLineEOF);
+ int l = 0;
+ while(testfilelines[l] != 0)
+ {
+ TEST_THAT(!getline.IsEOF());
+ std::string line = getline.GetLine(true);
+ TEST_EQUAL(testfilelines[l], line);
+ l++;
+ }
+ TEST_THAT(getline.IsEOF());
+ TEST_CHECK_THROWS(getline.GetLine(true), CommonException, GetLineEOF);
}
+
// and again without pre-processing
{
FileHandleGuard<O_RDONLY> file("testfiles"
@@ -430,7 +429,7 @@ int test(int argc, const char *argv[])
TEST_THAT_ABORTONFAIL(file2 != 0);
FdGetLine getline(file);
char ll[512];
-
+
while(!feof(file2))
{
fgets(ll, sizeof(ll), file2);
@@ -440,40 +439,38 @@ int test(int argc, const char *argv[])
e--;
}
ll[e] = '\0';
-
- TEST_THAT(!getline.IsEOF());
- std::string line = getline.GetLine(false);
- //printf("expected |%s| got |%s|\n", ll, line.c_str());
- TEST_THAT(strcmp(ll, line.c_str()) == 0);
+
+ TEST_THAT(!getline.IsEOF());
+ std::string line = getline.GetLine(false);
+ TEST_EQUAL(ll, line);
}
- TEST_THAT(getline.IsEOF());
- TEST_CHECK_THROWS(getline.GetLine(true), CommonException, GetLineEOF);
+ TEST_THAT(getline.IsEOF());
+ TEST_CHECK_THROWS(getline.GetLine(true), CommonException, GetLineEOF);
fclose(file2);
}
-
+
// Then the IOStream version of get line, seeing as we're here...
{
FileStream file("testfiles" DIRECTORY_SEPARATOR
"fdgetlinetest.txt", O_RDONLY);
IOStreamGetLine getline(file);
- int l = 0;
- while(testfilelines[l] != 0)
- {
- TEST_THAT(!getline.IsEOF());
- std::string line;
- while(!getline.GetLine(line, true))
- ;
- printf("expected |%s| got |%s|\n", testfilelines[l],
- line.c_str());
- TEST_LINE(strcmp(testfilelines[l], line.c_str()) == 0,
- line);
- l++;
- }
- TEST_THAT(getline.IsEOF());
- std::string dummy;
- TEST_CHECK_THROWS(getline.GetLine(dummy, true), CommonException, GetLineEOF);
+ int l = 0;
+ while(testfilelines[l] != 0)
+ {
+ TEST_THAT(!getline.IsEOF());
+ std::string line;
+ while(!getline.GetLine(line, true))
+ {
+ // skip line
+ }
+ TEST_EQUAL(testfilelines[l], line);
+ l++;
+ }
+ TEST_THAT(getline.IsEOF());
+ std::string dummy;
+ TEST_CHECK_THROWS(getline.GetLine(dummy, true), CommonException, GetLineEOF);
}
// and again without pre-processing
{
@@ -495,21 +492,20 @@ int test(int argc, const char *argv[])
e--;
}
ll[e] = '\0';
-
- TEST_THAT(!getline.IsEOF());
- std::string line;
- while(!getline.GetLine(line, false))
- ;
- //printf("expected |%s| got |%s|\n", ll, line.c_str());
- TEST_THAT(strcmp(ll, line.c_str()) == 0);
+
+ TEST_THAT(!getline.IsEOF());
+ std::string line;
+ while(!getline.GetLine(line, false))
+ ;
+ TEST_EQUAL(ll, line);
}
- TEST_THAT(getline.IsEOF());
- std::string dummy;
- TEST_CHECK_THROWS(getline.GetLine(dummy, true), CommonException, GetLineEOF);
+ TEST_THAT(getline.IsEOF());
+ std::string dummy;
+ TEST_CHECK_THROWS(getline.GetLine(dummy, true), CommonException, GetLineEOF);
fclose(file2);
}
-
+
// Doesn't exist
{
std::string errMsg;
@@ -569,50 +565,69 @@ int test(int argc, const char *argv[])
TEST_THAT(sub1_3.GetKeyValue("terrible") == "absolutely");
}
- static const char *file[] =
+ static const char *file[][2] =
{
- "testfiles" DIRECTORY_SEPARATOR "config2.txt",
+ {"testfiles" DIRECTORY_SEPARATOR "config2.txt",
+ "<root>.TOPlevel (key) is missing."},
// Value missing from root
- "testfiles" DIRECTORY_SEPARATOR "config3.txt",
+ {"testfiles" DIRECTORY_SEPARATOR "config3.txt",
+ "Unexpected start block in test1"},
// Unexpected {
- "testfiles" DIRECTORY_SEPARATOR "config4.txt",
+ {"testfiles" DIRECTORY_SEPARATOR "config4.txt",
+ "Root level has close block -- forgot to terminate subblock?"},
// Missing }
- "testfiles" DIRECTORY_SEPARATOR "config5.txt",
+ {"testfiles" DIRECTORY_SEPARATOR "config5.txt",
+ "Block subconfig2 wasn't started correctly (no '{' on line of it's own)\n"
+ "Root level has close block -- forgot to terminate subblock?"},
// { expected, but wasn't there
- "testfiles" DIRECTORY_SEPARATOR "config6.txt",
+ {"testfiles" DIRECTORY_SEPARATOR "config6.txt",
+ "test1.subconfig2.bing (key) multi value not allowed (duplicated key?)."},
// Duplicate key
- "testfiles" DIRECTORY_SEPARATOR "config7.txt",
+ {"testfiles" DIRECTORY_SEPARATOR "config7.txt",
+ "Invalid configuration key: = invalid thing here!"},
// Invalid key (no name)
- "testfiles" DIRECTORY_SEPARATOR "config8.txt",
+ {"testfiles" DIRECTORY_SEPARATOR "config8.txt",
+ "File ended without terminating all subblocks"},
// Not all sub blocks terminated
- "testfiles" DIRECTORY_SEPARATOR "config9.txt",
+ {"testfiles" DIRECTORY_SEPARATOR "config9.txt",
+ "test1.subconfig3.carrots (key) is not a valid integer."},
// Not valid integer
- "testfiles" DIRECTORY_SEPARATOR "config9b.txt",
+ {"testfiles" DIRECTORY_SEPARATOR "config9b.txt",
+ "test1.subconfig2.carrots (key) is not a valid integer."},
// Not valid integer
- "testfiles" DIRECTORY_SEPARATOR "config9c.txt",
+ {"testfiles" DIRECTORY_SEPARATOR "config9c.txt",
+ "test1.subconfig2.carrots (key) is not a valid integer."},
// Not valid integer
- "testfiles" DIRECTORY_SEPARATOR "config9d.txt",
+ {"testfiles" DIRECTORY_SEPARATOR "config9d.txt",
+ "test1.subconfig3.carrots (key) is not a valid integer."},
// Not valid integer
- "testfiles" DIRECTORY_SEPARATOR "config10.txt",
+ {"testfiles" DIRECTORY_SEPARATOR "config10.txt",
+ "test1.subconfig.carrots (key) is missing."},
// Missing key (in subblock)
- "testfiles" DIRECTORY_SEPARATOR "config11.txt",
+ {"testfiles" DIRECTORY_SEPARATOR "config11.txt",
+ "test1.subconfig3.NOTEXPECTED (key) is not a known key. Check spelling and placement."},
// Unknown key
- "testfiles" DIRECTORY_SEPARATOR "config12.txt",
+ {"testfiles" DIRECTORY_SEPARATOR "config12.txt",
+ "<root>.test1.otherthing (block) is missing."},
// Missing block
- "testfiles" DIRECTORY_SEPARATOR "config13.txt",
+ {"testfiles" DIRECTORY_SEPARATOR "config13.txt",
+ "<root>.test1.* (block) is missing (a block must be present).\n"
+ "<root>.test1.otherthing (block) is missing."},
// Subconfig (wildcarded) should exist, but missing (ie nothing present)
- "testfiles" DIRECTORY_SEPARATOR "config16.txt",
+ {"testfiles" DIRECTORY_SEPARATOR "config16.txt",
+ "<root>.BoolTrue1 (key) is not a valid boolean value."},
// bad boolean value
- 0
+ {NULL, NULL},
};
- for(int l = 0; file[l] != 0; ++l)
+ for(int l = 0; file[l][0] != 0; ++l)
{
+ HideCategoryGuard hide(ConfigurationVerify::VERIFY_ERROR);
std::string errMsg;
- std::auto_ptr<Configuration> pconfig(Configuration::LoadAndVerify(file[l], &verify, errMsg));
+ std::auto_ptr<Configuration> pconfig(Configuration::LoadAndVerify(file[l][0], &verify, errMsg));
TEST_THAT(pconfig.get() == 0);
- TEST_THAT(!errMsg.empty());
- printf("(%s) Error msg is:\n------\n%s------\n", file[l], errMsg.c_str());
+ errMsg = errMsg.substr(0, errMsg.size() > 0 ? errMsg.size() - 1 : 0);
+ TEST_EQUAL_LINE(file[l][1], errMsg, file[l][0]);
}
// Check that multivalues happen as expected
@@ -764,10 +779,13 @@ int test(int argc, const char *argv[])
// Add regex entries
#ifdef HAVE_REGEX_SUPPORT
+ {
+ HideCategoryGuard hide(ConfigurationVerify::VERIFY_ERROR);
elist.AddRegexEntries(std::string("[a-d]+\\.reg$" "\x01" "EXCLUDE" "\x01" "^exclude$"));
elist.AddRegexEntries(std::string(""));
TEST_CHECK_THROWS(elist.AddRegexEntries(std::string("[:not_valid")), CommonException, BadRegularExpression);
TEST_THAT(elist.SizeOfRegexList() == 3);
+ }
#else
TEST_CHECK_THROWS(elist.AddRegexEntries(std::string("[a-d]+\\.reg$" "\x01" "EXCLUDE" "\x01" "^exclude$")), CommonException, RegexNotSupportedOnThisPlatform);
TEST_THAT(elist.SizeOfRegexList() == 0);