1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#include <BALL/CONCEPT/classTest.h>
#include <BALLTestConfig.h>
// NOTE: This test *cannot* be run automatically unless you provide login credentials
// for the database in your home directory (~/.ballrc). Please make sure that this
// file is readable for *YOU ALONE*, as it will contain the login credentials in
// plain text! See the documentation of BALL/include/BALL/FORMAT/DBInterface.h for
// details.
// If no .ballrc is found, the test will abort without failing!
//
// There is a default database (BALL_DBINTERFACE_TEST) required to exist.
// you can easily create it by modifying the name in the first two lines
// of BALL/source/APPLICATIONS/create_database.sql and executing that
// SQL script.
///////////////////////////
#include <BALL/FORMAT/DBInterface.h>
#include <BALL/FORMAT/MOLFile.h>
#include <BALL/FORMAT/INIFile.h>
#include <QtGui/QApplication>
///////////////////////////
START_TEST(DBInterface)
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
using namespace BALL;
QApplication qapp(argc, argv, false);
DBInterface* dbi_ptr = 0;
CHECK(DBInterface())
dbi_ptr = new DBInterface;
TEST_NOT_EQUAL(dbi_ptr, 0)
RESULT
CHECK(~DBInterface())
delete dbi_ptr;
RESULT
// Make sure we can connect by default to a database named STRUCTURE_TEST
String filename = DBInterface::BALL_DEFAULT_DBRCFILE;
FileSystem::canonizePath(filename);
bool have_access = true;
if (File::isAccessible(filename) && File::isReadable(filename))
{
INIFile rc(filename);
rc.read();
String user = "";
String password = "";
String host = DBInterface::BALL_DEFAULT_DATABASE_HOST;
Size port = DBInterface::BALL_DEFAULT_DATABASE_PORT;
String driver = DBInterface::BALL_DEFAULT_DATABASE_DRIVER;
String database = "BALL_DBINTERFACE_TEST";
if (rc.hasEntry(DBInterface::BALL_DEFAULT_DATABASE_SECTIONNAME, "host"))
{
host = rc.getValue(DBInterface::BALL_DEFAULT_DATABASE_SECTIONNAME, "host");
}
if (rc.hasEntry(DBInterface::BALL_DEFAULT_DATABASE_SECTIONNAME, "driver"))
{
driver = rc.getValue(DBInterface::BALL_DEFAULT_DATABASE_SECTIONNAME, "driver");
}
if (rc.hasEntry(DBInterface::BALL_DEFAULT_DATABASE_SECTIONNAME, "port"))
{
port = (Size)rc.getValue(DBInterface::BALL_DEFAULT_DATABASE_SECTIONNAME, "port").toInt();
}
if (rc.hasEntry(DBInterface::BALL_DEFAULT_DATABASE_SECTIONNAME, "user")
&& rc.hasEntry(DBInterface::BALL_DEFAULT_DATABASE_SECTIONNAME, "password"))
{
user = rc.getValue(DBInterface::BALL_DEFAULT_DATABASE_SECTIONNAME, "user");
password = rc.getValue(DBInterface::BALL_DEFAULT_DATABASE_SECTIONNAME, "password");
}
else
{
// user/password entries are mandatory -- exit if they are not given
have_access = false;
STATUS("Database access: no login/pw available.")
}
if (have_access)
{
DBInterface dbi;
bool success = dbi.connect(user, password, database, host, port, driver);
have_access &= success;
STATUS("Database access: result of connect(...) = " << success)
}
}
else
{
STATUS("Database access: no credentials file.")
}
STATUS("Database access: " << (have_access ? "yes" : "no"))
// Execute the remaining tests only if we could access the database.
if (have_access)
{
CHECK(bool connect())
// ???
RESULT
CHECK((bool connect(const String& user, const String& password, const String& database_name = "structures", const String& host = "diclofenac.informatik.uni-tuebingen.de", Size port = 3306, const String& driver = "QMYSQL3")))
// ???
RESULT
CHECK(ConformationMethod getConformationMethod(ID method_id))
// ???
RESULT
CHECK(ErrorCode getError() const)
// ???
RESULT
CHECK((ID getConformationMethod(const String& method, const String& parameters)))
// ???
RESULT
CHECK(ID lastInsertedID())
// ???
RESULT
CHECK((ID newConformationMethod(const String& method, const String& parameters)))
// ???
RESULT
CHECK((ID newTopology(const System& system, const String& name, const String& source_id, ID id = 0)))
// ???
RESULT
CHECK((ID storeConformation(ID topology, ID method_ID, const System& system)))
// ???
RESULT
CHECK(IDVector getConformationList(ID structure))
// ???
RESULT
CHECK((IDVector getConformationList(ID topology_id, ID method_id)))
// ???
RESULT
CHECK(IDVector getConformationMethods())
// ???
RESULT
CHECK((QSqlQuery& executeQuery() throw(InvalidQuery, NotConnected)))
// ???
RESULT
CHECK((QSqlQuery& executeQuery(const String& query_string) throw(InvalidQuery, NotConnected)))
// ???
RESULT
CHECK(QSqlQuery& query())
// ???
RESULT
CHECK(QVariant value(Position k))
// ???
RESULT
CHECK(Size size())
// ???
RESULT
CHECK(String executedQuery())
// ???
RESULT
CHECK(bool first())
// ???
RESULT
CHECK((bool getMOLFile(ID id, String& file_text, String& name, String& source_id)))
// ???
RESULT
CHECK(bool good() const)
// ???
RESULT
CHECK(bool last())
// ???
RESULT
CHECK(bool next())
// ???
RESULT
CHECK(bool prev())
// ???
RESULT
CHECK(void addBindValue(const QVariant& v))
// ???
RESULT
CHECK((void addBindValue(const QVariant& v1, const QVariant& v2)))
// ???
RESULT
CHECK((void addBindValue(const QVariant& v1, const QVariant& v2, const QVariant& v3)))
// ???
RESULT
CHECK((void addBindValue(const QVariant& v1, const QVariant& v2, const QVariant& v3, const QVariant& v4)))
// ???
RESULT
CHECK((void addMOLFileToSystem(const String& molfile, System& system)))
// ???
RESULT
CHECK((void getTopology(ID topology, System& system)))
// ???
RESULT
CHECK((void loadConformation(const ID conformation, System& system)))
// ???
RESULT
CHECK(void prepare(const String& s))
// ???
RESULT
CHECK(void setError(ErrorCode error))
// ???
RESULT
CHECK((void setTopology(ID topology, const System& system)))
// ???
RESULT
}
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
END_TEST
|