]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2821] Move library_end to holder
authorJelte Jansen <jelte@isc.org>
Fri, 8 Mar 2013 11:01:03 +0000 (12:01 +0100)
committerJelte Jansen <jelte@isc.org>
Fri, 8 Mar 2013 11:01:03 +0000 (12:01 +0100)
and use the holder in the unit tests as well

src/lib/dhcpsrv/mysql_lease_mgr.h
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/run_unittests.cc

index e3bc040d14f71362799e16aa0d2a0d26c54fa1d2..390c24f4f8d9f14ccd8eaa44f201b43036bddfa5 100644 (file)
@@ -59,6 +59,8 @@ public:
         if (mysql_ != NULL) {
             mysql_close(mysql_);
         }
+        // The library itself shouldn't be needed anymore
+        mysql_library_end();
     }
 
     /// @brief Conversion Operator
index ddb2645032b9df43dd57ca84f80fe7fe501a695b..2ae6a490f29fed2269d04c552cbd27d482e992c6 100644 (file)
@@ -118,21 +118,16 @@ validConnectionString() {
 // There is no error checking in this code: if something fails, one of the
 // tests will (should) fall over.
 void destroySchema() {
-    // Initialise
-    MYSQL handle;
-    (void) mysql_init(&handle);
+    MySqlHolder mysql;
 
     // Open database
-    (void) mysql_real_connect(&handle, "localhost", "keatest",
+    (void) mysql_real_connect(mysql, "localhost", "keatest",
                               "keatest", "keatest", 0, NULL, 0);
 
     // Get rid of everything in it.
     for (int i = 0; destroy_statement[i] != NULL; ++i) {
-        (void) mysql_query(&handle, destroy_statement[i]);
+        (void) mysql_query(mysql, destroy_statement[i]);
     }
-
-    // ... and close
-    (void) mysql_close(&handle);
 }
 
 // @brief Create the Schema
@@ -142,21 +137,16 @@ void destroySchema() {
 // There is no error checking in this code: if it fails, one of the tests
 // will fall over.
 void createSchema() {
-    // Initialise
-    MYSQL handle;
-    (void) mysql_init(&handle);
+    MySqlHolder mysql;
 
     // Open database
-    (void) mysql_real_connect(&handle, "localhost", "keatest",
+    (void) mysql_real_connect(mysql, "localhost", "keatest",
                               "keatest", "keatest", 0, NULL, 0);
 
     // Execute creation statements.
     for (int i = 0; create_statement[i] != NULL; ++i) {
-        (void) mysql_query(&handle, create_statement[i]);
+        (void) mysql_query(mysql, create_statement[i]);
     }
-
-    // ... and close
-    (void) mysql_close(&handle);
 }
 
 /// @brief Test fixture class for testing MySQL Lease Manager
index 8235c59b21f6e767ea33d9a7b0bf793bfc024392..dcc0204223e4d1d715d2df12f11e96aea934888e 100644 (file)
 
 #include <gtest/gtest.h>
 
-#ifdef HAVE_MYSQL
-#include <mysql/mysql.h>
-#endif
-
 int
 main(int argc, char* argv[]) {
     ::testing::InitGoogleTest(&argc, argv);
@@ -28,9 +24,5 @@ main(int argc, char* argv[]) {
 
     int result = RUN_ALL_TESTS();
 
-#ifdef HAVE_MYSQL
-    mysql_library_end();
-#endif
-
     return (result);
 }