| t407-qfunction.c (b36f2af8eb4e779074f4d92faffbc034a6db4539) | t407-qfunction.c (3668ca4b583f336c0c2dcc810e26e2ac50a514b8) |
|---|---|
| 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 8typedef struct { 9 double time; 10 int count; 11} TestContext; 12 13int main(int argc, char **argv) { 14 Ceed ceed; 15 CeedQFunctionContext ctx; | 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 8typedef struct { 9 double time; 10 int count; 11} TestContext; 12 13int main(int argc, char **argv) { 14 Ceed ceed; 15 CeedQFunctionContext ctx; |
| 16 CeedContextFieldLabel time_label, count_label; 17 |
|
| 16 TestContext ctx_data = { 17 .time = 1.0, 18 .count = 42 19 }; 20 21 CeedInit(argv[1], &ceed); 22 23 CeedQFunctionContextCreate(ceed, &ctx); 24 CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_USE_POINTER, 25 sizeof(TestContext), &ctx_data); 26 27 CeedQFunctionContextRegisterDouble(ctx, "time", offsetof(TestContext, time), 28 "current time"); 29 CeedQFunctionContextRegisterInt32(ctx, "count", offsetof(TestContext, count), 30 "some sort of counter"); 31 | 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 |
| 32 const CeedQFunctionContextFieldDescription *field_descriptions; | 34 const CeedContextFieldLabel *field_labels; |
| 33 CeedInt num_fields; | 35 CeedInt num_fields; |
| 34 CeedQFunctionContextGetFieldDescriptions(ctx, &field_descriptions, &num_fields); | 36 CeedQFunctionContextGetAllFieldLabels(ctx, &field_labels, &num_fields); |
| 35 if (num_fields != 2) 36 // LCOV_EXCL_START 37 printf("Incorrect number of fields set: %d != 2", num_fields); 38 // LCOV_EXCL_STOP | 37 if (num_fields != 2) 38 // LCOV_EXCL_START 39 printf("Incorrect number of fields set: %d != 2", num_fields); 40 // LCOV_EXCL_STOP |
| 39 if (strcmp(field_descriptions[0].name, "time")) 40 // LCOV_EXCL_START 41 printf("Incorrect context field description for time: \"%s\" != \"time\"", 42 field_descriptions[0].name); 43 // LCOV_EXCL_STOP 44 if (strcmp(field_descriptions[1].name, "count")) 45 // LCOV_EXCL_START 46 printf("Incorrect context field description for time: \"%s\" != \"count\"", 47 field_descriptions[1].name); 48 // LCOV_EXCL_STOP | |
| 49 | 41 |
| 50 CeedQFunctionContextSetDouble(ctx, "time", 2.0); | 42 CeedQFunctionContextGetFieldLabel(ctx, "time", &time_label); 43 CeedQFunctionContextSetDouble(ctx, time_label, 2.0); |
| 51 if (ctx_data.time != 2.0) 52 // LCOV_EXCL_START 53 printf("Incorrect context data for time: %f != 2.0", ctx_data.time); 54 // LCOV_EXCL_STOP 55 | 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 |
| 56 CeedQFunctionContextSetInt32(ctx, "count", 43); | 49 CeedQFunctionContextGetFieldLabel(ctx, "count", &count_label); 50 CeedQFunctionContextSetInt32(ctx, count_label, 43); |
| 57 if (ctx_data.count != 43) 58 // LCOV_EXCL_START 59 printf("Incorrect context data for count: %d != 43", ctx_data.count); 60 // LCOV_EXCL_STOP 61 62 CeedQFunctionContextDestroy(&ctx); 63 CeedDestroy(&ceed); 64 return 0; 65} | 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} |