1 static const char help[] = "Tests PetscOptionsPrefix{Push,Pop} and PetscOptionsDeprecated\n\n";
2
3 #include <petscsys.h>
4
main(int argc,char * argv[])5 int main(int argc, char *argv[])
6 {
7 PetscInt opts[6] = {0};
8 PetscBool hascl = PETSC_FALSE, hasstr = PETSC_FALSE;
9 char deprecated_prefix[PETSC_MAX_OPTION_NAME] = {0};
10 PetscBool oldopt = PETSC_FALSE, newopt = PETSC_FALSE, useprefix;
11
12 PetscFunctionBeginUser;
13 PetscCall(PetscInitialize(&argc, &argv, 0, help));
14 PetscCall(PetscOptionsSetValue(NULL, "-zero", "0"));
15 PetscCall(PetscOptionsPrefixPush(NULL, "a_"));
16 PetscCall(PetscOptionsSetValue(NULL, "-one", "1"));
17 PetscCall(PetscOptionsPrefixPush(NULL, "bb_"));
18 PetscCall(PetscOptionsSetValue(NULL, "-two", "2"));
19 PetscCall(PetscOptionsPrefixPop(NULL));
20 PetscCall(PetscOptionsSetValue(NULL, "-three", "3"));
21 PetscCall(PetscOptionsPrefixPush(NULL, "cc_"));
22 PetscCall(PetscOptionsPrefixPush(NULL, "ddd_"));
23 PetscCall(PetscOptionsSetValue(NULL, "-four", "4"));
24 PetscCall(PetscOptionsPrefixPop(NULL));
25 PetscCall(PetscOptionsPrefixPop(NULL));
26 PetscCall(PetscOptionsPrefixPop(NULL));
27 PetscCall(PetscOptionsSetValue(NULL, "-five", "5"));
28
29 PetscCall(PetscOptionsGetInt(NULL, 0, "-zero", &opts[0], 0));
30 PetscCall(PetscOptionsGetInt(NULL, 0, "-a_one", &opts[1], 0));
31 PetscCall(PetscOptionsGetInt(NULL, 0, "-a_bb_two", &opts[2], 0));
32 PetscCall(PetscOptionsGetInt(NULL, 0, "-a_three", &opts[3], 0));
33 PetscCall(PetscOptionsGetInt(NULL, 0, "-a_cc_ddd_four", &opts[4], 0));
34 PetscCall(PetscOptionsGetInt(NULL, 0, "-five", &opts[5], 0));
35 PetscCall(PetscPrintf(PETSC_COMM_WORLD, "opts = {%" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT "}\n", opts[0], opts[1], opts[2], opts[3], opts[4], opts[5]));
36
37 PetscCall(PetscOptionsGetBool(NULL, 0, "-cl", &hascl, 0));
38 if (hascl) {
39 PetscCall(PetscMemzero(opts, sizeof(opts)));
40 PetscCall(PetscOptionsGetInt(NULL, 0, "-cl_zero", &opts[0], 0));
41 PetscCall(PetscOptionsGetInt(NULL, 0, "-cl_a_one", &opts[1], 0));
42 PetscCall(PetscOptionsGetInt(NULL, 0, "-cl_a_bb_two", &opts[2], 0));
43 PetscCall(PetscOptionsGetInt(NULL, 0, "-cl_a_three", &opts[3], 0));
44 PetscCall(PetscOptionsGetInt(NULL, 0, "-cl_a_cc_ddd_four", &opts[4], 0));
45 PetscCall(PetscOptionsGetInt(NULL, 0, "-cl_five", &opts[5], 0));
46 PetscCall(PetscPrintf(PETSC_COMM_WORLD, "cl_opts = {%" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT "}\n", opts[0], opts[1], opts[2], opts[3], opts[4], opts[5]));
47 }
48
49 PetscCall(PetscOptionsGetBool(NULL, 0, "-str", &hasstr, 0));
50 if (hasstr) {
51 PetscCall(
52 PetscOptionsInsertString(NULL, "-prefix_push str_ -zero 100 -prefix_push a_ -one 101 -prefix_push bb_ -two 102 -prefix_pop -three 103 -prefix_push cc_ -prefix_push ddd_ -four 104 -prefix_pop -prefix_pop -prefix_pop -five 105 -prefix_pop"));
53 PetscCall(PetscMemzero(opts, sizeof(opts)));
54 PetscCall(PetscOptionsGetInt(NULL, 0, "-str_zero", &opts[0], 0));
55 PetscCall(PetscOptionsGetInt(NULL, 0, "-str_a_one", &opts[1], 0));
56 PetscCall(PetscOptionsGetInt(NULL, 0, "-str_a_bb_two", &opts[2], 0));
57 PetscCall(PetscOptionsGetInt(NULL, 0, "-str_a_three", &opts[3], 0));
58 PetscCall(PetscOptionsGetInt(NULL, 0, "-str_a_cc_ddd_four", &opts[4], 0));
59 PetscCall(PetscOptionsGetInt(NULL, 0, "-str_five", &opts[5], 0));
60 PetscCall(PetscPrintf(PETSC_COMM_WORLD, "str_opts = {%" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT " %" PetscInt_FMT "}\n", opts[0], opts[1], opts[2], opts[3], opts[4], opts[5]));
61 }
62
63 PetscCall(PetscOptionsGetString(NULL, 0, "-deprecated_prefix", deprecated_prefix, sizeof(deprecated_prefix), &useprefix));
64 PetscOptionsBegin(PETSC_COMM_WORLD, useprefix ? deprecated_prefix : NULL, "test deprecated options", NULL);
65 PetscCall(PetscOptionsBool("-old_option", NULL, NULL, oldopt, &oldopt, NULL));
66 PetscCall(PetscOptionsDeprecated("-old_option", "-new_option", "0.0", NULL));
67 PetscCall(PetscOptionsBool("-new_option", NULL, NULL, newopt, &newopt, NULL));
68 PetscOptionsEnd();
69 PetscCall(PetscPrintf(PETSC_COMM_WORLD, "opts = {old %d new %d}\n", oldopt, newopt));
70
71 PetscCall(PetscFinalize());
72 return 0;
73 }
74
75 /*TEST
76
77 test:
78 suffix: 1
79 args: -old_option 1 -new_option 0
80
81 test:
82 suffix: 2
83 args: -cl -prefix_push cl_ -zero 10 -prefix_push a_ -one 11 -prefix_push bb_ -two 12 -prefix_pop -three 13 -prefix_push cc_ -prefix_push ddd_ -four 14 -prefix_pop -prefix_pop -prefix_pop -five 15 -prefix_pop
84
85 test:
86 suffix: 3
87 args: -str -deprecated_prefix zz_ -zz_old_option 0 -zz_new_option 1
88
89 test:
90 suffix: 4
91 args: -deprecated_prefix yy_ -yy_old_option 1
92
93 TEST*/
94