Date: Friday, December 9, 2005 @ 13:14:42
  Author: csaba
    Path: /cvsroot/carob/libmysequoia/test

Modified: TestMySQLAPI.cpp (1.6 -> 1.7)

- more mysql_real_connect() test cases.
- more checks after each function


------------------+
 TestMySQLAPI.cpp |   39 +++++++++++++++++++++++++++++++++------
 1 files changed, 33 insertions(+), 6 deletions(-)


Index: libmysequoia/test/TestMySQLAPI.cpp
diff -u libmysequoia/test/TestMySQLAPI.cpp:1.6 
libmysequoia/test/TestMySQLAPI.cpp:1.7
--- libmysequoia/test/TestMySQLAPI.cpp:1.6      Fri Dec  9 11:17:02 2005
+++ libmysequoia/test/TestMySQLAPI.cpp  Fri Dec  9 13:14:42 2005
@@ -25,6 +25,8 @@
 #include "TestMySQLAPI.hpp"
 #include "Globals.hpp"
 
+#include <stdlib.h>
+
 CPPUNIT_TEST_SUITE_REGISTRATION (TestMySQLAPI);
 
 void TestMySQLAPI::setUp(void)
@@ -58,6 +60,22 @@
   // implicit localhost
   CPPUNIT_ASSERT(mysql_real_connect(mysql, "", USER1, PASSWD1, DB1, 0, 0, 0) 
!= 0);  
   CPPUNIT_ASSERT(mysql_real_connect(mysql, 0, USER1, PASSWD1, DB1, 0, 0, 0) != 
0);  
+  CPPUNIT_ASSERT(mysql->host && strcmp("localhost", mysql->host) == 0);
+
+  // connect without the username parameter
+  // implicit the current login name under unix
+/* TODO uncomment when the code will be in place
+  CPPUNIT_ASSERT(mysql_real_connect(mysql, HOST, "", PASSWD1, DB1, 0, 0, 0) != 
0);  
+  CPPUNIT_ASSERT(mysql_real_connect(mysql, HOST, 0, PASSWD1, DB1, 0, 0, 0) != 
0);  
+  char *user = getenv("USER");
+  CPPUNIT_ASSERT(mysql->user && strcmp(user ? user : "UNKNOWN_USER", 
mysql->user));
+*/
+  // connect with an empty password
+/* TODO put in the config file an username with an empty password and uncoment
+   the test
+  CPPUNIT_ASSERT(mysql_real_connect(mysql, HOST, USER1, "", DB1, 0, 0, 0) != 
0);  
+*/
+  CPPUNIT_ASSERT(mysql_real_connect(mysql, HOST, USER1, 0, DB1, 0, 0, 0) != 
0);  
 }
 
 void TestMySQLAPI::mysql_real_connect_negative_test(void)
@@ -65,9 +83,6 @@
   // connect specifying unix socket
   CPPUNIT_ASSERT(mysql_real_connect(mysql, HOST, USER1, PASSWD1, DB1, 0, 
SOCKET, 0) == 0);  
  
-  // giving no user name
-  CPPUNIT_ASSERT(mysql_real_connect(mysql, HOST, 0, PASSWD1, DB1, 0, 0, 0) == 
0);  
-   
   // connect with bad username
   CPPUNIT_ASSERT(mysql_real_connect(mysql, HOST, BAD_USER, PASSWD1, DB1, 0, 0, 
0) == 0);  
   // TODO check error message
@@ -96,7 +111,6 @@
 {
   // connect to the database - do not specify the DB name
   CPPUNIT_ASSERT(mysql_real_connect(mysql, HOST, USER1, PASSWD1, 0, 0, 0, 0) 
!= 0);
-
   CPPUNIT_ASSERT(mysql->host && strcmp(HOST, mysql->host) == 0);
   CPPUNIT_ASSERT(mysql->user && strcmp(USER1, mysql->user) == 0);
   CPPUNIT_ASSERT(mysql->passwd && strcmp(PASSWD1, mysql->passwd) == 0);
@@ -104,33 +118,45 @@
   CPPUNIT_ASSERT(mysql->port != 0);
 
   // select DB1 - the real connection will happen here
+  // be aware 0 - success
   CPPUNIT_ASSERT(mysql_select_db(mysql, DB1) == 0);
   CPPUNIT_ASSERT(mysql->db && strcmp(DB1, mysql->db) == 0);
 
-  // select DB2 - reconnect will happen
+  // select DB2 - reconnect will happen - be aware 0 - success
   CPPUNIT_ASSERT(mysql_select_db(mysql, DB2) == 0);
+  CPPUNIT_ASSERT(mysql->db && strcmp(DB2, mysql->db) == 0);
 }
 
 void TestMySQLAPI::mysql_select_db_negative_test(void)
 {
   // try to select DB without connecting to server
   CPPUNIT_ASSERT(mysql_select_db(mysql, DB1) != 0);
+  // TODO check error
 
   // connect to the database
   CPPUNIT_ASSERT(mysql_real_connect(mysql, HOST, USER1, PASSWD1, DB1, 0, 0, 0) 
!= 0);
+  CPPUNIT_ASSERT(mysql->host && strcmp(HOST, mysql->host) == 0);
+  CPPUNIT_ASSERT(mysql->user && strcmp(USER1, mysql->user) == 0);
+  CPPUNIT_ASSERT(mysql->passwd && strcmp(PASSWD1, mysql->passwd) == 0);
+  CPPUNIT_ASSERT(mysql->db && strcmp(DB1, mysql->db) == 0);
+  CPPUNIT_ASSERT(mysql->port != 0);
 
   // select a nonexistent DB
-//  CPPUNIT_ASSERT(mysql_select_db(mysql, BAD_DB) == 0);
+/* TODO uncomment if the bug is fixed in Sequoia
+  CPPUNIT_ASSERT(mysql_select_db(mysql, BAD_DB) == 0);
+*/
 }
 
 void TestMySQLAPI::mysql_change_user_test(void)
 {
   // connect to the database
   CPPUNIT_ASSERT(mysql_real_connect(mysql, HOST, USER1, PASSWD1, DB1, 0, 0, 0) 
!= 0);
+
   // change user specifying every parameter - be aware 0 = success
   CPPUNIT_ASSERT(mysql_change_user(mysql, USER2, PASSWD2, DB1) == 0);
   CPPUNIT_ASSERT(mysql->user && strcmp(USER2, mysql->user) == 0);
   CPPUNIT_ASSERT(mysql->passwd && strcmp(PASSWD2, mysql->passwd) == 0);
+
   // change user not specifying the DB name - be aware 0 = success
   CPPUNIT_ASSERT(mysql_change_user(mysql, USER1, PASSWD1, 0) == 0);
   CPPUNIT_ASSERT(mysql->user && strcmp(USER1, mysql->user) == 0);
@@ -141,6 +167,7 @@
 {
   // connect to the database
   CPPUNIT_ASSERT(mysql_real_connect(mysql, HOST, USER1, PASSWD1, DB1, 0, 0, 0) 
!= 0);
+
   // change user specifying every parameter but a BAD username 0 = success
   CPPUNIT_ASSERT(mysql_change_user(mysql, BAD_USER, PASSWD2, DB1) != 0);
 }

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

Reply via email to