18 #include <CUnit/CUnit.h> 19 #include <libfocunit.h> 25 void test_queryAllLicenses() {
26 PGresult* licenses = queryAllLicenses(dbManager);
28 CU_ASSERT_PTR_NOT_NULL_FATAL(licenses);
30 FO_ASSERT_EQUAL_FATAL(PQntuples(licenses), 2);
35 void test_getTextFromId() {
36 char* lic1Text = getLicenseTextForLicenseRefId(dbManager, 1);
37 CU_ASSERT_STRING_EQUAL(lic1Text,
"gnu general public license version 3,");
41 void test_getTextFromBadId() {
42 printf(
"test: expecting a warning: \n--\n");
43 char* notExistingText = getLicenseTextForLicenseRefId(dbManager, LONG_MAX);
45 CU_ASSERT_STRING_EQUAL(notExistingText,
"");
46 g_free(notExistingText);
49 #define doOrReturnError(fmt, ...) do {\ 50 PGresult* copy = fo_dbManager_Exec_printf(dbManager, fmt, #__VA_ARGS__); \ 58 int database_setUpFunc() {
63 if (!fo_dbManager_tableExists(dbManager,
"license_ref")) {
64 doOrReturnError(
"CREATE TABLE license_ref(rf_pk int, rf_shortname text, rf_text text, rf_active bool, rf_detector_type int)",);
67 doOrReturnError(
"INSERT INTO license_ref(rf_pk, rf_shortname, rf_text, rf_active ,rf_detector_type) " 68 "VALUES (1, 'GPL-3.0', 'gnu general public license version 3,', true, 1)",);
69 doOrReturnError(
"INSERT INTO license_ref(rf_pk, rf_shortname, rf_text, rf_active ,rf_detector_type) " 70 "VALUES (2, 'GPL-2.0', 'gnu general public license, version 2', true, 1)",);
75 int database_tearDownFunc() {
80 doOrReturnError(
"DROP TABLE license_ref",);
85 CU_TestInfo database_testcases[] = {
86 {
"Testing get lla licenses:", test_queryAllLicenses},
87 {
"Testing get text from id:", test_getTextFromId},
88 {
"Testing get text from bad id:", test_getTextFromBadId},
fo_dbManager * dbManager
fo_dbManager object