From 175b621d7a5244324b5d67c03f50fc138105f73b Mon Sep 17 00:00:00 2001 From: xavi Date: Fri, 13 Sep 2024 22:22:21 -0700 Subject: [PATCH] Added test to check if update task works --- Makefile | 7 +++---- src/dodo.c | 2 +- src/dodo.schema | 2 +- tests/tests.c | 51 +++++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 48 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index ece7703..d5243de 100644 --- a/Makefile +++ b/Makefile @@ -49,13 +49,12 @@ $(X_STRING_OBJ): $(X_STRING_HEADERS) $(SQLITE_OBJ): $(SQLITE_HEADERS) $(CC) -c -o $(OBJ_DIR)/$(@F) $(CFLAGS) $(SQLITE_SRC) -dodo: test - ./test - rm test +dodo: $(OBJ) $(CC) -o $@ $(CFLAGS) $(ALL_OBJS) -test: $(OBJ) +test: $(OBJ) $(TEST_SRC) $(CC) -o $@ $(TEST_SRC) $(INC_DIRS) $(DFLAGS) $(CFLAGS) obj/dodo.o $(X_STRING_OBJ) $(SQLITE_OBJ) + ./test install: diff --git a/src/dodo.c b/src/dodo.c index 512dc2c..3f066e4 100644 --- a/src/dodo.c +++ b/src/dodo.c @@ -96,7 +96,7 @@ int checksqlerr(int rc, char *errmsg){ if( rc!=SQLITE_OK ){ fprintf(stderr, "rc = %d\n", rc); fprintf(stderr, "SQL error: %s\n", errmsg); - sqlite3_free(errmsg); + //sqlite3_free(errmsg); return -1; } return 0; diff --git a/src/dodo.schema b/src/dodo.schema index 36aae10..88ac3be 100644 --- a/src/dodo.schema +++ b/src/dodo.schema @@ -1,6 +1,6 @@ CREATE TABLE tasks( task_id INTEGER PRIMARY KEY, - title TEXT NOT NULL, + title TEXT NOT NULL UNIQUE, active_id INTEGER, status TEXT NOT NULL DEFAULT 'backlog', creation_date DATE DEFAULT (date('now')), diff --git a/tests/tests.c b/tests/tests.c index c72719b..40f155b 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -14,9 +14,9 @@ // SET THE NUMBER OF TESTS -#define NUM_TESTS 4 +#define NUM_TESTS 5 -// DEFINE REUSABLE TEST SETUP +// DEFINE REUSABLE TEST SETUPS int set_up_db(sqlite3 **db){ char* home_dir = getenv("HOME"); char* filename = x_strconcat(home_dir, DB_PATH); @@ -30,7 +30,7 @@ int test_add_new_task_no_date(){ printf("%s... ", __func__); int rc = 0; sqlite3 *db; - char *argv[3] = {"", "", "jello"}; + char *argv[3] = {"./dodo", "new", "jello"}; if ( (rc = set_up_db(&db)) ){ return rc; @@ -42,7 +42,7 @@ int test_del_task(){ printf("%s... ", __func__); int rc = 0; sqlite3 *db; - char *argv[3] = {"", "", "jello"}; + char *argv[3] = {"./dodo", "del", "jello"}; if ( rc = set_up_db(&db) ){ return rc; @@ -54,24 +54,58 @@ 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"}; + char *argv_1[3] = {"./dodo", "new", "jello"}; + char *argv_2[3] = {"./dodo", "del", "jello"}; if ( (rc = set_up_db(&db)) ){ return rc; } - if ( rc = add_new_task(db, argc, argv) ){ + if ( rc = add_new_task(db, 3, argv_1) ){ return rc; } - if ( rc = del_task(db, 3, argv) ){ + if ( rc = del_task(db, 3, argv_2) ){ return rc; } return 0; } +int test_add_then_update_task_status_then_delete(){ + printf("%s... ", __func__); + int rc = 0; + sqlite3 *db; + char *argv_1[3] = {"./dodo", "new", "jello"}; + char *argv_2[3] = {"./dodo", "today", "jello"}; + char *argv_3[3] = {"./dodo", "del", "jello"}; + + if ( (rc = set_up_db(&db)) ){ + return rc; + } + + if ( rc = add_new_task(db, 3, argv_1) ){ + return rc; + } + + if ( rc = update_task_status(db, 3, argv_2) ){ + return rc; + } + + if ( rc = del_task(db, 3, argv_3) ){ + return rc; + } + + return 0; +} + +int test_update_task(){ + printf("%s... ", __func__); + int rc = 0; + sqlite3 *db; + +} + // DUMMY TEST int fail(){ printf("%s... ", __func__); @@ -107,6 +141,7 @@ int main(){ tests[1] = test_add_new_task_no_date; tests[2] = test_del_task; tests[3] = test_add_new_task_with_date_and_delete; + tests[4] = test_add_then_update_task_status_then_delete; // END OF PASSING TESTS