myserver-commit
[Top][All Lists]
Advanced

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

[myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9_2-7-gf


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9_2-7-gf94f2cc
Date: Thu, 18 Feb 2010 11:54:09 +0000

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 "GNU MyServer".

The branch, master has been updated
       via  f94f2ccdd45fc7d0ebb4f41f125f706df0d755f4 (commit)
      from  af784c22995cd1d92e25ff53b21c68c8bb6ed14f (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 -----------------------------------------------------------------


commit f94f2ccdd45fc7d0ebb4f41f125f706df0d755f4
Author: Giuseppe Scrivano <address@hidden>
Date:   Thu Feb 18 12:51:52 2010 +0100

    XmlMainConfiguration::getValue uses the DEFINE value, not the raw xml.
    
    Add a test in TestXmlMainConfiguration to exercise it.

diff --git a/myserver/include/conf/main/xml_main_configuration.h 
b/myserver/include/conf/main/xml_main_configuration.h
index eeb25e8..f9f763a 100644
--- a/myserver/include/conf/main/xml_main_configuration.h
+++ b/myserver/include/conf/main/xml_main_configuration.h
@@ -40,10 +40,7 @@ public:
     return open (filename.c_str ());
   };
 
-  virtual const char *getValue (const char* field)
-  {
-    return xmlParser.getValue (field);
-  }
+  virtual const char *getValue (const char* field);
 
   virtual const char *getValue (string const &field)
   {
diff --git a/myserver/src/conf/main/xml_main_configuration.cpp 
b/myserver/src/conf/main/xml_main_configuration.cpp
index 6eb38c6..04f3cb3 100644
--- a/myserver/src/conf/main/xml_main_configuration.cpp
+++ b/myserver/src/conf/main/xml_main_configuration.cpp
@@ -36,3 +36,35 @@ void XmlMainConfiguration::readData (list<NodeTree<string>*> 
*hashedDataTrees,
   xmlNodePtr root = xmlDocGetRootElement (xmlParser.getDoc 
())->xmlChildrenNode;
   XmlConf::build (root, hashedDataTrees, hashedData);
 }
+
+/*!
+ * Return the last value defined as <DEFINE name="FIELD" value="VALUE" /> in 
the
+ * xml file.
+ */
+const char *XmlMainConfiguration::getValue (const char* field)
+{
+  const char *ret = NULL;
+  xmlNodePtr lcur = xmlDocGetRootElement (xmlParser.getDoc 
())->xmlChildrenNode;
+  xmlAttr *attrs;
+  for (; lcur; lcur = lcur->next)
+    if (lcur->name && !xmlStrcmp (lcur->name, (const xmlChar *) "DEFINE"))
+      {
+        NodeTree<string> *node = new NodeTree<string> ();
+        const char *name = NULL;
+        const char *value = NULL;
+
+        for (attrs = lcur->properties; attrs; attrs = attrs->next)
+          {
+            if (!xmlStrcmp (attrs->name, (const xmlChar *) "name") &&
+                attrs->children && attrs->children->content)
+              name = (const char*)attrs->children->content;
+            else if (!xmlStrcmp (attrs->name, (const xmlChar *) "value") &&
+                attrs->children && attrs->children->content)
+              value = (const char*)attrs->children->content;
+          }
+        if (! strcmp (name, field))
+          ret = value;
+      }
+
+  return ret;
+}
diff --git a/myserver/tests/test_xml_main_configuration.cpp 
b/myserver/tests/test_xml_main_configuration.cpp
index bf0baf5..4a25c46 100644
--- a/myserver/tests/test_xml_main_configuration.cpp
+++ b/myserver/tests/test_xml_main_configuration.cpp
@@ -23,36 +23,80 @@
 #include <cppunit/ui/text/TestRunner.h>
 #include <cppunit/extensions/HelperMacros.h>
 
+#include <include/base/file/files_utility.h>
+
+#define KEY "foo.bar"
+#define VALUE "value"
+#define XML_FILE "foo.xml"
+#define XML_CONTENT "<?xml version=\"1.0\"?>\n<MYSERVER>"   \
+  "<DEFINE name=\"" KEY "\" value=\"garbage\" />"             \
+  "<DEFINE name=\"" KEY "\" value=\"" VALUE "\" />"             \
+  "</MYSERVER>\n"
+
 class TestXmlMainConfiguration : public CppUnit::TestFixture
 {
-  /* FIXME: Actually these tests don't really check if things work, simply they
-     check that they don't work when they shouldn't.  */
-       CPPUNIT_TEST_SUITE (TestXmlMainConfiguration);
-       CPPUNIT_TEST (testOpen);
-       CPPUNIT_TEST (testGetDoc);
-       CPPUNIT_TEST (testClose);
-       CPPUNIT_TEST_SUITE_END ();
+  CPPUNIT_TEST_SUITE (TestXmlMainConfiguration);
+  CPPUNIT_TEST (testOpen);
+  CPPUNIT_TEST (testGetDoc);
+  CPPUNIT_TEST (testGetValue);
+  CPPUNIT_TEST (testClose);
+  CPPUNIT_TEST_SUITE_END ();
 
+  File xmlFile;
+  XmlMainConfiguration xmlConf;
 public:
-       void setUp () {}
-       void tearDown () {}
-       void testOpen ()
-       {
-    XmlMainConfiguration xmlConf;
-               CPPUNIT_ASSERT (xmlConf.open ("bla/bla/bla"));
-       }
-
-       void testGetDoc ()
-       {
-    XmlMainConfiguration xmlConf;
-               CPPUNIT_ASSERT_EQUAL (xmlConf.getDoc (), (xmlDocPtr)NULL);
-       }
-
-       void testClose ()
-       {
-    XmlMainConfiguration xmlConf;
-               CPPUNIT_ASSERT (xmlConf.close ());
-       }
+  void setUp ()
+  {
+    u_long nbw;
+    xmlFile.openFile (XML_FILE, File::WRITE | File::READ
+                      | File::FILE_CREATE_ALWAYS);
+    CPPUNIT_ASSERT_EQUAL (xmlFile.write (XML_CONTENT, strlen (XML_CONTENT),
+                                           &nbw), 0);
+    CPPUNIT_ASSERT_EQUAL (nbw, static_cast<u_long> (strlen (XML_CONTENT)));
+
+    CPPUNIT_ASSERT_EQUAL (xmlConf.open (XML_FILE), 0);
+  }
+  void tearDown ()
+  {
+    CPPUNIT_ASSERT_EQUAL (xmlConf.close (), 0);
+    FilesUtility::deleteFile (XML_FILE);
+  }
+
+  void testOpen ()
+  {
+    XmlMainConfiguration tmpXmlConf;
+
+    /* These files don't exist.  */
+    CPPUNIT_ASSERT (tmpXmlConf.open ("foo/bar/baz.xml"));
+    CPPUNIT_ASSERT (tmpXmlConf.open ("baz.xml"));
+
+    CPPUNIT_ASSERT_EQUAL (tmpXmlConf.open (XML_FILE), 0);
+    CPPUNIT_ASSERT_EQUAL (tmpXmlConf.close (), 0);
+  }
+
+  void testGetDoc ()
+  {
+    XmlMainConfiguration tmpXmlConf;
+    CPPUNIT_ASSERT_EQUAL (tmpXmlConf.getDoc (), static_cast <xmlDocPtr> 
(NULL));
+    CPPUNIT_ASSERT (xmlConf.getDoc ());
+  }
+
+  void testGetValue ()
+  {
+    const char *ret = xmlConf.getValue (KEY);
+    CPPUNIT_ASSERT (ret);
+    CPPUNIT_ASSERT (! strcmp (ret, VALUE));
+    CPPUNIT_ASSERT_EQUAL (strcmp (ret, VALUE), 0);
+  }
+
+  void testClose ()
+  {
+    XmlMainConfiguration tmpXmlConf;
+
+    CPPUNIT_ASSERT (tmpXmlConf.close ());
+    CPPUNIT_ASSERT_EQUAL (tmpXmlConf.open (XML_FILE), 0);
+    CPPUNIT_ASSERT_EQUAL (tmpXmlConf.close (), 0);
+  }
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION (TestXmlMainConfiguration);

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

Summary of changes:
 .../include/conf/main/xml_main_configuration.h     |    5 +-
 myserver/src/conf/main/xml_main_configuration.cpp  |   32 +++++++
 myserver/tests/test_xml_main_configuration.cpp     |   96 ++++++++++++++------
 3 files changed, 103 insertions(+), 30 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

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