120 lines
2.1 KiB
C
120 lines
2.1 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
// printf Formating
|
|
#define X_RED "\x1B[31m"
|
|
#define X_GREEN "\x1B[32m"
|
|
#define X_RST "\x1B[0m"
|
|
|
|
// INSERT HEADERS FOR FUNCS
|
|
#include "sqlite3.h"
|
|
#include "x_string.h"
|
|
#include "x_curses.h"
|
|
#include "dodo.h"
|
|
|
|
|
|
// SET THE NUMBER OF TESTS
|
|
#define NUM_TESTS 4
|
|
|
|
// DEFINE REUSABLE TEST SETUP
|
|
int set_up_db(sqlite3 **db){
|
|
char* home_dir = getenv("HOME");
|
|
char* filename = x_strconcat(home_dir, DB_PATH);
|
|
return opendb(db, filename);
|
|
}
|
|
|
|
|
|
|
|
// DEFINE TESTS
|
|
int test_add_new_task_no_date(){
|
|
printf("%s... ", __func__);
|
|
int rc = 0;
|
|
sqlite3 *db;
|
|
char *argv[3] = {"", "", "jello"};
|
|
|
|
if ( (rc = set_up_db(&db)) ){
|
|
return rc;
|
|
}
|
|
return add_new_task(db, 3, argv);
|
|
}
|
|
|
|
int test_del_task(){
|
|
printf("%s... ", __func__);
|
|
int rc = 0;
|
|
sqlite3 *db;
|
|
char *argv[3] = {"", "", "jello"};
|
|
|
|
if ( rc = set_up_db(&db) ){
|
|
return rc;
|
|
}
|
|
return del_task(db, 3, argv);
|
|
}
|
|
|
|
int test_add_new_task_with_date_and_delete(){
|
|
printf("%s... ", __func__);
|
|
int rc = 0;
|
|
sqlite3 *db;
|
|
const int argc = 4;
|
|
char *argv[] = {"", "", "jello", "2024-03-03"};
|
|
|
|
if ( (rc = set_up_db(&db)) ){
|
|
return rc;
|
|
}
|
|
|
|
if ( rc = add_new_task(db, argc, argv) ){
|
|
return rc;
|
|
}
|
|
|
|
if ( rc = del_task(db, 3, argv) ){
|
|
return rc;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
// DUMMY TEST
|
|
int fail(){
|
|
printf("%s... ", __func__);
|
|
return -1;
|
|
}
|
|
|
|
// END OF TEST DEFINITIONS
|
|
|
|
void run_tests(int (**tests)()){
|
|
int i = 0;
|
|
int errors = 0;
|
|
|
|
for ( i = 0; i < NUM_TESTS; i++ ){
|
|
printf("Test #%d: ", i);
|
|
if ( tests[i]() == 0){
|
|
printf("%spassed%s\n", X_GREEN, X_RST);
|
|
}
|
|
else {
|
|
printf("%sfailed%s\n", X_RED, X_RST);
|
|
errors++;
|
|
}
|
|
}
|
|
|
|
printf("Tests completed with %s%d passed%s", X_GREEN, NUM_TESTS - errors, X_RST);
|
|
printf(" and %s%d failed%s\n", X_RED, errors, X_RST);
|
|
}
|
|
|
|
int main(){
|
|
int (*tests[NUM_TESTS])();
|
|
|
|
// PASS TESTS INTO ARRAY
|
|
tests[0] = fail;
|
|
tests[1] = test_add_new_task_no_date;
|
|
tests[2] = test_del_task;
|
|
tests[3] = test_add_new_task_with_date_and_delete;
|
|
|
|
|
|
// END OF PASSING TESTS
|
|
|
|
// RUN TESTS
|
|
run_tests(tests);
|
|
|
|
return 0;
|
|
}
|
|
|