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