powerguru-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Powerguru-commit] [SCM] powerguru branch, master, updated. 7ae481f5ea87


From: Rob Savoye
Subject: [Powerguru-commit] [SCM] powerguru branch, master, updated. 7ae481f5ea8785eef8564650c2c19c55448bd708
Date: Sun, 25 Nov 2018 14:47:13 -0500 (EST)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "powerguru".

The branch, master has been updated
       via  7ae481f5ea8785eef8564650c2c19c55448bd708 (commit)
       via  aa371ad4c3bf14f464d75ac2f566a2f715e66e2c (commit)
      from  11d4afbbf83e2e9cdfc48b93edc475ac68b94408 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=7ae481f5ea8785eef8564650c2c19c55448bd708


commit 7ae481f5ea8785eef8564650c2c19c55448bd708
Author: Rob Savoye <address@hidden>
Date:   Sun Nov 25 12:47:06 2018 -0700

    All tests pass, class seems to work again.

diff --git a/lib/xml.cc b/lib/xml.cc
index 5d54215..20da003 100644
--- a/lib/xml.cc
+++ b/lib/xml.cc
@@ -102,18 +102,12 @@ XML::extractNode(xmlNodePtr node)
         //ptr = node->children->content;
         ptr = xmlNodeGetContent(node->children);
         if (ptr != NULL) {
-            if ((strchr((const char *)ptr, '\n') == 0) && (ptr[0] != 0)) {
-                if (node->children->content == NULL) {
-                    dbglogfile << "FIXME: Node " << name << " has no contents" 
<< std::endl;
-                } else {
-                    value = reinterpret_cast<const char 
*>(node->children->content);
+            value = reinterpret_cast<const char *>(node->children->content);
 #if 1
-                    dbglogfile << "extractChildNode from text for " << name
-                               << " has contents " << value << std::endl;
+            dbglogfile << "\tChild node: " << name
+                       << " has contents " << value << std::endl;
 #endif
-                    xml->valueSet(value.substr(0, value.find('\n')));
-                }
-            }
+            xml->valueSet(value.substr(0, value.find('\n')));
             xmlFree(ptr);
         }
     }
