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 CeedQFunctionContextRestoreData(ctx, &ctx_data_copy); 31 CeedQFunctionContextRestoreDataRead(ctx, &ctx_data_copy); 32 33 CeedQFunctionContextDestroy(&ctx); 34 CeedDestroy(&ceed); 35 return 0; 36 } 37