Added three tests

This commit is contained in:
xavi 2024-09-12 22:48:15 -07:00
parent c27eae1dcc
commit 10999563d3
3 changed files with 75 additions and 11 deletions

View File

@ -28,7 +28,9 @@ TEST_OBJ = $(patsubst $(TEST_DIR)/%.c, $(OBJ_DIR)/%.o, $(TEST_SRC))
SQLITE_DB_SCHEMA = $(SRC_DIR)/dodo.schema
INC_DIRS=-I./$(X_STRING_DIR)/src/ -I./$(SQLITE_DIR)/src/
INC_DIRS=-I./$(X_STRING_DIR)/src/ -I./$(SQLITE_DIR)/src/ -I./src
CFLAGS = -ggdb
HOME_DIR = $$HOME
CONFIG_DIR = /.config/dodo
@ -39,21 +41,21 @@ DFLAGS = -DDB_PATH=\"$(DB_FILE)\"
all: dodo
$(OBJ): $(X_STRING_OBJ) $(SQLITE_OBJ) $(HEADERS)
$(CC) -c -o $(OBJ_DIR)/$(@F) $(INC_DIRS) $(DFLAGS) $(SRC_DIR)/$(@F:.o=.c)
$(CC) -c -o $(OBJ_DIR)/$(@F) $(INC_DIRS) $(CFLAGS) $(DFLAGS) $(SRC_DIR)/$(@F:.o=.c)
$(X_STRING_OBJ): $(X_STRING_HEADERS)
$(CC) -c -o $(OBJ_DIR)/$(@F) $(X_STRING_SRC)
$(CC) -c -o $(OBJ_DIR)/$(@F) $(CFLAGS) $(X_STRING_SRC)
$(SQLITE_OBJ): $(SQLITE_HEADERS)
$(CC) -c -o $(OBJ_DIR)/$(@F) $(SQLITE_SRC)
$(CC) -c -o $(OBJ_DIR)/$(@F) $(CFLAGS) $(SQLITE_SRC)
dodo: test
$(CC) -o $@ $(ALL_OBJS)
./test
rm test
$(CC) -o $@ $(CFLAGS) $(ALL_OBJS)
test: $(OBJ)
$(CC) -o $@ $(TEST_SRC) obj/dodo.o $(X_STRING_OBJ) $(SQLITE_OBJ)
./test
rm ./test
$(CC) -o $@ $(TEST_SRC) $(INC_DIRS) $(DFLAGS) $(CFLAGS) obj/dodo.o $(X_STRING_OBJ) $(SQLITE_OBJ)
install:

View File

@ -1,6 +1,6 @@
CREATE TABLE tasks(
task_id INTEGER PRIMARY KEY,
title TEXT NOT NULL UNIQUE,
title TEXT NOT NULL,
active_id INTEGER,
status TEXT NOT NULL DEFAULT 'backlog',
creation_date DATE DEFAULT (date('now')),

View File

@ -1,4 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
// printf Formating
#define X_RED "\x1B[31m"
@ -6,16 +7,74 @@
#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 1
#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;
}
@ -26,7 +85,7 @@ void run_tests(int (**tests)()){
int errors = 0;
for ( i = 0; i < NUM_TESTS; i++ ){
printf("Test #%d... ", i);
printf("Test #%d: ", i);
if ( tests[i]() == 0){
printf("%spassed%s\n", X_GREEN, X_RST);
}
@ -45,6 +104,9 @@ int main(){
// 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