@@ -123,19 +117,14 @@ XML::extractNode(xmlNodePtr node)
 
     while (childnode != NULL) {
         if (childnode->type == XML_ELEMENT_NODE) {
-            dbglogfile << "\t\t extracting node " << (const char 
*)childnode->name << std::endl;
+            dbglogfile << "\tfound node " << (const char *)childnode->name << 
std::endl;
             XMLNode *child = extractNode(childnode);
             //if (child->_value.get_type() != as_value::UNDEFINED) {
-#if 0
-            if (!child->valueGet().empty() {
-                dbglogfile << "\tPushing childNode " << child->nameGet()
-                           << " value " << child->valueGet()
-                           <<  " on element "
-                           <<  xml << std::endl;
-            } else {
-                dbglogfile << "\tPushing childNode " << 
child->nameGet().c_str()
-                           << std::endl;
-            }
+#if 1
+            dbglogfile << "\tPushing child Node " << child->nameGet()
+                       << " value " << child->valueGet()
+                       <<  " on element "
+                       <<  xml->nameGet() << std::endl;
 #endif
             xml->childAdd(child);
         }
diff --git a/lib/xml.h b/lib/xml.h
index 8d9a39e..005f0cc 100644
--- a/lib/xml.h
+++ b/lib/xml.h
@@ -34,22 +34,6 @@
 #include "xml.h"
 #include "log.h"
 
-#if 0
-// This holds the data (name & value) for an XML node's attributes.
-class XMLAttr {
-public:
-    XMLAttr();
-    ~XMLAttr();
-    const std::string &nameGet(void);
-    void nameSet(const std::string &name);
-    const std::string &valueGet(void);
-    void valueSet(const std::string &val);
-private:
-    std::string _name;
-    std::string _value;
-};
-#endif
-
 // This holds the data (name & value) for an XML node.
 class XMLNode
 {
@@ -58,7 +42,10 @@ public:
     ~XMLNode() {};
 
     XMLNode *childGet(int x) { return _children[x]; }
-    XMLNode *operator [] (int x) { return _children[x]; }
+    XMLNode *operator [] (int x) {
+        return (x < _children.size())? _children[x]: 0;
+    }
+    
     void operator = (XMLNode &node);
 
     const std::string &nameGet(void) { return _name; }
@@ -87,7 +74,7 @@ class XML {
 public:
     XML() {} ;
     XML(const std::string &xml_in) {};
-    XML(struct node * childNode) {};
+    //XML(struct node * childNode) {};
     ~XML() {};
 
     // bool parseRoot(xmlDocPtr document);
@@ -95,14 +82,16 @@ public:
     bool parseFile(const std::string &filespec);
 
     const std::string &nameGet(void) { return _nodes->nameGet(); }
+    const std::string &valueGet(void) { return _nodes->valueGet(); }
     void nameSet(const std::string &name) { _nodes->nameSet(name); }
     bool hasChildren(void) {  return _nodes->hasChildren(); }
     bool hasAttributes(void) { return _nodes->hasAttributes(); }
-    //XMLNode *processNode(xmlTextReaderPtr reader);
     //const std::string &nodeNameGet(void) { return nameGet(); }
 
-    XMLNode *childGet(int x) { return _nodes->childGet(x); };
-    //XMLNode *operator [] (int x) { return _nodes[x]; };
+    XMLNode *operator [] (int x) {
+        // range check the index for better error handling
+        return (x < _nodes->childrenSize())? _nodes->childGet(x): 0;
+    };
     //const XML &operator = (const XMLNode &node);
 private:
     XMLNode *extractNode(xmlNodePtr node);
diff --git a/testsuite/libtests/xml-test.cc b/testsuite/libtests/xml-test.cc
index 44d39ac..8c837b6 100644
--- a/testsuite/libtests/xml-test.cc
+++ b/testsuite/libtests/xml-test.cc
@@ -93,52 +93,103 @@ xml_tests(void) {
     std::string xmlfile = SRCDIR;
     xmlfile += "/test.xml";
     
+    std:: cout << "Testing file parsing" << std::endl;
     if (xml.parseFile(xmlfile)) {
         runtest.pass ("XML::parseFile()");
     } else {
         runtest.fail ("XML::parseFile()");
     }
+    
     std::string name = xml.nameGet();
-    if (name == "one") {
-        runtest.pass ("XML::nameGet(file)");
+    std::string value = xml.valueGet();
+    if (name == "one" && value == "One") {
+        runtest.pass ("XML::parseFile(name, value)");
     } else {
-        runtest.fail ("XML::nameGet(file)");
+        runtest.fail ("XML::parseFile(name, value)");
     }
 
-    std::string testxml = 
"<one2><two2>two2<three2>three2</three2></two2></one2>";
-    if (xml.parseMem(testxml)) {
-        runtest.pass ("XML::parseMem()");
+    if (xml.hasChildren()) {
+        runtest.pass ("XML::hasChildren(file)");
     } else {
-        runtest.fail ("XML::parseMem()");
+        runtest.fail ("XML::hasChildren(file)");
     }
-    // 
-    name = xml.nameGet();
-    if (name == "one2") {
-        runtest.pass ("XML::nameGet(memory)");
+
+    if (!xml.hasAttributes()) {
+        runtest.pass ("XML::hasAttributes(file)");
+    } else {
+        runtest.fail ("XML::hasAttributes(file)");
+    }
+
+    // Get first child element
+    XMLNode *child = xml[0];
+    name = child->nameGet();
+    value = child->valueGet();
+    if (name == "two" && value == "Two") {
+        runtest.pass ("XML[0]");
+    } else {
+        runtest.fail ("XML]0]");
+    }
+    
+    if (child->hasAttributes() && (child->attribGet("foo") == "Bar")) {
+        runtest.pass ("XML::attribGet(child)");
+    } else {
+        runtest.fail ("XML::attribGet(child)");
+    }
+
+    // there should only be one child, so this should return an error.
+    if (xml[1] == 0) {
+        runtest.pass ("XM[1]: out of range");
     } else {
-        runtest.fail ("XML::nameGet(memory)");
+        runtest.fail ("XML[1]: out of range");
+    }
+        
+    child = child->childGet(0);
+    if (child->nameGet() == "three2" && child->valueGet() == "Three2") {
+        runtest.xpass ("XML[0][0]");
+    } else {
+        runtest.xfail ("XML[0][0]");
     }
 
+    // Memory parsing
+    std:: cout << "Testing memory parsing" << std::endl;
+    std::string testxml = "<one2>One2<two2>Two2<three2 
bar='foo'>Three2</three2></two2></one2>";
+    if (xml.parseMem(testxml)) {
+        runtest.pass ("XML::parseMem()");
+    } else {
+        runtest.fail ("XML::parseMem()");
+    }
     if (xml.hasChildren()) {
-        runtest.pass ("XML::hasChildren()");
+        runtest.pass ("XML::hasChildren(mem)");
     } else {
-        runtest.fail ("XML::hasChildren()");
+        runtest.fail ("XML::hasChildren(mem)");
     }
 
     if (!xml.hasAttributes()) {
-        runtest.pass ("XML::hasAttributes()");
+        runtest.pass ("XML::hasAttributes(mem)");
     } else {
-        runtest.fail ("XML::hasAttributes()");
+        runtest.fail ("XML::hasAttributes(mem)");
     }
+    // 
+    name = xml.nameGet();
+    value = xml.valueGet();
+    if (name == "one2" && value == "One2") {
+        runtest.pass ("XML::nameGet(mem)");
+    } else {
+        runtest.fail ("XML::nameGet(mem)");
+        std::cerr << "FIXME2: " << name << " | " << value << std::endl;
+    }
+
     // Get first child element
-    XMLNode *child = xml.childGet(0);
-    if (child->nameGet() == "two") {
+    child = xml[0];
+    name = child->nameGet();
+    value = child->valueGet();
+    if (name == "two2" && value == "Two2") {
         runtest.pass ("XML::nameGet(child)");
     } else {
         runtest.fail ("XML::nameGet(child)");
     }
     
-    if (child->hasAttributes() && (child->attribGet("foo") == "bar")) {
+    if (!child->hasAttributes()) {
         runtest.pass ("XML::attribGet()");
     } else {
         runtest.fail ("XML::attribGet()");
@@ -146,11 +197,16 @@ xml_tests(void) {
 
     // Get the child of the child
     child = child->childGet(0);
-    if (child->nameGet() == "three") {
+    if (child->nameGet() == "three2" && child->valueGet() == "Three2") {
         runtest.pass ("XML::nameGet(child)");
     } else {
         runtest.fail ("XML::nameGet(child)");
     }    
+    if (child->hasAttributes() && (child->attribGet("bar") == "foo")) {
+        runtest.pass ("XML::attribGet()");
+    } else {
+        runtest.fail ("XML::attribGet()");
+    }
 }
 
 void

http://git.savannah.gnu.org/cgit/powerguru.git/commit/?id=aa371ad4c3bf14f464d75ac2f566a2f715e66e2c


commit aa371ad4c3bf14f464d75ac2f566a2f715e66e2c
Author: Rob Savoye <address@hidden>
Date:   Sun Nov 25 11:47:39 2018 -0700

    delete extra garbage at the end of a line.

diff --git a/lib/xml.cc b/lib/xml.cc
index 643a5a4..5d54215 100644
--- a/lib/xml.cc
+++ b/lib/xml.cc
@@ -86,8 +86,18 @@ XML::extractNode(xmlNodePtr node)
         }
     }
 
-    name = reinterpret_cast<const char *>(node->name);
-    xml->nameSet(name);
+    if (node->name != 0) {
+        name = reinterpret_cast<const char *>(node->name);
+        xml->nameSet(name);
+    }
+    // Sometimes the content is at the end of a line, so remove the carriage 
return
+    // and trailing garbage. It's a const, so return a substring instead of 
trying
+    // to change the value string.
+    if (node->children->content != 0) {
+        value = reinterpret_cast<char *>(node->children->content);
+        xml->valueSet(value.substr(0, value.find('\n')));
+    }
+
     if (node->children) {
         //ptr = node->children->content;
         ptr = xmlNodeGetContent(node->children);
@@ -101,7 +111,7 @@ XML::extractNode(xmlNodePtr node)
                     dbglogfile << "extractChildNode from text for " << name
                                << " has contents " << value << std::endl;
 #endif
-                    xml->valueSet(value);
+                    xml->valueSet(value.substr(0, value.find('\n')));
                 }
             }
             xmlFree(ptr);
@@ -211,8 +221,7 @@ XML::parseMem(const std::string &xml_in)
         dbglogfile << "ERROR: Can't parse XML data!" << std::endl;
         return false;
     }
-    //ret = parseRoot(_doc);
-    //ret = xmlDocGetRootElement(_doc);
+    _nodes = extractNode(xmlDocGetRootElement(_doc));
     xmlCleanupParser();
     xmlFreeDoc(_doc);
     xmlMemoryDump();

-----------------------------------------------------------------------

Summary of changes:
 lib/xml.cc                     | 48 ++++++++++-----------
 lib/xml.h                      | 31 +++++---------
 testsuite/libtests/xml-test.cc | 96 +++++++++++++++++++++++++++++++++---------
 3 files changed, 109 insertions(+), 66 deletions(-)


hooks/post-receive
-- 
powerguru



reply via email to

[Prev in Thread] Current Thread [Next in Thread]