xref: /libCEED/tests/t408-qfunction.c (revision 77bb289ab1e4b7f6618bd6e1f5afbd06578dc0f7)
1 /// @file
2 /// Test read access for QFunctionContext data
3 /// \test Test read access for QFunctionContext data
4 #include <ceed.h>
5 #include <math.h>
6 #include <stdio.h>
7 
8 int main(int argc, char **argv) {
9   Ceed                 ceed;
10   CeedQFunctionContext ctx;
11   CeedScalar           ctx_data[5] = {1, 2, 3, 4, 5}, *ctx_data_copy;
12 
13   CeedInit(argv[1], &ceed);
14 
15   CeedQFunctionContextCreate(ceed, &ctx);
16   CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_COPY_VALUES, sizeof(ctx_data), &ctx_data);
17 
18   // Get data access
19   CeedQFunctionContextGetDataRead(ctx, CEED_MEM_HOST, &ctx_data_copy);
20   if (ctx_data_copy[4] != 5) {
21     // LCOV_EXCL_START
22     printf("error reading data: %f != 5.0\n", ctx_data_copy[4]);
23     // LCOV_EXCL_STOP
24   }
25   CeedQFunctionContextRestoreDataRead(ctx, &ctx_data_copy);
26 
27   // Check access protection - should error
28   CeedQFunctionContextGetDataRead(ctx, CEED_MEM_HOST, &ctx_data_copy);
29   CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &ctx_data_copy);
30   // LCOV_EXCL_START
31   CeedQFunctionContextRestoreData(ctx, &ctx_data_copy);
32   CeedQFunctionContextRestoreDataRead(ctx, &ctx_data_copy);
33 
34   CeedQFunctionContextDestroy(&ctx);
35   CeedDestroy(&ceed);
36   return 0;
37   // LCOV_EXCL_STOP
38 }
39