Author: phunt
Date: Tue Oct 14 13:09:57 2008
New Revision: 704657

URL: http://svn.apache.org/viewvc?rev=704657&view=rev
Log:
ZOOKEEPER-182.  zookeeper_init accepts empty host-port string and returns valid 
pointer to zhandle_t

Modified:
    hadoop/zookeeper/trunk/src/c/src/zookeeper.c
    hadoop/zookeeper/trunk/src/c/tests/TestZookeeperInit.cc

Modified: hadoop/zookeeper/trunk/src/c/src/zookeeper.c
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/c/src/zookeeper.c?rev=704657&r1=704656&r2=704657&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/c/src/zookeeper.c (original)
+++ hadoop/zookeeper/trunk/src/c/src/zookeeper.c Tue Oct 14 13:09:57 2008
@@ -415,6 +415,10 @@
     } else {
        zh->watcher = null_watcher_fn;
     }
+    if (host == 0 || *host == 0) { // what we shouldn't dup
+        errno=EINVAL;
+        goto abort;
+    }
     zh->hostname = strdup(host);
     if (zh->hostname == 0) {
         goto abort;

Modified: hadoop/zookeeper/trunk/src/c/tests/TestZookeeperInit.cc
URL: 
http://svn.apache.org/viewvc/hadoop/zookeeper/trunk/src/c/tests/TestZookeeperInit.cc?rev=704657&r1=704656&r2=704657&view=diff
==============================================================================
--- hadoop/zookeeper/trunk/src/c/tests/TestZookeeperInit.cc (original)
+++ hadoop/zookeeper/trunk/src/c/tests/TestZookeeperInit.cc Tue Oct 14 13:09:57 
2008
@@ -39,6 +39,10 @@
        CPPUNIT_TEST(testBasic);
     CPPUNIT_TEST(testAddressResolution);
     CPPUNIT_TEST(testMultipleAddressResolution);
+    CPPUNIT_TEST(testNullAddressString);
+    CPPUNIT_TEST(testEmptyAddressString);
+    CPPUNIT_TEST(testOneSpaceAddressString);
+    CPPUNIT_TEST(testTwoSpacesAddressString);
     CPPUNIT_TEST(testInvalidAddressString1);
     CPPUNIT_TEST(testInvalidAddressString2);
     CPPUNIT_TEST(testNonexistentHost);
@@ -161,6 +165,33 @@
                 CPPUNIT_ASSERT_EQUAL(3434,(int)ntohs(addr->sin_port));
         }
     }
+    void testNullAddressString()
+    {
+        zh=zookeeper_init(NULL,0,0,0,0,0);
+        CPPUNIT_ASSERT(zh==0);
+        CPPUNIT_ASSERT_EQUAL(EINVAL,errno);
+    }
+    void testEmptyAddressString()
+    {
+        const string INVALID_HOST("");
+        zh=zookeeper_init(INVALID_HOST.c_str(),0,0,0,0,0);
+        CPPUNIT_ASSERT(zh==0);
+        CPPUNIT_ASSERT_EQUAL(EINVAL,errno);
+    }
+    void testOneSpaceAddressString()
+    {
+        const string INVALID_HOST(" ");
+        zh=zookeeper_init(INVALID_HOST.c_str(),0,0,0,0,0);
+        CPPUNIT_ASSERT(zh==0);
+        CPPUNIT_ASSERT_EQUAL(EINVAL,errno);
+    }
+    void testTwoSpacesAddressString()
+    {
+        const string INVALID_HOST("  ");
+        zh=zookeeper_init(INVALID_HOST.c_str(),0,0,0,0,0);
+        CPPUNIT_ASSERT(zh==0);
+        CPPUNIT_ASSERT_EQUAL(EINVAL,errno);
+    }
     void testInvalidAddressString1()
     {
         const string INVALID_HOST("host1");


Reply via email to