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> 5*e6a0ab89SJeremy L Thompson #include <ceed/backend.h> 6cdf32b93SJeremy L Thompson #include <stddef.h> 7cdf32b93SJeremy L Thompson #include <string.h> 8cdf32b93SJeremy L Thompson 9cdf32b93SJeremy L Thompson typedef struct { 10cdf32b93SJeremy L Thompson double time; 117bfe0f0eSJeremy L Thompson int count[2]; 12cdf32b93SJeremy L Thompson } TestContext; 13cdf32b93SJeremy L Thompson 14cdf32b93SJeremy L Thompson int main(int argc, char **argv) { 15cdf32b93SJeremy L Thompson Ceed ceed; 16cdf32b93SJeremy L Thompson CeedQFunctionContext ctx; 173668ca4bSJeremy L Thompson CeedContextFieldLabel time_label, count_label; 183668ca4bSJeremy L Thompson 19cdf32b93SJeremy L Thompson TestContext ctx_data = { 20cdf32b93SJeremy L Thompson .time = 1.0, 217bfe0f0eSJeremy L Thompson .count = {13, 42}, 22cdf32b93SJeremy L Thompson }; 23cdf32b93SJeremy L Thompson 24cdf32b93SJeremy L Thompson CeedInit(argv[1], &ceed); 25cdf32b93SJeremy L Thompson 26cdf32b93SJeremy L Thompson CeedQFunctionContextCreate(ceed, &ctx); 27cdf32b93SJeremy L Thompson CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_USE_POINTER, 28cdf32b93SJeremy L Thompson sizeof(TestContext), &ctx_data); 29cdf32b93SJeremy L Thompson 30cdf32b93SJeremy L Thompson CeedQFunctionContextRegisterDouble(ctx, "time", offsetof(TestContext, time), 317bfe0f0eSJeremy L Thompson 1, "current time"); 32cdf32b93SJeremy L Thompson CeedQFunctionContextRegisterInt32(ctx, "count", offsetof(TestContext, count), 337bfe0f0eSJeremy L Thompson 2, "some sort of counter"); 34cdf32b93SJeremy L Thompson 353668ca4bSJeremy L Thompson const CeedContextFieldLabel *field_labels; 36cdf32b93SJeremy L Thompson CeedInt num_fields; 373668ca4bSJeremy L Thompson CeedQFunctionContextGetAllFieldLabels(ctx, &field_labels, &num_fields); 38cdf32b93SJeremy L Thompson if (num_fields != 2) 39cdf32b93SJeremy L Thompson // LCOV_EXCL_START 407bfe0f0eSJeremy L Thompson printf("Incorrect number of fields set: %d != 2\n", num_fields); 41cdf32b93SJeremy L Thompson // LCOV_EXCL_STOP 427bfe0f0eSJeremy L Thompson 430f86cbe7SJeremy L Thompson const char *name; 447bfe0f0eSJeremy L Thompson size_t num_values; 450f86cbe7SJeremy L Thompson CeedContextFieldType type; 467bfe0f0eSJeremy L Thompson CeedContextFieldLabelGetDescription(field_labels[0], &name, NULL, &num_values, 477bfe0f0eSJeremy L Thompson &type); 480f86cbe7SJeremy L Thompson if (strcmp(name, "time")) 490f86cbe7SJeremy L Thompson // LCOV_EXCL_START 507bfe0f0eSJeremy L Thompson printf("Incorrect context field description for time: \"%s\" != \"time\"\n", 510f86cbe7SJeremy L Thompson name); 520f86cbe7SJeremy L Thompson // LCOV_EXCL_STOP 537bfe0f0eSJeremy L Thompson if (num_values != 1) 547bfe0f0eSJeremy L Thompson // LCOV_EXCL_START 557bfe0f0eSJeremy L Thompson printf("Incorrect context field number of values for time: \"%ld\" != 1\n", 567bfe0f0eSJeremy L Thompson num_values); 577bfe0f0eSJeremy L Thompson // LCOV_EXCL_STOP 580f86cbe7SJeremy L Thompson if (type != CEED_CONTEXT_FIELD_DOUBLE) 590f86cbe7SJeremy L Thompson // LCOV_EXCL_START 607bfe0f0eSJeremy L Thompson printf("Incorrect context field type for time: \"%s\" != \"%s\"\n", 610f86cbe7SJeremy L Thompson CeedContextFieldTypes[type], CeedContextFieldTypes[CEED_CONTEXT_FIELD_DOUBLE]); 620f86cbe7SJeremy L Thompson // LCOV_EXCL_STOP 637bfe0f0eSJeremy L Thompson 647bfe0f0eSJeremy L Thompson CeedContextFieldLabelGetDescription(field_labels[1], &name, NULL, &num_values, 657bfe0f0eSJeremy L Thompson &type); 660f86cbe7SJeremy L Thompson if (strcmp(name, "count")) 670f86cbe7SJeremy L Thompson // LCOV_EXCL_START 687bfe0f0eSJeremy L Thompson printf("Incorrect context field description for count: \"%s\" != \"count\"\n", 690f86cbe7SJeremy L Thompson name); 700f86cbe7SJeremy L Thompson // LCOV_EXCL_STOP 717bfe0f0eSJeremy L Thompson if (num_values != 2) 727bfe0f0eSJeremy L Thompson // LCOV_EXCL_START 737bfe0f0eSJeremy L Thompson printf("Incorrect context field number of values for count: \"%ld\" != 2\n", 747bfe0f0eSJeremy L Thompson num_values); 757bfe0f0eSJeremy L Thompson // LCOV_EXCL_STOP 760f86cbe7SJeremy L Thompson if (type != CEED_CONTEXT_FIELD_INT32) 770f86cbe7SJeremy L Thompson // LCOV_EXCL_START 787bfe0f0eSJeremy L Thompson printf("Incorrect context field type for count: \"%s\" != \"%s\"\n", 790f86cbe7SJeremy L Thompson CeedContextFieldTypes[type], CeedContextFieldTypes[CEED_CONTEXT_FIELD_INT32]); 800f86cbe7SJeremy L Thompson // LCOV_EXCL_STOP 81cdf32b93SJeremy L Thompson 823668ca4bSJeremy L Thompson CeedQFunctionContextGetFieldLabel(ctx, "time", &time_label); 837bfe0f0eSJeremy L Thompson double value_time = 2.0; 847bfe0f0eSJeremy L Thompson CeedQFunctionContextSetDouble(ctx, time_label, &value_time); 85cdf32b93SJeremy L Thompson if (ctx_data.time != 2.0) 86cdf32b93SJeremy L Thompson // LCOV_EXCL_START 877bfe0f0eSJeremy L Thompson printf("Incorrect context data for time: %f != 2.0\n", ctx_data.time); 88cdf32b93SJeremy L Thompson // LCOV_EXCL_STOP 89cdf32b93SJeremy L Thompson 903668ca4bSJeremy L Thompson CeedQFunctionContextGetFieldLabel(ctx, "count", &count_label); 917bfe0f0eSJeremy L Thompson int values_count[2] = {14, 43}; 927bfe0f0eSJeremy L Thompson CeedQFunctionContextSetInt32(ctx, count_label, (int *)&values_count); 937bfe0f0eSJeremy L Thompson if (ctx_data.count[0] != 14) 94cdf32b93SJeremy L Thompson // LCOV_EXCL_START 957bfe0f0eSJeremy L Thompson printf("Incorrect context data for count[0]: %d != 14\n", ctx_data.count[0]); 967bfe0f0eSJeremy L Thompson // LCOV_EXCL_STOP 977bfe0f0eSJeremy L Thompson if (ctx_data.count[1] != 43) 987bfe0f0eSJeremy L Thompson // LCOV_EXCL_START 997bfe0f0eSJeremy L Thompson printf("Incorrect context data for count[1]: %d != 43\n", ctx_data.count[1]); 100cdf32b93SJeremy L Thompson // LCOV_EXCL_STOP 101cdf32b93SJeremy L Thompson 102cdf32b93SJeremy L Thompson CeedQFunctionContextDestroy(&ctx); 103cdf32b93SJeremy L Thompson CeedDestroy(&ceed); 104cdf32b93SJeremy L Thompson return 0; 105cdf32b93SJeremy L Thompson } 106