Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <stdlib.h>
00037 #include <stdio.h>
00038 #include <string.h>
00039
00040 #include "ksm/database.h"
00041 #include "test_routines.h"
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074 const char* TdbUsername(void)
00075 {
00076 return getenv("DB_USERNAME");
00077 }
00078
00079 const char* TdbPassword(void)
00080 {
00081 return getenv("DB_PASSWORD");
00082 }
00083
00084 const char* TdbHost(void)
00085 {
00086 return getenv("DB_HOST");
00087 }
00088
00089 const char* TdbName(void)
00090 {
00091 return getenv("DB_NAME");
00092 }
00093
00094 const char* TdbPort(void)
00095 {
00096 return getenv("DB_PORT");
00097 }
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116 int TdbSetup(void)
00117 {
00118 DB_HANDLE handle;
00119 int status;
00120 const char* name = TdbName();
00121 const char* host = TdbHost();
00122 const char* port = TdbPort();
00123 const char* user = TdbUsername();
00124 const char* pass = TdbPassword();
00125
00126 if (name && !strlen(name)) name=NULL;
00127 if (host && !strlen(host)) host=NULL;
00128 if (port && !strlen(port)) port=NULL;
00129 if (user && !strlen(user)) user=NULL;
00130 if (pass && !strlen(pass)) pass=NULL;
00131
00132 #ifdef USE_MYSQL
00133 if (!name || !pass || !user)
00134 {
00135 printf("Please run ./configure with --with-dbname, --with-dbuser, and --with-dbpass. "
00136 "(--with-dbhost and --with-dbport are optional)\n");
00137 exit(1);
00138 }
00139
00140 (void) system("sh ./database_setup_mysql.sh setup");
00141 #else
00142 if (!name) {
00143 printf("Please run ./configure with --with-dbname to indicate the location of a test database.\n");
00144 exit(1);
00145 }
00146
00147 (void) system("sh ./database_setup_sqlite3.sh setup");
00148 #endif
00149
00150 DbInit();
00151
00152 status = DbConnect(&handle, name, host, pass, user, port);
00153
00154 return status;
00155 }
00156
00157 int TdbTeardown(void)
00158 {
00159
00160
00161 (void) DbDisconnect(DbHandle());
00162
00163 DbRundown();
00164
00165 #ifdef USE_MYSQL
00166 (void) system("sh ./database_setup_mysql.sh teardown");
00167 #else
00168 (void) system("sh ./database_setup_sqlite3.sh teardown");
00169 #endif
00170
00171 return 0;
00172 }