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