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 CHKERRQ(PetscInitialize(&argc,&args,(char*)0,help)); 13 CHKERRQ(PetscOptionsGetViewer(PETSC_COMM_WORLD,NULL,NULL,"-myviewer",&viewer,&format,NULL)); 14 CHKERRQ(PetscObjectTypeCompare((PetscObject)viewer,PETSCVIEWERASCII,&iascii)); 15 if (iascii) { 16 PetscBool flg; 17 CHKERRQ(PetscViewerPushFormat(viewer,format)); 18 CHKERRQ(PetscViewerASCIIPrintf(viewer,"Testing PetscViewerASCIIPrintf %d\n", 0)); 19 CHKERRQ(PetscViewerPopFormat(viewer)); 20 CHKERRQ(PetscViewerDestroy(&viewer)); 21 CHKERRQ(PetscOptionsPushGetViewerOff(PETSC_TRUE)); 22 CHKERRQ(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 CHKERRQ(PetscViewerPushFormat(viewer,format)); 26 CHKERRQ(PetscViewerASCIIPrintf(viewer,"Testing PetscViewerASCIIPrintf %d\n", 1)); 27 CHKERRQ(PetscViewerPopFormat(viewer)); 28 } 29 CHKERRQ(PetscOptionsPopGetViewerOff()); 30 CHKERRQ(PetscOptionsGetViewer(PETSC_COMM_WORLD,NULL,NULL,"-myviewer",&viewer,&format,&flg)); 31 CHKERRQ(PetscViewerPushFormat(viewer,format)); 32 CHKERRQ(PetscViewerASCIIPrintf(viewer,"Testing PetscViewerASCIIPrintf %d\n", 2)); 33 CHKERRQ(PetscViewerPopFormat(viewer)); 34 } 35 CHKERRQ(PetscViewerDestroy(&viewer)); 36 CHKERRQ(PetscFinalize()); 37 return 0; 38 } 39 40 /*TEST 41 42 test: 43 args: -myviewer 44 45 TEST*/ 46