Added test to check if update task works

This commit is contained in:
xavi 2024-09-13 22:22:21 -07:00
parent 10999563d3
commit 175b621d7a
4 changed files with 48 additions and 14 deletions

View File

@ -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:

View File

@ -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;

View File

@ -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')),

View File

@ -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