Date: Friday, May 4, 2007 @ 22:35:55
  Author: marc
    Path: /cvsroot/carob/libmysequoia/test

   Added: testmysequoia.conf (1.1)
Modified: Globals.hpp (1.6 -> 1.7) TestMySQLAPI.cpp (1.50 -> 1.51)
          runTests.cpp (1.4 -> 1.5)

Externalized test configuration from compile-time Globals.hpp
constants to runtime testmysequoia.conf file.


--------------------+
 Globals.hpp        |   24 +++++++++++++---------
 TestMySQLAPI.cpp   |    4 ++-
 runTests.cpp       |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 testmysequoia.conf |   13 ++++++++++++
 4 files changed, 83 insertions(+), 12 deletions(-)


Index: libmysequoia/test/Globals.hpp
diff -u libmysequoia/test/Globals.hpp:1.6 libmysequoia/test/Globals.hpp:1.7
--- libmysequoia/test/Globals.hpp:1.6   Tue Nov 28 17:22:56 2006
+++ libmysequoia/test/Globals.hpp       Fri May  4 22:35:55 2007
@@ -22,15 +22,19 @@
 #ifndef _GLOBALS_HPP
 #define _GLOBALS_HPP
 
-const char *USER1 = "user";
-const char *PASSWD1 = "pass";
-const char *USER2 = "user2";
-const char *PASSWD2 = "pass2";
-const char *BAD_USER = "nonexistent_user_name";
-const char *BAD_PASSWD = "bad_password";
-const char *HOST = "n1 n2";
-const char *DB1 = "DB1";
-const char *BAD_DB = "nonexistent_db_name";
-const char *SOCKET = "/var/run/mysqld/mysqld.sock";
+namespace LMStestconf {
+
+  extern const char *USER1;
+  extern const char *PASSWD1;
+  extern const char *USER2;
+  extern const char *PASSWD2;
+  extern const char *HOST;
+  extern const char *DB1;
+
+  const char *BAD_USER = "nonexistent_user_name";
+  const char *BAD_PASSWD = "bad_password";
+  const char *BAD_DB = "nonexistent_db_name";
+  const char *SOCKET = "/var/run/mysqld/mysqld.sock";
+}
 
 #endif /* _GLOBALS_HPP */
Index: libmysequoia/test/TestMySQLAPI.cpp
diff -u libmysequoia/test/TestMySQLAPI.cpp:1.50 
libmysequoia/test/TestMySQLAPI.cpp:1.51
--- libmysequoia/test/TestMySQLAPI.cpp:1.50     Fri May  4 15:30:34 2007
+++ libmysequoia/test/TestMySQLAPI.cpp  Fri May  4 22:35:55 2007
@@ -16,7 +16,7 @@
  * limitations under the License.
  *
  * Initial developer(s): Zsolt Simon, Csaba Simon
- * Contributor(s): 
+ * Contributor(s): Marc Herbert
  */
 
 #include <mysql_wrapper.h>
@@ -30,6 +30,8 @@
 
 CPPUNIT_TEST_SUITE_REGISTRATION (TestMySQLAPI);
 
+using namespace LMStestconf;
+
 void TestMySQLAPI::setUp(void)
 {
   mysql = mysql_init(0);
Index: libmysequoia/test/runTests.cpp
diff -u libmysequoia/test/runTests.cpp:1.4 libmysequoia/test/runTests.cpp:1.5
--- libmysequoia/test/runTests.cpp:1.4  Tue Mar 28 09:32:53 2006
+++ libmysequoia/test/runTests.cpp      Fri May  4 22:35:55 2007
@@ -19,6 +19,8 @@
  * Contributor(s): 
  */
 
+#include "IniParser.hpp"
+
 #include <cppunit/extensions/TestFactoryRegistry.h>
 #include <cppunit/ui/text/TestRunner.h>
 #include <cppunit/CompilerOutputter.h>
@@ -27,10 +29,60 @@
 
 #include <cstring>
 
-using namespace CPPUNIT_NS;
+#define TESTCONF "testmysequoia.conf"
+
+
+namespace LMStestconf
+{
+  const char *USER1;
+  const char *PASSWD1;
+  const char *USER2;
+  const char *PASSWD2;
+  const char *HOST;
+  const char *DB1;
+}
+
+namespace {
+
+  IniParser ini;
+
+  std::string
+  param(const char *name)
+  {
+    std::string val = ini.get("client", name);
+    if (val.empty())
+      // TODO: use some cppunit trick?
+      std::cout << "WARNING: empty or missing parameter '" << name << "' in " 
<< TESTCONF << std::endl;
+    
+    return val;
+  }
+
+}
+
 
 int main (int argc, char* argv[])
 {
+  using namespace CPPUNIT_NS;
+  using namespace LMStestconf;
+
+  // TODO: check for missing file
+  ini.parseFile(TESTCONF);
+
+  std::string user1(param("user"));
+  std::string passwd1(param("password"));
+  std::string user2(param("user2"));
+  std::string passwd2(param("passwd2"));
+  std::string host(param("host"));
+  std::string db1(param("database"));
+
+  USER1 = user1.c_str();
+  PASSWD1 =  passwd1.c_str() ;
+  USER2 = user2.c_str();
+  PASSWD2 = passwd2.c_str();
+  HOST = host.c_str();
+  DB1 = db1.c_str();
+
+
   TextTestRunner runner;
   BriefTestProgressListener listener;
   bool silent;
Index: libmysequoia/test/testmysequoia.conf
diff -u /dev/null libmysequoia/test/testmysequoia.conf:1.1
--- /dev/null   Fri May  4 22:35:55 2007
+++ libmysequoia/test/testmysequoia.conf        Fri May  4 22:35:55 2007
@@ -0,0 +1,13 @@
+
+
+[client]
+# names borrowed from mysequoia.conf
+user = user
+password = pass
+host = node10 node11
+database = DB1
+
+# not
+user2 = user2
+passwd2 = pass2
+

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to