xref: /libCEED/tests/t408-qfunction.c (revision f85e4a7b5ace0077fded2faa470b8becfe6fbd4e)
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>
649aac155SJeremy L Thompson #include <stdio.h>
728bfd0b7SJeremy L Thompson 
828bfd0b7SJeremy L Thompson int main(int argc, char **argv) {
928bfd0b7SJeremy L Thompson   Ceed                 ceed;
1028bfd0b7SJeremy L Thompson   CeedQFunctionContext ctx;
114fee36f0SJeremy L Thompson   CeedScalar           ctx_data[5] = {1, 2, 3, 4, 5}, *ctx_data_copy;
1228bfd0b7SJeremy L Thompson 
1328bfd0b7SJeremy L Thompson   CeedInit(argv[1], &ceed);
1428bfd0b7SJeremy L Thompson 
1528bfd0b7SJeremy L Thompson   CeedQFunctionContextCreate(ceed, &ctx);
164fee36f0SJeremy L Thompson   CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_COPY_VALUES, sizeof(ctx_data), &ctx_data);
1728bfd0b7SJeremy L Thompson 
1828bfd0b7SJeremy L Thompson   // Get data access
194fee36f0SJeremy L Thompson   CeedQFunctionContextGetDataRead(ctx, CEED_MEM_HOST, &ctx_data_copy);
20*f85e4a7bSJeremy L Thompson   if (ctx_data_copy[4] != 5) {
2128bfd0b7SJeremy L Thompson     // LCOV_EXCL_START
224fee36f0SJeremy L Thompson     printf("error reading data: %f != 5.0\n", ctx_data_copy[4]);
2328bfd0b7SJeremy L Thompson     // LCOV_EXCL_STOP
24*f85e4a7bSJeremy L Thompson   }
254fee36f0SJeremy L Thompson   CeedQFunctionContextRestoreDataRead(ctx, &ctx_data_copy);
2628bfd0b7SJeremy L Thompson 
2728bfd0b7SJeremy L Thompson   // Check access protection - should error
284fee36f0SJeremy L Thompson   CeedQFunctionContextGetDataRead(ctx, CEED_MEM_HOST, &ctx_data_copy);
294fee36f0SJeremy L Thompson   CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &ctx_data_copy);
304fee36f0SJeremy L Thompson   CeedQFunctionContextRestoreData(ctx, &ctx_data_copy);
314fee36f0SJeremy L Thompson   CeedQFunctionContextRestoreDataRead(ctx, &ctx_data_copy);
3228bfd0b7SJeremy L Thompson 
3328bfd0b7SJeremy L Thompson   CeedQFunctionContextDestroy(&ctx);
3428bfd0b7SJeremy L Thompson   CeedDestroy(&ceed);
3528bfd0b7SJeremy L Thompson   return 0;
3628bfd0b7SJeremy L Thompson }
37