1 /// @file 2 /// Test registering and setting QFunctionContext fields 3 /// \test Test registering and setting QFunctionContext fields 4 #include <ceed.h> 5 #include <stddef.h> 6 #include <string.h> 7 8 typedef struct { 9 double time; 10 int count; 11 } TestContext; 12 13 int main(int argc, char **argv) { 14 Ceed ceed; 15 CeedQFunctionContext ctx; 16 CeedContextFieldLabel time_label, count_label; 17 18 TestContext ctx_data = { 19 .time = 1.0, 20 .count = 42 21 }; 22 23 CeedInit(argv[1], &ceed); 24 25 CeedQFunctionContextCreate(ceed, &ctx); 26 CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_USE_POINTER, 27 sizeof(TestContext), &ctx_data); 28 29 CeedQFunctionContextRegisterDouble(ctx, "time", offsetof(TestContext, time), 30 "current time"); 31 CeedQFunctionContextRegisterInt32(ctx, "count", offsetof(TestContext, count), 32 "some sort of counter"); 33 34 const CeedContextFieldLabel *field_labels; 35 CeedInt num_fields; 36 CeedQFunctionContextGetAllFieldLabels(ctx, &field_labels, &num_fields); 37 if (num_fields != 2) 38 // LCOV_EXCL_START 39 printf("Incorrect number of fields set: %d != 2", num_fields); 40 // LCOV_EXCL_STOP 41 42 CeedQFunctionContextGetFieldLabel(ctx, "time", &time_label); 43 CeedQFunctionContextSetDouble(ctx, time_label, 2.0); 44 if (ctx_data.time != 2.0) 45 // LCOV_EXCL_START 46 printf("Incorrect context data for time: %f != 2.0", ctx_data.time); 47 // LCOV_EXCL_STOP 48 49 CeedQFunctionContextGetFieldLabel(ctx, "count", &count_label); 50 CeedQFunctionContextSetInt32(ctx, count_label, 43); 51 if (ctx_data.count != 43) 52 // LCOV_EXCL_START 53 printf("Incorrect context data for count: %d != 43", ctx_data.count); 54 // LCOV_EXCL_STOP 55 56 CeedQFunctionContextDestroy(&ctx); 57 CeedDestroy(&ceed); 58 return 0; 59 } 60