xref: /libCEED/tests/t005-ceed.c (revision d1d35e2f02dc969aee8debf3fd943dd784aa847a)
1477729cfSJeremy L Thompson /// @file
2477729cfSJeremy L Thompson /// Test error storage for a CEED object
3477729cfSJeremy L Thompson /// \test Test error storage for a CEED object
4477729cfSJeremy L Thompson #include <ceed.h>
5477729cfSJeremy L Thompson #include <string.h>
6477729cfSJeremy L Thompson 
7477729cfSJeremy L Thompson int main(int argc, char **argv) {
8477729cfSJeremy L Thompson   Ceed ceed;
9477729cfSJeremy L Thompson 
10477729cfSJeremy L Thompson   CeedInit(argv[1], &ceed);
11477729cfSJeremy L Thompson 
12477729cfSJeremy L Thompson   // Check for standard message with default handler
13*d1d35e2fSjeremylt   const char *err_msg = NULL;
14*d1d35e2fSjeremylt   CeedGetErrorMessage(ceed, &err_msg);
15*d1d35e2fSjeremylt   if (strcmp(err_msg, "No error message stored"))
16477729cfSJeremy L Thompson     // LCOV_EXCL_START
17*d1d35e2fSjeremylt     printf("Unexpected error message received: \"%s\"\n", err_msg);
18477729cfSJeremy L Thompson   // LCOV_EXCL_STOP
19477729cfSJeremy L Thompson 
20477729cfSJeremy L Thompson   // Set error handler to store error message
21477729cfSJeremy L Thompson   CeedSetErrorHandler(ceed, CeedErrorStore);
22477729cfSJeremy L Thompson 
23477729cfSJeremy L Thompson   // Generate error
24477729cfSJeremy L Thompson   CeedVector vec;
25477729cfSJeremy L Thompson   CeedScalar *array;
26477729cfSJeremy L Thompson   CeedVectorCreate(ceed, 10, &vec);
27477729cfSJeremy L Thompson   CeedVectorGetArray(vec, CEED_MEM_HOST, &array);
28477729cfSJeremy L Thompson   CeedVectorGetArray(vec, CEED_MEM_HOST, &array);
29477729cfSJeremy L Thompson 
30477729cfSJeremy L Thompson   // Check error message
31*d1d35e2fSjeremylt   CeedGetErrorMessage(ceed, &err_msg);
32*d1d35e2fSjeremylt   if (!err_msg || !strcmp(err_msg, "No error message stored"))
33477729cfSJeremy L Thompson     // LCOV_EXCL_START
34*d1d35e2fSjeremylt     printf("Unexpected error message received: \"%s\"\n", err_msg);
35477729cfSJeremy L Thompson   // LCOV_EXCL_STOP
36*d1d35e2fSjeremylt   CeedResetErrorMessage(ceed, &err_msg);
37477729cfSJeremy L Thompson 
38477729cfSJeremy L Thompson   // Check error message reset
39*d1d35e2fSjeremylt   CeedGetErrorMessage(ceed, &err_msg);
40*d1d35e2fSjeremylt   if (strcmp(err_msg, "No error message stored"))
41477729cfSJeremy L Thompson     // LCOV_EXCL_START
42*d1d35e2fSjeremylt     printf("Unexpected error message received: \"%s\"\n", err_msg);
43477729cfSJeremy L Thompson   // LCOV_EXCL_STOP
44477729cfSJeremy L Thompson 
45477729cfSJeremy L Thompson   // Cleanup
46477729cfSJeremy L Thompson   CeedVectorRestoreArray(vec, &array);
47477729cfSJeremy L Thompson   CeedVectorDestroy(&vec);
48477729cfSJeremy L Thompson   CeedDestroy(&ceed);
49477729cfSJeremy L Thompson   return 0;
50477729cfSJeremy L Thompson }
51