1c4762a1bSJed Brown static char help[] = "Tests PetscOptionsPushGetViewerOff() via checking output of PetscViewerASCIIPrintf().\n\n"; 2c4762a1bSJed Brown 3c4762a1bSJed Brown #include <petscviewer.h> 4c4762a1bSJed Brown 5d71ae5a4SJacob Faibussowitsch int main(int argc, char **args) 6d71ae5a4SJacob Faibussowitsch { 7c4762a1bSJed Brown PetscViewer viewer; 8c4762a1bSJed Brown PetscViewerFormat format; 9*9f196a02SMartin Diehl PetscBool isascii; 10c4762a1bSJed Brown 11327415f7SBarry Smith PetscFunctionBeginUser; 12c8025a54SPierre Jolivet PetscCall(PetscInitialize(&argc, &args, NULL, help)); 13648c30bcSBarry Smith PetscCall(PetscOptionsCreateViewer(PETSC_COMM_WORLD, NULL, NULL, "-myviewer", &viewer, &format, NULL)); 14*9f196a02SMartin Diehl PetscCall(PetscObjectTypeCompare((PetscObject)viewer, PETSCVIEWERASCII, &isascii)); 15*9f196a02SMartin Diehl if (isascii) { 16c4762a1bSJed Brown PetscBool flg; 179566063dSJacob Faibussowitsch PetscCall(PetscViewerPushFormat(viewer, format)); 189566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "Testing PetscViewerASCIIPrintf %d\n", 0)); 199566063dSJacob Faibussowitsch PetscCall(PetscViewerPopFormat(viewer)); 20648c30bcSBarry Smith PetscCall(PetscViewerDestroy(&viewer)); 21648c30bcSBarry Smith PetscCall(PetscOptionsPushCreateViewerOff(PETSC_TRUE)); 22648c30bcSBarry Smith PetscCall(PetscOptionsCreateViewer(PETSC_COMM_WORLD, NULL, NULL, "-myviewer", &viewer, &format, &flg)); 2328b400f6SJacob Faibussowitsch PetscCheck(!flg, PETSC_COMM_SELF, PETSC_ERR_ARG_WRONGSTATE, "Pushed viewer off, but viewer was set"); 24c4762a1bSJed Brown if (viewer) { 259566063dSJacob Faibussowitsch PetscCall(PetscViewerPushFormat(viewer, format)); 269566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "Testing PetscViewerASCIIPrintf %d\n", 1)); 279566063dSJacob Faibussowitsch PetscCall(PetscViewerPopFormat(viewer)); 28c4762a1bSJed Brown } 29648c30bcSBarry Smith PetscCall(PetscOptionsPopCreateViewerOff()); 30648c30bcSBarry Smith PetscCall(PetscOptionsCreateViewer(PETSC_COMM_WORLD, NULL, NULL, "-myviewer", &viewer, &format, &flg)); 319566063dSJacob Faibussowitsch PetscCall(PetscViewerPushFormat(viewer, format)); 329566063dSJacob Faibussowitsch PetscCall(PetscViewerASCIIPrintf(viewer, "Testing PetscViewerASCIIPrintf %d\n", 2)); 339566063dSJacob Faibussowitsch PetscCall(PetscViewerPopFormat(viewer)); 34c4762a1bSJed Brown } 35648c30bcSBarry Smith PetscCall(PetscViewerDestroy(&viewer)); 369566063dSJacob Faibussowitsch PetscCall(PetscFinalize()); 37b122ec5aSJacob Faibussowitsch return 0; 38c4762a1bSJed Brown } 39c4762a1bSJed Brown 40c4762a1bSJed Brown /*TEST 41c4762a1bSJed Brown 42c4762a1bSJed Brown test: 43c4762a1bSJed Brown args: -myviewer 44c4762a1bSJed Brown 45c4762a1bSJed Brown TEST*/ 46