1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-06-30 00:44:52 +02:00

Working on tests for QMCKL_ERROR. #15

This commit is contained in:
vijay gopal chilkuri 2021-05-25 13:29:37 +05:30
parent 9479ec51ff
commit 97e74c6c3f

View File

@ -293,6 +293,50 @@ qmckl_set_error(qmckl_context context,
}
#+end_src
* 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
@ -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