hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
XMLCleanerTest.cpp
Go to the documentation of this file.
1 
14 #include <Poco/SAX/SAXException.h>
15 
16 #include "XMLCleanerTest.hpp"
17 #include "TestData.hpp"
18 
19 std::string XMLpath = "sphinx:docset/sphinx:schema";
20 std::string XMLElement = "sphinx:document";
21 std::string XMLIdName = "id";
22 
24 {
25  std::string ret;
26  Poco::XML::DOMParser parser;
27  Poco::AutoPtr<Poco::XML::Document> pDoc = parser.parseString(saveXMLTest_Data);
28  Poco::XML::NodeIterator it(pDoc, Poco::XML::NodeFilter::SHOW_ALL);
29  Poco::XML::Node* rootNode = it.root();
30  ret = xmlCleanerA->saveXMLWrp(rootNode);
31 
32  CPPUNIT_ASSERT(!ret.empty());
33 
34  CPPUNIT_ASSERT(ret.find("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") != ret.npos || ret.find("<?xml version=\"1.0\" encoding=\"utf-8\"?>") != ret.npos);
35  CPPUNIT_ASSERT(ret.find("<sphinx:docset xmlns:sphinx=\"http://sphinxsearch.com\">") != ret.npos);
36  CPPUNIT_ASSERT(ret.find("<sphinx:document id=\"24\">") != ret.npos);
37  CPPUNIT_ASSERT(ret.find("<h><![CDATA[[time element, as specified in ISO 8601. Year: YYYY (eg 1997) Year and month: YYYY-MM (eg 1997-07)]]></h>") != ret.npos);
38  CPPUNIT_ASSERT(ret.find("</sphinx:docset>") != ret.npos);
39 
40  CPPUNIT_ASSERT(ret.find("<empty tag>") == ret.npos);
41 
42  ret = xmlCleanerA->saveXMLWrp(NULL);
43  CPPUNIT_ASSERT(ret.empty());
44 }
45 
47 {
48  std::string ret;
49  std::set<unsigned long long> delList;
50 
51  ret = xmlCleanerA->process(processTest_Data, delList);
52 
53  CPPUNIT_ASSERT(!ret.empty());
54  CPPUNIT_ASSERT(ret.find("<?xml version=\"1.0\" encoding=\"UTF-8\"?>") != ret.npos || ret.find("<?xml version=\"1.0\" encoding=\"utf-8\"?>") != ret.npos);
55  CPPUNIT_ASSERT(ret.find("<sphinx:docset xmlns:sphinx=\"http://sphinxsearch.com\">") != ret.npos);
56  CPPUNIT_ASSERT(ret.find("<ext_f4>0022_1</ext_f4>") != ret.npos);
57  CPPUNIT_ASSERT(ret.find("<ext_f4>0023_2</ext_f4>") != ret.npos);
58  CPPUNIT_ASSERT(ret.find("<ext_f4>0024_1</ext_f4>") != ret.npos);
59  CPPUNIT_ASSERT(ret.find("<ext_f4>0023_1</ext_f4>") == ret.npos);
60 
61  delList.insert(14);
62  delList.insert(22);
63  ret = xmlCleanerA->process(processTest_Data, delList);
64 
65  CPPUNIT_ASSERT(!ret.empty());
66  CPPUNIT_ASSERT(ret.find("<ext_f4>0022_1</ext_f4>") == ret.npos);
67  CPPUNIT_ASSERT(ret.find("<ext_f4>0023_2</ext_f4>") != ret.npos);
68  CPPUNIT_ASSERT(ret.find("<ext_f4>0024_1</ext_f4>") != ret.npos);
69  CPPUNIT_ASSERT(ret.find("<ext_f4>0023_1</ext_f4>") == ret.npos);
70 
71  CPPUNIT_ASSERT_THROW(xmlCleanerA->process(processTestBD1_Data, delList), Poco::XML::SAXParseException);
72  CPPUNIT_ASSERT_THROW(xmlCleanerA->process(processTestBD2_Data, delList), Poco::XML::SAXParseException);
73  CPPUNIT_ASSERT_THROW(xmlCleanerA->process(processTestBD3_Data, delList), Poco::XML::SAXParseException);
74 }
75 
77 {
78  xmlCleanerA = Poco::SharedPtr<XMLCleanerA>(new XMLCleanerA(XMLpath, XMLElement, XMLIdName));
79 }
80 
82 {
83 }
84 
86 {
87 }
88 
89 CppUnit::Test *XMLCleanerTest::suite()
90 {
91  CppUnit::TestSuite *suiteOfTests = new CppUnit::TestSuite("XMLCleanerTest");
92  suiteOfTests->addTest(new CppUnit::TestCaller<XMLCleanerTest>("XMLCleanerTest_saveXMLTest", &XMLCleanerTest::saveXMLTest));
93  suiteOfTests->addTest(new CppUnit::TestCaller<XMLCleanerTest>("XMLCleanerTest_processTest", &XMLCleanerTest::processTest));
94  return suiteOfTests;
95 }