xref: /libCEED/tests/t408-qfunction.c (revision 4fee36f0a30516a0b5ad51bf7eb3b32d83efd623)
128bfd0b7SJeremy L Thompson /// @file
228bfd0b7SJeremy L Thompson /// Test read access for QFunctionContext data
328bfd0b7SJeremy L Thompson /// \test Test read access for QFunctionContext data
428bfd0b7SJeremy L Thompson #include <ceed.h>
528bfd0b7SJeremy L Thompson #include <math.h>
628bfd0b7SJeremy L Thompson 
728bfd0b7SJeremy L Thompson int main(int argc, char **argv) {
828bfd0b7SJeremy L Thompson   Ceed                 ceed;
928bfd0b7SJeremy L Thompson   CeedQFunctionContext ctx;
10*4fee36f0SJeremy L Thompson   CeedScalar           ctx_data[5] = {1, 2, 3, 4, 5}, *ctx_data_copy;
1128bfd0b7SJeremy L Thompson 
1228bfd0b7SJeremy L Thompson   CeedInit(argv[1], &ceed);
1328bfd0b7SJeremy L Thompson 
1428bfd0b7SJeremy L Thompson   CeedQFunctionContextCreate(ceed, &ctx);
15*4fee36f0SJeremy L Thompson   CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_COPY_VALUES, sizeof(ctx_data), &ctx_data);
1628bfd0b7SJeremy L Thompson 
1728bfd0b7SJeremy L Thompson   // Get data access
18*4fee36f0SJeremy L Thompson   CeedQFunctionContextGetDataRead(ctx, CEED_MEM_HOST, &ctx_data_copy);
19*4fee36f0SJeremy L Thompson   if (ctx_data_copy[4] != 5)
2028bfd0b7SJeremy L Thompson     // LCOV_EXCL_START
21*4fee36f0SJeremy L Thompson     printf("error reading data: %f != 5.0\n", ctx_data_copy[4]);
2228bfd0b7SJeremy L Thompson   // LCOV_EXCL_STOP
23*4fee36f0SJeremy L Thompson   CeedQFunctionContextRestoreDataRead(ctx, &ctx_data_copy);
2428bfd0b7SJeremy L Thompson 
2528bfd0b7SJeremy L Thompson   // Check access protection - should error
26*4fee36f0SJeremy L Thompson   CeedQFunctionContextGetDataRead(ctx, CEED_MEM_HOST, &ctx_data_copy);
27*4fee36f0SJeremy L Thompson   CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &ctx_data_copy);
28*4fee36f0SJeremy L Thompson   CeedQFunctionContextRestoreData(ctx, &ctx_data_copy);
29*4fee36f0SJeremy L Thompson   CeedQFunctionContextRestoreDataRead(ctx, &ctx_data_copy);
3028bfd0b7SJeremy L Thompson 
3128bfd0b7SJeremy L Thompson   CeedQFunctionContextDestroy(&ctx);
3228bfd0b7SJeremy L Thompson   CeedDestroy(&ceed);
3328bfd0b7SJeremy L Thompson   return 0;
3428bfd0b7SJeremy L Thompson }
35