8 #include <CUnit/CUnit.h>
9 #include <libfocunit.h>
15 void test_queryAllLicenses() {
16 PGresult* licenses = queryAllLicenses(
dbManager);
18 CU_ASSERT_PTR_NOT_NULL_FATAL(licenses);
20 FO_ASSERT_EQUAL_FATAL(PQntuples(licenses), 2);
25 void test_getTextFromId() {
26 char* lic1Text = getLicenseTextForLicenseRefId(
dbManager, 1);
27 CU_ASSERT_STRING_EQUAL(lic1Text,
"gnu general public license version 3,");
31 void test_getTextFromBadId() {
32 printf(
"test: expecting a warning: \n--\n");
33 char* notExistingText = getLicenseTextForLicenseRefId(
dbManager, LONG_MAX);
35 CU_ASSERT_STRING_EQUAL(notExistingText,
"");
36 g_free(notExistingText);
39 #define doOrReturnError(fmt, ...) do {\
40 PGresult* copy = fo_dbManager_Exec_printf(dbManager, fmt, #__VA_ARGS__); \
48 int database_setUpFunc() {
53 if (!fo_dbManager_tableExists(
dbManager,
"license_ref")) {
54 doOrReturnError(
"CREATE TABLE license_ref(rf_pk int, rf_shortname text, rf_text text, rf_active bool, rf_detector_type int)",);
57 doOrReturnError(
"INSERT INTO license_ref(rf_pk, rf_shortname, rf_text, rf_active ,rf_detector_type) "
58 "VALUES (1, 'GPL-3.0', 'gnu general public license version 3,', true, 1)",);
59 doOrReturnError(
"INSERT INTO license_ref(rf_pk, rf_shortname, rf_text, rf_active ,rf_detector_type) "
60 "VALUES (2, 'GPL-2.0', 'gnu general public license, version 2', true, 1)",);
65 int database_tearDownFunc() {
70 doOrReturnError(
"DROP TABLE license_ref",);
75 CU_TestInfo database_testcases[] = {
76 {
"Testing get lla licenses:", test_queryAllLicenses},
77 {
"Testing get text from id:", test_getTextFromId},
78 {
"Testing get text from bad id:", test_getTextFromBadId},
fo_dbManager * dbManager
fo_dbManager object