xref: /libCEED/tests/t005-ceed.c (revision 4fee36f0a30516a0b5ad51bf7eb3b32d83efd623)
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;
9*4fee36f0SJeremy L Thompson   CeedVector  vec;
10*4fee36f0SJeremy L Thompson   CeedScalar *array;
11*4fee36f0SJeremy L Thompson   const char *err_msg = NULL;
12477729cfSJeremy L Thompson 
13477729cfSJeremy L Thompson   CeedInit(argv[1], &ceed);
14477729cfSJeremy L Thompson 
15477729cfSJeremy L Thompson   // Check for standard message with default handler
16d1d35e2fSjeremylt   CeedGetErrorMessage(ceed, &err_msg);
172b730f8bSJeremy L Thompson   if (strcmp(err_msg, "No error message stored")) printf("Unexpected error message received: \"%s\"\n", err_msg);
18477729cfSJeremy L Thompson 
19477729cfSJeremy L Thompson   // Set error handler to store error message
20477729cfSJeremy L Thompson   CeedSetErrorHandler(ceed, CeedErrorStore);
21477729cfSJeremy L Thompson 
22477729cfSJeremy L Thompson   // Generate error
23477729cfSJeremy L Thompson   CeedVectorCreate(ceed, 10, &vec);
24477729cfSJeremy L Thompson   CeedVectorGetArray(vec, CEED_MEM_HOST, &array);
25477729cfSJeremy L Thompson   CeedVectorGetArray(vec, CEED_MEM_HOST, &array);
26477729cfSJeremy L Thompson 
27477729cfSJeremy L Thompson   // Check error message
28d1d35e2fSjeremylt   CeedGetErrorMessage(ceed, &err_msg);
292b730f8bSJeremy L Thompson   if (!err_msg || !strcmp(err_msg, "No error message stored\n")) printf("Unexpected error message received: \"%s\"\n", err_msg);
30d1d35e2fSjeremylt   CeedResetErrorMessage(ceed, &err_msg);
31477729cfSJeremy L Thompson 
32477729cfSJeremy L Thompson   // Check error message reset
33d1d35e2fSjeremylt   CeedGetErrorMessage(ceed, &err_msg);
342b730f8bSJeremy L Thompson   if (strcmp(err_msg, "No error message stored")) printf("Unexpected error message received: \"%s\"\n", err_msg);
35477729cfSJeremy L Thompson 
36477729cfSJeremy L Thompson   // Cleanup
37477729cfSJeremy L Thompson   CeedVectorRestoreArray(vec, &array);
38477729cfSJeremy L Thompson   CeedVectorDestroy(&vec);
39477729cfSJeremy L Thompson   CeedDestroy(&ceed);
40477729cfSJeremy L Thompson   return 0;
41477729cfSJeremy L Thompson }
42