libmpm

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

commit bed63db2a0c4a3625ab5329f1479b2dea57db707
parent eb237882a887a3a74d8d1f84118f2d30acdad749
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Tue, 30 May 2017 18:45:57 +0200

Add(Tests): Add tests for error:

Fix a wrong reset value too

Diffstat:
Msrc/error.c | 2+-
Mtests/main.c | 1+
Mtests/test.h | 1+
Atests/test_error.c | 20++++++++++++++++++++
4 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/error.c b/src/error.c @@ -47,6 +47,6 @@ const char *mpm_strerror(mpm_error_t err_num) { if (err_num > 0 && err_num < ERR_LAST) ret = g_str_errors[err_num]; - err_num = ERR_NO_ERROR; + g_error = ERR_NO_ERROR; return ret; } diff --git a/tests/main.c b/tests/main.c @@ -5,6 +5,7 @@ int main(void) { mpm_init(); + register_test_error(); register_flags_test(); register_test_database(); register_test_files(); diff --git a/tests/test.h b/tests/test.h @@ -17,6 +17,7 @@ void register_test_category(void); void register_test_config(void); void register_test_packer(void); void register_test_compile(void); +void register_test_error(void); void clean_db(const char *name); int free_sql_results(void *ptr); diff --git a/tests/test_error.c b/tests/test_error.c @@ -0,0 +1,20 @@ +#include "test.h" + +TEST(set_mpm_error) { + TEST_ASSERT(get_mpm_error() == ERR_NO_ERROR, "Default value for errors is wrong"); + set_mpm_error(ERR_MEMORY); + return TEST_SUCCESS; +} + +TEST(get_mpm_error) { + TEST_ASSERT(get_mpm_error() == ERR_MEMORY, "Value is wrong"); + TEST_ASSERT(strcmp(mpm_strerror(get_mpm_error()), "Insufficient memory") == 0, + "String is wrong"); + TEST_ASSERT(get_mpm_error() == ERR_NO_ERROR, "Default value for errors is wrong"); + return TEST_SUCCESS; +} + +void register_test_error(void) { + reg_test("error", set_mpm_error); + reg_test("error", get_mpm_error); +}