20 #include <cppunit/TestFixture.h> 21 #include <cppunit/extensions/HelperMacros.h> 26 #include <libfodbreposysconf.h> 51 CPPUNIT_TEST_SUITE_END();
60 dbManager =
new fo::DbManager(createTestEnvironment(
"", NULL, 0));
69 dropTestEnvironment(NULL,
"", NULL);
83 CPPUNIT_ASSERT(result);
99 CPPUNIT_ASSERT(manager.
queryPrintf(
"CREATE TABLE tbl(col integer)"));
119 CPPUNIT_ASSERT(manager.
queryPrintf(
"CREATE TABLE tbl(col integer)"));
120 CPPUNIT_ASSERT(manager.
queryPrintf(
"INSERT INTO tbl(col) VALUES (%d)", val));
125 CPPUNIT_ASSERT(result);
127 CPPUNIT_ASSERT_EQUAL(1, result.getRowCount());
129 std::vector<std::string> row = result.getRow(0);
131 CPPUNIT_ASSERT_EQUAL(1, (
int) row.size());
132 CPPUNIT_ASSERT_EQUAL(std::string(
"17"), row[0]);
134 std::vector<int> results = result.getSimpleResults(0, atoi);
135 std::vector<int> expected = {17};
137 CPPUNIT_ASSERT_EQUAL(expected, results);
152 CPPUNIT_ASSERT(manager.
queryPrintf(
"CREATE TABLE tbl(col integer)"));
157 "INSERT INTO tbl(col) VALUES ($1)",
162 for (
int i = 0; i < 5; ++i) {
170 CPPUNIT_ASSERT(result);
174 std::vector<int> expected = {0, 2, 4, 6, 8};
176 CPPUNIT_ASSERT_EQUAL(expected, results);
194 CPPUNIT_ASSERT(manager1.
queryPrintf(
"CREATE TABLE tbl(col integer)"));
201 "INSERT INTO tbl(col) VALUES ($1)",
208 "INSERT INTO tbl(col) VALUES ($1)",
212 CPPUNIT_ASSERT(manager1.
begin());
213 CPPUNIT_ASSERT(manager2.
begin());
214 for (
int i = 0; i < 5; ++i) {
215 CPPUNIT_ASSERT(manager1.
execPrepared(preparedStatement1, (i + 1) * 2));
216 CPPUNIT_ASSERT(manager2.
execPrepared(preparedStatement2, i * 2));
218 CPPUNIT_ASSERT(manager1.
commit());
219 CPPUNIT_ASSERT(manager2.
rollback());
224 CPPUNIT_ASSERT(result);
226 std::vector<int> results = result.getSimpleResults(0, atoi);
228 std::vector<int> expected = {2, 4, 6, 8, 10};
230 CPPUNIT_ASSERT_EQUAL(expected, results);
245 std::cout << std::endl <<
"expecting errors" << std::endl <<
"-----" << std::endl;
249 std::cout << std::endl <<
"-----" << std::endl;
251 CPPUNIT_ASSERT(!result);
267 CPPUNIT_ASSERT(system((std::string(
"install -D ../../../../VERSION '") + sysConf +
"/mods-enabled/an agent name/VERSION'").c_str()) >= 0);
268 char const* argv[] = {
"an agent name",
"-c", sysConf};
275 CPPUNIT_ASSERT(result);
278 CPPUNIT_ASSERT(system((std::string(
"rm -rf '") + sysConf +
"/mods-enabled'").c_str()) >= 0);
void test_runSimpleQuery()
void test_runBadCommandQueryCheckIfError()
bool tableExists(const char *tableName) const
QueryResult execPrepared(fo_dbManager_PreparedStatement *stmt,...) const
Execute a prepared statement with new parameters.
void test_runSchedulerConnectConstructor()
Utility functions for test.
fo_dbManager * getStruct_dbManager() const
void test_runCommandQueryCheckIfSuccess()
fo::DbManager * dbManager
Object for DbManager.
QueryResult queryPrintf(const char *queryFormat,...) const
Execute a query in printf format.
void test_runPreparedStatement()
char * get_sysconfdir()
get sysconfig dir path just created by create_db_repo_sysconf()
std::vector< T > getSimpleResults(int columnN, T(functionP)(const char *)) const
Get vector of a single column from query result.
Test cases for CPP DB Manager.