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