9 #include <cppunit/TestFixture.h>
10 #include <cppunit/extensions/HelperMacros.h>
15 #include <libfodbreposysconf.h>
40 CPPUNIT_TEST_SUITE_END();
61 dropTestEnvironment(NULL,
"", NULL);
75 CPPUNIT_ASSERT(result);
91 CPPUNIT_ASSERT(manager.
queryPrintf(
"CREATE TABLE tbl(col integer)"));
111 CPPUNIT_ASSERT(manager.
queryPrintf(
"CREATE TABLE tbl(col integer)"));
112 CPPUNIT_ASSERT(manager.
queryPrintf(
"INSERT INTO tbl(col) VALUES (%d)", val));
117 CPPUNIT_ASSERT(result);
119 CPPUNIT_ASSERT_EQUAL(1, result.getRowCount());
121 std::vector<std::string> row = result.getRow(0);
123 CPPUNIT_ASSERT_EQUAL(1, (
int) row.size());
124 CPPUNIT_ASSERT_EQUAL(std::string(
"17"), row[0]);
126 std::vector<int> results = result.getSimpleResults(0, atoi);
127 std::vector<int> expected = {17};
129 CPPUNIT_ASSERT_EQUAL(expected, results);
144 CPPUNIT_ASSERT(manager.
queryPrintf(
"CREATE TABLE tbl(col integer)"));
149 "INSERT INTO tbl(col) VALUES ($1)",
154 for (
int i = 0; i < 5; ++i) {
162 CPPUNIT_ASSERT(result);
164 std::vector<int> results = result.getSimpleResults(0, atoi);
166 std::vector<int> expected = {0, 2, 4, 6, 8};
168 CPPUNIT_ASSERT_EQUAL(expected, results);
186 CPPUNIT_ASSERT(manager1.
queryPrintf(
"CREATE TABLE tbl(col integer)"));
193 "INSERT INTO tbl(col) VALUES ($1)",
200 "INSERT INTO tbl(col) VALUES ($1)",
204 CPPUNIT_ASSERT(manager1.
begin());
205 CPPUNIT_ASSERT(manager2.
begin());
206 for (
int i = 0; i < 5; ++i) {
207 CPPUNIT_ASSERT(manager1.
execPrepared(preparedStatement1, (i + 1) * 2));
208 CPPUNIT_ASSERT(manager2.
execPrepared(preparedStatement2, i * 2));
210 CPPUNIT_ASSERT(manager1.
commit());
211 CPPUNIT_ASSERT(manager2.
rollback());
216 CPPUNIT_ASSERT(result);
218 std::vector<int> results = result.getSimpleResults(0, atoi);
220 std::vector<int> expected = {2, 4, 6, 8, 10};
222 CPPUNIT_ASSERT_EQUAL(expected, results);
237 std::cout << std::endl <<
"expecting errors" << std::endl <<
"-----" << std::endl;
241 std::cout << std::endl <<
"-----" << std::endl;
243 CPPUNIT_ASSERT(!result);
260 CPPUNIT_ASSERT(system((std::string(
"install -D ") + BUILDDIR +
"/install/VERSION '" + sysConf +
"/mods-enabled/an agent name/VERSION'").c_str()) >= 0);
261 char const* argv[] = {
"an agent name",
"-c", sysConf};
268 CPPUNIT_ASSERT(result);
271 CPPUNIT_ASSERT(system((std::string(
"rm -rf '") + sysConf +
"/mods-enabled'").c_str()) >= 0);
Test cases for CPP DB Manager.
void test_runPreparedStatement()
void test_runSchedulerConnectConstructor()
void test_runBadCommandQueryCheckIfError()
void test_runCommandQueryCheckIfSuccess()
fo::DbManager * dbManager
Object for DbManager.
void test_runSimpleQuery()
QueryResult execPrepared(fo_dbManager_PreparedStatement *stmt,...) const
Execute a prepared statement with new parameters.
bool tableExists(const char *tableName) const
QueryResult queryPrintf(const char *queryFormat,...) const
Execute a query in printf format.
fo_dbManager * getStruct_dbManager() const
char * get_sysconfdir()
get sysconfig dir path just created by create_db_repo_sysconf()
Utility functions for test.