1 static char help[] = "Tests PetscOptionsPushGetViewerOff() via checking output of PetscViewerASCIIPrintf().\n\n"; 2 3 #include <petscviewer.h> 4 5 int main(int argc, char **args) 6 { 7 PetscViewer viewer; 8 PetscViewerFormat format; 9 PetscBool isascii; 10 11 PetscFunctionBeginUser; 12 PetscCall(PetscInitialize(&argc, &args, NULL, help)); 13 PetscCall(PetscOptionsCreateViewer(PETSC_COMM_WORLD, NULL, NULL, "-myviewer", &viewer, &format, NULL)); 14 PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii)); 15 if (isascii) { 16 PetscBool flg; 17 PetscCall(PetscViewerPushFormat(viewer, format)); 18 PetscCall(PetscViewerASCIIPrintf(viewer, "Testing PetscViewerASCIIPrintf %d\n", 0)); 19 PetscCall(PetscViewerPopFormat(viewer)); 20 PetscCall(PetscViewerDestroy(&viewer)); 21 PetscCall(PetscOptionsPushCreateViewerOff(PETSC_TRUE)); 22 PetscCall(PetscOptionsCreateViewer(PETSC_COMM_WORLD, NULL, NULL, "-myviewer", &viewer, &format, &flg)); 23 PetscCheck(!flg, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Pushed viewer off, but viewer was set"); 24 if (viewer) { 25 PetscCall(PetscViewerPushFormat(viewer, format)); 26 PetscCall(PetscViewerASCIIPrintf(viewer, "Testing PetscViewerASCIIPrintf %d\n", 1)); 27 PetscCall(PetscViewerPopFormat(viewer)); 28 } 29 PetscCall(PetscOptionsPopCreateViewerOff()); 30 PetscCall(PetscOptionsCreateViewer(PETSC_COMM_WORLD, NULL, NULL, "-myviewer", &viewer, &format, &flg)); 31 PetscCall(PetscViewerPushFormat(viewer, format)); 32 PetscCall(PetscViewerASCIIPrintf(viewer, "Testing PetscViewerASCIIPrintf %d\n", 2)); 33 PetscCall(PetscViewerPopFormat(viewer)); 34 } 35 PetscCall(PetscViewerDestroy(&viewer)); 36 PetscCall(PetscFinalize()); 37 return 0; 38 } 39 40 /*TEST 41 42 test: 43 args: -myviewer 44 45 TEST*/ 46