libmpm

morphux C package management library
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/libmpm

commit fe065d5de728c0304c352519062b315469acbe2d
parent 02aec5a15e25c58819b2785cde9bb4a20f3783d3
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue,  7 Feb 2017 19:05:50 +0100

Fix(Categories): Fix query for categories search:

Finalise some tests for it
Add a test for sql_to_categ

Diffstat:
Minc/database.h | 2+-
Mtests/test_database.c | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/inc/database.h b/inc/database.h @@ -28,7 +28,7 @@ # define QUERY_GET_PACKAGE_BY_ID(id) "SELECT * FROM " PKG_TABLE " WHERE id = %lld", id # define QUERY_GET_PACKAGE_BY_NAME(name) "SELECT * FROM " PKG_TABLE " WHERE name = \"%s\"", name # define QUERY_GET_FILES_BY_ID(id) "SELECT * FROM " FILE_TABLE " WHERE id = %lld", id -# define QUERY_GET_CATEG_BY_ID(id) "SELECT * FROM" CAT_TABLE " WHERE id = %lld", id +# define QUERY_GET_CATEG_BY_ID(id) "SELECT * FROM " CAT_TABLE " WHERE id = %lld", id # define SQL_CREATE_TABLE "CREATE table " # define SQL_INSERT_TABLE "INSERT INTO " diff --git a/tests/test_database.c b/tests/test_database.c @@ -331,6 +331,14 @@ TEST(database_add_category_1) { return TEST_SUCCESS; } +TEST(database_add_category_2) { + u8_t ret = 0; + + ret = mpm_database_add_categ(NULL, NULL); + TEST_ASSERT((ret == 1), "Can't handle NULL pointer"); + return TEST_SUCCESS; +} + TEST(database_get_pkg_by_id_1) { mlist_t *lst; database_t *ptr = NULL; @@ -417,6 +425,31 @@ TEST(database_get_file_by_id_2) { return TEST_SUCCESS; } +TEST(database_get_category_by_id_1) { + mlist_t *lst; + database_t *ptr = NULL; + u8_t ret = 0; + + ptr = mpm_database_open(&ret, NULL); + TEST_ASSERT((ret == 0), "Can't open the database"); + TEST_ASSERT((ptr != NULL), "Can't open the database"); + + ret = mpm_get_categ_by_id(ptr, 1, &lst); + TEST_ASSERT((list_size(lst) == 1), "Can't find the package"); + mpm_database_close(ptr); + list_free(lst, &mpm_category_free); + return TEST_SUCCESS; +} + +TEST(database_get_category_by_id_2) { + mlist_t *lst; + u8_t ret = 0; + + ret = mpm_get_categ_by_id(NULL, 1, &lst); + TEST_ASSERT((ret == 1), "Can't handle NULL pointer"); + return TEST_SUCCESS; +} + TEST(database_sql_to_file) { file_t *ptr = NULL; int st, fd[2]; @@ -440,6 +473,29 @@ TEST(database_sql_to_file) { return TEST_SUCCESS; } +TEST(database_sql_to_categ) { + category_t *ptr = NULL; + int st, fd[2]; + pid_t pid; + + ptr = sql_to_category(NULL, NULL, NULL); + TEST_ASSERT((ptr == NULL), "Pointer is not NULL"); + + ptr = malloc(sizeof(file_t)); + + pipe(fd); + if ((pid = fork()) == 0) { + DUP_ALL_OUTPUTS(fd); + ptr = sql_to_category(ptr, "Unknown", "Nothing"); + } else { + WAIT_AND_CLOSE(pid, st, fd); + TEST_ASSERT((WEXITSTATUS(st) == 1), "Exit code is wrong"); + } + free(ptr); + clean_db(DB_FN); + return TEST_SUCCESS; +} + void clean_db(const char *name) { int st, fd[2]; @@ -512,4 +568,8 @@ void register_test_database(void) { reg_test("database", database_get_file_by_id_2); reg_test("database", database_sql_to_file); reg_test("database", database_add_category_1); + reg_test("database", database_add_category_2); + reg_test("database", database_get_category_by_id_1); + reg_test("database", database_get_category_by_id_2); + reg_test("database", database_sql_to_categ); }