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 PetscCall(PetscInitialize(&argc,&args,(char*)0,help)); 13 PetscCall(PetscOptionsGetViewer(PETSC_COMM_WORLD,NULL,NULL,"-myviewer",&viewer,&format,NULL)); 14 PetscCall(PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii)); 15 if (iascii) { 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(PetscOptionsPushGetViewerOff(PETSC_TRUE)); 22 PetscCall(PetscOptionsGetViewer(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(PetscOptionsPopGetViewerOff()); 30 PetscCall(PetscOptionsGetViewer(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