|
|
@@ -0,0 +1,163 @@ |
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "CodeDweller/configuration.hpp"
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Configuration ///////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// End of configuration ////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
int nTotalTests = 0;
|
|
|
|
int nPass = 0;
|
|
|
|
int nFail = 0;
|
|
|
|
|
|
|
|
bool result;
|
|
|
|
|
|
|
|
#define NO_EXCEPTION_TERM(msg) \
|
|
|
|
std::cout \
|
|
|
|
<< msg << " failed to throw exception at line " \
|
|
|
|
<< __LINE__ << "." << std::endl
|
|
|
|
|
|
|
|
#define EXCEPTION_TERM(msg) \
|
|
|
|
std::cout \
|
|
|
|
<< msg << " threw unexpected exception: " << e.what() << std::endl
|
|
|
|
|
|
|
|
#define RETURN_FALSE(msg) \
|
|
|
|
std::cout \
|
|
|
|
<< msg << " at line " << __LINE__ << std::endl; \
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#define RUN_TEST(test) \
|
|
|
|
std::cout << " " #test ": "; \
|
|
|
|
std::cout.flush(); \
|
|
|
|
result = test(); \
|
|
|
|
std::cout << (result ? "ok" : "fail") << std::endl; \
|
|
|
|
nTotalTests++; \
|
|
|
|
if (result) nPass++; else nFail++;
|
|
|
|
|
|
|
|
#define SUMMARY \
|
|
|
|
std::cout \
|
|
|
|
<< "\nPass: " << nPass \
|
|
|
|
<< ", Fail: " << nFail \
|
|
|
|
<< ", Total: " << nTotalTests << std::endl
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Tests ///////////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
bool testSimilarElementName() {
|
|
|
|
|
|
|
|
std::string stageContent, stage1Content, stage2Content;
|
|
|
|
CodeDweller::ConfigurationElement reader("elem");
|
|
|
|
|
|
|
|
reader
|
|
|
|
.Element("stage", stageContent)
|
|
|
|
.End("stage")
|
|
|
|
.Element("stage1", stage1Content)
|
|
|
|
.End("stage1")
|
|
|
|
.Element("stage2", stage2Content)
|
|
|
|
.End("stage2")
|
|
|
|
.End("elem");
|
|
|
|
|
|
|
|
std::string xml;
|
|
|
|
std::string expectedStageContent = "StageContent";
|
|
|
|
std::string expectedStage1Content = "Stage1Content";
|
|
|
|
std::string expectedStage2Content = "Stage2Content";
|
|
|
|
|
|
|
|
xml =
|
|
|
|
"<elem>\n"
|
|
|
|
" <stage2>" + expectedStage2Content + "</stage2>\n"
|
|
|
|
" <stage>" + expectedStageContent + "</stage>\n"
|
|
|
|
" <stage1>" + expectedStage1Content + "</stage1>\n"
|
|
|
|
"</elem>";
|
|
|
|
|
|
|
|
CodeDweller::ConfigurationData confData(xml.data(), xml.size());
|
|
|
|
|
|
|
|
reader.initialize();
|
|
|
|
|
|
|
|
if (0 == reader.interpret(confData)) {
|
|
|
|
RETURN_FALSE("Error parsing XML: " + confData.Log.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expectedStageContent != stageContent) {
|
|
|
|
RETURN_FALSE("<stage> content read failure");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expectedStage1Content != stage1Content) {
|
|
|
|
RETURN_FALSE("<stage1> content read failure");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expectedStage2Content != stage2Content) {
|
|
|
|
RETURN_FALSE("<stage2> content read failure");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool testSimilarAttributeName() {
|
|
|
|
|
|
|
|
std::string nameAttr, naAttr, nameLongAttr;
|
|
|
|
CodeDweller::ConfigurationElement reader("elem");
|
|
|
|
|
|
|
|
reader
|
|
|
|
.Element("stage")
|
|
|
|
.Attribute("name", nameAttr)
|
|
|
|
.Attribute("na", naAttr)
|
|
|
|
.Attribute("nameLong", nameLongAttr)
|
|
|
|
.End("stage")
|
|
|
|
.End("elem");
|
|
|
|
|
|
|
|
std::string xml;
|
|
|
|
std::string expectedNameAttr = "NameValue";
|
|
|
|
std::string expectedNaAttr = "NaValue";
|
|
|
|
std::string expectedNameLongAttr = "NameLongValue";
|
|
|
|
|
|
|
|
xml =
|
|
|
|
"<elem>\n"
|
|
|
|
" <stage\n"
|
|
|
|
" name='" + expectedNameAttr + "'\n"
|
|
|
|
" na='" + expectedNaAttr + "'\n"
|
|
|
|
" nameLong='" + expectedNameLongAttr + "'/>"
|
|
|
|
"</elem>";
|
|
|
|
|
|
|
|
CodeDweller::ConfigurationData confData(xml.data(), xml.size());
|
|
|
|
|
|
|
|
reader.initialize();
|
|
|
|
|
|
|
|
if (0 == reader.interpret(confData)) {
|
|
|
|
RETURN_FALSE("Error parsing XML: " + confData.Log.str());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expectedNameAttr != nameAttr) {
|
|
|
|
RETURN_FALSE("\"name\" attribute read failure");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expectedNaAttr != naAttr) {
|
|
|
|
RETURN_FALSE("\"na\" attribute read failure");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expectedNameLongAttr != nameLongAttr) {
|
|
|
|
RETURN_FALSE("\"nameLong\" attribute read failure");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// End of tests ////////////////////////////////////////////////////////////////
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
std::cout << "CodeDweller::configuration unit tests" << std::endl
|
|
|
|
<< std::endl;
|
|
|
|
|
|
|
|
RUN_TEST(testSimilarElementName);
|
|
|
|
RUN_TEST(testSimilarAttributeName);
|
|
|
|
|
|
|
|
SUMMARY;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|