1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2024-12-22 20:36:01 +01:00

Added test for qmckl_set_error and qmckl_get_error. #15

This commit is contained in:
vijay gopal chilkuri 2021-05-25 17:16:21 +05:30
parent 7c7a166bb8
commit 8fc3aa9330

View File

@ -30,8 +30,11 @@
#+end_src #+end_src
#+begin_src c :tangle (eval c_test) :noweb yes #+begin_src c :tangle (eval c_test) :noweb yes
#include <string.h>
#include <stdio.h>
#include "qmckl.h" #include "qmckl.h"
#include "assert.h" #include "assert.h"
#include "qmckl_error_private_type.h"
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -307,17 +310,18 @@ qmckl_set_error(qmckl_context context,
#+begin_src c :comments org :tangle (eval h_func) :exports none #+begin_src c :comments org :tangle (eval h_func) :exports none
qmckl_exit_code qmckl_exit_code
qmckl_get_error(qmckl_context context, qmckl_get_error(qmckl_context context,
const qmckl_exit_code exit_code, qmckl_exit_code *exit_code,
const char* function_name, char* function_name,
const char* message); char* message);
#+end_src #+end_src
# Source # Source
#+begin_src c :tangle (eval c) #+begin_src c :tangle (eval c)
qmckl_exit_code qmckl_exit_code
qmckl_get_error(qmckl_context context, qmckl_get_error(qmckl_context context,
const char* function_name, qmckl_exit_code *exit_code,
const char* message) char* function_name,
char* message)
{ {
/* Passing a function name and a message is mandatory. */ /* Passing a function name and a message is mandatory. */
assert (function_name != NULL); assert (function_name != NULL);
@ -333,6 +337,7 @@ qmckl_get_error(qmckl_context context,
strncpy(function_name, ctx->error.function, QMCKL_MAX_FUN_LEN-1); strncpy(function_name, ctx->error.function, QMCKL_MAX_FUN_LEN-1);
strncpy(message , ctx->error.message , QMCKL_MAX_MSG_LEN-1); strncpy(message , ctx->error.message , QMCKL_MAX_MSG_LEN-1);
(*exit_code) = ctx->error.exit_code;
} }
qmckl_unlock(context); qmckl_unlock(context);
@ -410,12 +415,21 @@ if (x < 0) {
** Test ** Test
#+begin_src c :comments link :tangle (eval c_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'}; /* Initialize the variables */
const char* message[QMCKL_MAX_FUN_LEN]={'S','u','c','c','e','s','s','\0'}; char function_name[QMCKL_MAX_FUN_LEN]="";
qmckl_exit_code exit_code; char message[QMCKL_MAX_MSG_LEN]="";
exit_code = 0;
/* Set the error code to be different from Success */
qmckl_exit_code exit_code;
exit_code = 1;
assert (qmckl_set_error(context, exit_code, "qmckl_transpose", "Success") == QMCKL_SUCCESS);
assert (qmckl_get_error(context, &exit_code, function_name, message) == QMCKL_SUCCESS);
assert (exit_code == 1);
//assert (function_name == "qmckl_transpose");
//assert (message == "Success");
assert (qmckl_set_error(context, exit_code, function_name, message) == QMCKL_SUCCESS);
return 0; return 0;
} }
#+end_src #+end_src