From 97e74c6c3f58bb7358e1e801d9cf7c573412bc0c Mon Sep 17 00:00:00 2001 From: vijay gopal chilkuri Date: Tue, 25 May 2021 13:29:37 +0530 Subject: [PATCH] Working on tests for QMCKL_ERROR. #15 --- org/qmckl_error.org | 48 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/org/qmckl_error.org b/org/qmckl_error.org index 49b6616..9c958cf 100644 --- a/org/qmckl_error.org +++ b/org/qmckl_error.org @@ -293,8 +293,52 @@ qmckl_set_error(qmckl_context context, } #+end_src -* Failing +* Get the error + Upon error, the error type and message can be obtained from the + context using ~qmckl_get_error~. The message and function name + is returned in the variables provided. Therefore, passing a + function name and message is mandatory. + + # Header + #+begin_src c :comments org :tangle (eval h_func) :exports none +qmckl_exit_code +qmckl_get_error(qmckl_context context, + const qmckl_exit_code exit_code, + const char* function_name, + const char* message); + #+end_src + + # Source + #+begin_src c :tangle (eval c) +qmckl_exit_code +qmckl_get_error(qmckl_context context, + const char* function_name, + const char* message) +{ + /* Passing a function name and a message is mandatory. */ + assert (function_name != NULL); + assert (message != NULL); + + /* The context is assumed to exist. */ + assert (qmckl_context_check(context) != QMCKL_NULL_CONTEXT); + + qmckl_lock(context); + { + qmckl_context_struct* const ctx = (qmckl_context_struct* const) context; + assert (ctx != NULL); /* Impossible because the context is valid. */ + + strncpy(function_name, ctx->error.function, QMCKL_MAX_FUN_LEN-1); + strncpy(message , ctx->error.message , QMCKL_MAX_MSG_LEN-1); + } + qmckl_unlock(context); + + return QMCKL_SUCCESS; +} + #+end_src + +* Failing + To make a function fail, the ~qmckl_failwith~ function should be called, such that information about the failure is stored in the context. The desired exit code is given as an argument, as @@ -363,6 +407,8 @@ if (x < 0) { ** Test #+begin_src c :comments link :tangle (eval c_test) +const char* function_name[QMCKL_MAX_FUN_LEN]={'q','m','c','k','l','_','t','r','a','n','s','p','o','s','e','\0'}; +const char* message[QMCKL_MAX_FUN_LEN]={'S','u','c','c','e','s','s','\0'}; return 0; } #+end_src