1891038deSjeremylt /// @file
2891038deSjeremylt /// Test creation, setting, and taking data for QFunctionContext
3891038deSjeremylt /// \test Test creation, setting, and taking data for QFunctionContext
4891038deSjeremylt #include <ceed.h>
5891038deSjeremylt #include <math.h>
6*49aac155SJeremy L Thompson #include <stdio.h>
7891038deSjeremylt
main(int argc,char ** argv)8891038deSjeremylt int main(int argc, char **argv) {
9891038deSjeremylt Ceed ceed;
10891038deSjeremylt CeedQFunctionContext ctx;
114fee36f0SJeremy L Thompson CeedScalar ctx_data[5] = {1, 2, 3, 4, 5}, *ctx_data_copy;
12891038deSjeremylt
13891038deSjeremylt CeedInit(argv[1], &ceed);
14891038deSjeremylt
150f58c348SJeremy L Thompson // Set borrowed pointer
16891038deSjeremylt CeedQFunctionContextCreate(ceed, &ctx);
174fee36f0SJeremy L Thompson CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_USE_POINTER, sizeof(ctx_data), &ctx_data);
18891038deSjeremylt
190f58c348SJeremy L Thompson // Update borrowed pointer
204fee36f0SJeremy L Thompson CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &ctx_data_copy);
214fee36f0SJeremy L Thompson ctx_data_copy[4] = 6;
224fee36f0SJeremy L Thompson CeedQFunctionContextRestoreData(ctx, &ctx_data_copy);
234fee36f0SJeremy L Thompson if (ctx_data[4] != 6) printf("error modifying data: %f != 6.0\n", ctx_data[4]);
24891038deSjeremylt
250f58c348SJeremy L Thompson // Take back borrowed pointer
264fee36f0SJeremy L Thompson CeedQFunctionContextTakeData(ctx, CEED_MEM_HOST, &ctx_data_copy);
274fee36f0SJeremy L Thompson if (ctx_data_copy[4] != 6) printf("error accessing borrowed data: %f != 6.0\n", ctx_data_copy[4]);
280f58c348SJeremy L Thompson
290f58c348SJeremy L Thompson // Set copied data
304fee36f0SJeremy L Thompson ctx_data[4] = 6;
314fee36f0SJeremy L Thompson CeedQFunctionContextSetData(ctx, CEED_MEM_HOST, CEED_COPY_VALUES, sizeof(ctx_data), &ctx_data);
320f58c348SJeremy L Thompson
330f58c348SJeremy L Thompson // Check copied data
344fee36f0SJeremy L Thompson CeedQFunctionContextGetData(ctx, CEED_MEM_HOST, &ctx_data_copy);
354fee36f0SJeremy L Thompson if (ctx_data_copy[4] != 6) printf("error accessing copied data: %f != 6.0\n", ctx_data_copy[4]);
364fee36f0SJeremy L Thompson CeedQFunctionContextRestoreData(ctx, &ctx_data_copy);
370f58c348SJeremy L Thompson
38891038deSjeremylt CeedQFunctionContextDestroy(&ctx);
39891038deSjeremylt CeedDestroy(&ceed);
40891038deSjeremylt return 0;
41891038deSjeremylt }
42