// $Revision: 1.4 $ // Copyright (C) 1995 Taligent, Inc. All rights reserved. // // This test case is only trying to test all the API's which are not // covered by the two GUIDriver test. The 2 GUIDriver test cases are // Total.Event & GrafEditBAT.Event. // #define protected public // for testing only #define private public #include "MarsTestPresenter.h" #include "TestClasses.h" #ifndef Taligent_CANVASCURVE #include #endif #include #include #include #include #include MCanvasGraphic* GetCanvasGraphic() { static int i = 0; TGPointArray points(3); points.SetPoint(0, TGPoint(10+i, 10+i)); points.SetPoint(1, TGPoint(100+i, 10+i)); points.SetPoint(2, TGPoint(10+i, 100+i)); TGCurve c( 3, TGRPointArray(points) ); TCanvasCurve *theCurve = new TCanvasCurve (c); i+=5; return theCurve; } void PrintDebug(char* theText) { #ifndef _DEBUG_STRING qprintf("%s\n",theText); #endif } #define DEBUGSTRING(x) PrintDebug(x); TTestGrafEditClass::TTestGrafEditClass(TGUIPresenter *aPresenter, TGUIBundle *theBundle, TStandardCanvasView* aView) : fPresenter(aPresenter), fGUIBundle(theBundle), fView(aView) { // DEBUGSTRING("TTestGrafEditClass::TTestGrafEditClass"); } int TTestGrafEditClass::Test() { int i = 0; // DEBUGSTRING("TTestGrafEditClass::Test"); i += HandleTestGrafEditStates(); i += HandleTestSelectionNotification(); i += HandleTestCommands(); i += HandleTestSelection(); i += HandleTestModel(); i += HandleTestStandardCanvasView(); i += HandleTestCanvasGraphicDeque(); i += HandleTestInteractor(); i += HandleTestCanvasPolyLine(); i += HandleTestCanvasPolygon(); i += HandleTestCanvasCurve(); i += HandleTestCanvasLine(); i += HandleTestBasicCanvasGraphic(); i += HandleTestCanvasTextGraphic(); i += HandleTestSRTFeedbacker(); return i; } int TTestGrafEditClass::HandleTestGrafEditStates() { int pass = 1; try { { TStandardCanvasFillColorSelectionState aState; TStreamCopyAssignmentTest aStreamTest(&aState,TStandardText("TStandardCanvasFillColorSelectionState")); } { TStandardCanvasFrameColorSelectionState aState; TStreamCopyAssignmentTest aStreamTest(&aState,TStandardText("TStandardCanvasFrameColorSelectionState")); } { TStandardCanvasLineWidthSelectionState aState; TStreamCopyAssignmentTest aStreamTest(&aState,TStandardText("TStandardCanvasLineWidthSelectionState")); } } catch ( ... ) { DEBUGSTRING("TTestGrafEditClass::HandleTestGrafEditStates"); pass = 0; } return pass; } int TTestGrafEditClass::HandleTestSelectionNotification() { int pass = 1; TStandardCanvasModelSelection* theSelection = NIL; try { theSelection = GetModelSelection(); TModelInterest interest = GetModelInterest(); TGRect aRect(10,10,100,100); TStandardCanvasSelectionNotification aNotification; const TStandardCanvasSelectionNotification notification (interest, *theSelection, aRect); TStandardCanvasSelectionNotification clone(notification); TStreamCopyAssignmentTest aStreamTest(&clone, TStandardText("TStandardCanvasSelectionNotification")); notification.Hash(); TGArea area; notification.GetArea(area); aNotification.GetSelection(); } catch ( ... ) { DEBUGSTRING("TTestGrafEditClass::HandleTestSelectionNotification"); pass = 0; } delete theSelection; return pass; } int TTestGrafEditClass::HandleTestCommands() { int pass = 1; try { for (int i = 0; i< 5; i++) AddGraphics(); try { TGPointArray points(3); points.SetPoint(0, TGPoint(10,10)); points.SetPoint(1, TGPoint(100,10)); points.SetPoint(2, TGPoint(10,100)); TGCurve c( 3, TGRPointArray(points) ); TCanvasCurve *theCurve = new TCanvasCurve (c); TAdoptCanvasGraphicCmd aCommand(theCurve); TStreamCopyAssignmentTest aStreamTest( &aCommand , TStandardText("TAdoptCanvasGraphicCmd") ); } catch ( ... ) { DEBUGSTRING("TAdoptCanvasGraphicCmd: failed\n"); } try { AddGraphics(); TDeleteCanvasGraphicsCmd aCommand; TStreamCopyAssignmentTest aStreamTest(&aCommand , TStandardText("TDeleteCanvasGraphicsCmd") ); TestCommands(aCommand); TestUndoRedoCommand(true); TestUndoRedoCommand(false); } catch ( ... ) { DEBUGSTRING("TDeleteCanvasGraphicsCmd: failed\n"); } try { AddGraphics(); TChangeCanvasGraphicCmd aCommand; TStreamCopyAssignmentTest aStreamTest(&aCommand , TStandardText("TChangeCanvasGraphicCmd") ); } catch ( ... ) { DEBUGSTRING("TChangeCanvasGraphicCmd: failed\n"); } try { AddGraphics(); TSetCanvasGraphicFillColorCmd aCommand; TColorPaint red(TColorPaint::GetRed()); aCommand.SetColor( *red.GetColor() ); TStreamCopyAssignmentTest aStreamTest(&aCommand , TStandardText("TSetCanvasGraphicFillColorCmd") ); TestCommands(aCommand); TestUndoRedoCommand(true); TestUndoRedoCommand(false); } catch ( ... ) { DEBUGSTRING("TSetCanvasGraphicFillColorCmd: failed\n"); } try { AddGraphics(); TSetCanvasGraphicFillColorCmd aCommand; TColorPaint red(TColorPaint::GetRed()); aCommand.SetColor( *red.GetColor() ); TestIncrementCommands(aCommand); } catch ( ... ) { DEBUGSTRING("TSetCanvasGraphicFillColorCmd: TestIncrementCommands failed\n"); } try { AddGraphics(); TSetCanvasGraphicFrameColorCmd aCommand; TColorPaint red(TColorPaint::GetRed()); aCommand.SetColor( *red.GetColor() ); TStreamCopyAssignmentTest aStreamTest(&aCommand , TStandardText("TSetCanvasGraphicFrameColorCmd") ); TestCommands(aCommand); TestUndoRedoCommand(true); TestUndoRedoCommand(false); } catch ( ... ) { DEBUGSTRING("TSetCanvasGraphicFrameColorCmd: failed\n"); } try { AddGraphics(); TSetCanvasGraphicFrameColorCmd aCommand; TColorPaint red(TColorPaint::GetRed()); aCommand.SetColor( *red.GetColor() ); TestIncrementCommands(aCommand); } catch ( ... ) { DEBUGSTRING("TSetCanvasGraphicFrameColorCmd: TestIncrementCommands failed\n"); } try { AddGraphics(); TSetCanvasGraphicLineWidthCmd aCommand; aCommand.SetWidth(5.0); TStreamCopyAssignmentTest aStreamTest(&aCommand , TStandardText("TSetCanvasGraphicLineWidthCmd") ); TestCommands(aCommand); TestUndoRedoCommand(true); TestUndoRedoCommand(false); } catch ( ... ) { DEBUGSTRING("TSetCanvasGraphicLineWidthCmd: failed\n"); } try { AddGraphics(); TSetCanvasGraphicLineWidthCmd aCommand; aCommand.SetWidth(5.0); TestIncrementCommands(aCommand); } catch ( ... ) { DEBUGSTRING("TSetCanvasGraphicLineWidthCmd: TestIncrementCommands failed\n"); } try { AddGraphics(); TScaleCanvasGraphicCmd aCommand; TGPoint p1(2,2); TGPoint p2(2,2); TScaleCanvasGraphicCmd aCommand2( p1, p2 ); aCommand.SetScaleFactor(TGPoint(2,2)); TStreamCopyAssignmentTest aStreamTest(&aCommand , TStandardText("TScaleCanvasGraphicCmd") ); TestCommands(aCommand); TestUndoRedoCommand(true); TestUndoRedoCommand(false); } catch ( ... ) { DEBUGSTRING("TScaleCanvasGraphicCmd: failed\n"); } try { AddGraphics(); TRotateCanvasGraphicCmd aCommand; aCommand.SetAngle(0.45); TStreamCopyAssignmentTest aStreamTest(&aCommand , TStandardText("TRotateCanvasGraphicCmd") ); TestCommands(aCommand); TestUndoRedoCommand(true); TestUndoRedoCommand(false); } catch ( ... ) { DEBUGSTRING("TRotateCanvasGraphicCmd: failed\n"); } try { AddGraphics(); TTranslateCanvasGraphicCmd aCommand; TGPoint p1(2,2); TTranslateCanvasGraphicCmd aCommand2(p1); aCommand.SetOffset(TGPoint(10,10)); TStreamCopyAssignmentTest aStreamTest(&aCommand , TStandardText("TTranslateCanvasGraphicCmd") ); TestCommands(aCommand); TestUndoRedoCommand(true); TestUndoRedoCommand(false); } catch ( ... ) { DEBUGSTRING("TTranslateCanvasGraphicCmd: failed\n"); } try { AddGraphics(); TTransformCanvasGraphicCmd aCommand; TGrafMatrix aMatrix(TGPoint(12,12), TGPoint(200,200)); TTransformCanvasGraphicCmd aCommand2(aMatrix); aCommand.SetTransform(aMatrix); TStreamCopyAssignmentTest aStreamTest(&aCommand , TStandardText("TTransformCanvasGraphicCmd") ); TestCommands(aCommand); TestUndoRedoCommand(true); TestUndoRedoCommand(false); } catch ( ... ) { DEBUGSTRING("TTransformCanvasGraphicCmd: failed\n"); } try { AddGraphics(); TTransformCanvasGraphicCmd aCommand; TGrafMatrix aMatrix(TGPoint(12,12), TGPoint(200,200)); aCommand.SetTransform(aMatrix); TestIncrementCommands(aCommand); } catch ( ... ) { DEBUGSTRING("TTransformCanvasGraphicCmd: TestIncrementCommands: failed\n"); } } catch ( ... ) { DEBUGSTRING("TTestGrafEditClass::HandleTestCommands"); pass = 0; } return pass; } TTypeDescription kGrafEditModel (static_type_info(TStandardCanvasModel)) ; int TTestGrafEditClass::HandleTestSelection() { int pass = 1; try { TStandardCanvasModelSelection theSelection(*GetModelSelection()); TStandardCanvasModelSelection assignSelection; assignSelection.operator=(theSelection); { const TStandardCanvasModelSelection constSelection(theSelection); constSelection.MCanvasSelection::Hash(); } MCanvasGraphic *theGraphic = GetCanvasGraphic(); TCanvasGraphicID id = theGraphic->GetID(); assignSelection.DeselectGraphic(*theGraphic); assignSelection.DeselectGraphic(id); TDequeOf theChoices; theChoices.Add( &kGrafEditModel) ; TDequeOf theChosenTypes; theSelection.ChooseTypes(theChoices, theChosenTypes); theSelection.HandleCopyData(kGrafEditModel); delete theGraphic; } catch ( ... ) { DEBUGSTRING("TTestGrafEditClass::HandleTestSelection"); pass = 0; } return pass; } int TTestGrafEditClass::HandleTestModel() { int pass = 1; try { TStandardCanvasModel *theModel = GetModel(); TStandardCanvasModel assignModel; assignModel.operator=(*theModel); theModel->GetGraphicsAddedInterest(); theModel->GetGraphicsRemovedInterest(); theModel->GetEmbeddedGraphicAddedInterest(); MCanvasGraphic *theGraphic = GetCanvasGraphic(); TCanvasGraphicID id = theGraphic->GetID(); theModel->AdoptBefore(id,theGraphic); theModel->MoveToFront(id); theModel->MoveToBack(id); theModel->MoveForward(id); theModel->MoveBackward(id); theModel->Member(id); theModel->Lookup(id); theModel->Delete(id); theModel->DeleteAll(); { const TStandardCanvasModel aModel(*theModel); aModel.Lookup(id); } // theModel->HandleDrasticChange( aNotification); delete theModel; } catch ( ... ) { DEBUGSTRING("TTestGrafEditClass::HandleTestModel"); pass = 0; } return pass; } int TTestGrafEditClass::HandleTestStandardCanvasView() { int pass = 1; try { TStandardCanvasView aView(); TStandardCanvasView aCopyView(*fView); TStandardCanvasView *apView = &aCopyView; apView->Hash(); apView->SetCurrentSelection(*GetModelSelection()); TStreamCopyAssignmentTest aStreamTest(fView , TStandardText("TStandardCanvasView") ); TColorPaint red(TColorPaint::GetRed()); // apView->SetForegroundColor(*red.GetColor()); apView->SupportsFeedback(); apView->SetBackgroundColor(*red.GetColor()); TInterest anInterest( TDocument::GetNotifier(), TToken("Test")); TNotification aNotify(anInterest); fView->HandleDrasticChange( aNotify ); { const TStandardCanvasView* constView = fView; constView->Hash(); } } catch ( ... ) { DEBUGSTRING("TTestGrafEditClass::HandleTestStandardCanvasView"); pass = 0; } return pass; } int TTestGrafEditClass::HandleTestCanvasGraphicDeque() { int pass = 1; try { TDequeOf theDeque; theDeque.Add(GetCanvasGraphic()); theDeque.Add(GetCanvasGraphic()); TCanvasGraphicDequeWriteIterator anIterator(theDeque); anIterator.Last(); anIterator.Previous(); } catch ( ... ) { DEBUGSTRING("TTestGrafEditClass::HandleTestCanvasGraphicDeque"); pass = 0; } return pass; } int TTestGrafEditClass::HandleTestInteractor() { int pass = 1; try { } catch ( ... ) { DEBUGSTRING("TTestGrafEditClass::HandleTestInteractor"); pass = 0; } return pass; } int TTestGrafEditClass::HandleTestCanvasPolyLine() { int pass = 1; try { TCanvasPolyline aPolyLine(); TCanvasPolyline aCopyPolyLine; // aCopyPolyLine = aPolyLine; TStreamCopyAssignmentTest aStreamTest(&aCopyPolyLine, TStandardText("TCanvasPolyline") ); TCanvasPolylineCreationTool aTool; TStreamCopyAssignmentTest aStreamTest2(&aTool, TStandardText("TCanvasPolylineCreationTool") ); aTool.CreatePaletteGraphic(); TStandardText theText; aTool.GetPaletteText(theText); } catch ( ... ) { DEBUGSTRING("TTestGrafEditClass::HandleTestPolyLine"); pass = 0; } return pass; } int TTestGrafEditClass::HandleTestCanvasPolygon() { int pass = 1; try { TCanvasPolygon aCanvasGraphic; TCanvasPolygon aCopyGraphic; TGPoint p1(10,10); GCoordinate gc = 1; TCanvasPolygon* aPointer = &aCanvasGraphic; aPointer->HandleHit(p1); aPointer->GetParametric(p1,gc); aPointer->DragPolygonTo(gc,p1); // aCopyGraphic = aCanvasGraphic; TStreamCopyAssignmentTest aStreamTest(&aCopyGraphic, TStandardText("TCanvasPolygon") ); TCanvasPolygonCreationTool aTool; TStreamCopyAssignmentTest aStreamTest2(&aTool, TStandardText("TCanvasPolygonCreationTool") ); aTool.CreatePaletteGraphic(); TStandardText theText; aTool.GetPaletteText(theText); } catch ( ... ) { DEBUGSTRING("TTestGrafEditClass::HandleTestCanvasPolygon"); pass = 0; } return pass; } int TTestGrafEditClass::HandleTestCanvasCurve() { int pass = 1; try { TCanvasCurve aCanvasGraphic; TCanvasCurve aCopyGraphic; aCopyGraphic.operator=(aCanvasGraphic); TStreamCopyAssignmentTest aStreamTest(&aCopyGraphic, TStandardText("TCanvasCurve") ); TCanvasCurveCreationTool aTool; TStreamCopyAssignmentTest aStreamTest2(&aTool, TStandardText("TCanvasCurveCreationTool") ); aTool.CreatePaletteGraphic(); TStandardText theText; aTool.GetPaletteText(theText); } catch ( ... ) { DEBUGSTRING("TTestGrafEditClass::HandleTestCanvasCurve"); pass = 0; } return pass; } int TTestGrafEditClass::HandleTestCanvasLine() { int pass = 1; try { TCanvasLine aCanvasGraphic; TCanvasLine aCopyGraphic; aCopyGraphic = aCanvasGraphic; TStreamCopyAssignmentTest aStreamTest(&aCopyGraphic, TStandardText("TCanvasLine") ); TCanvasLineCreationTool aTool; TStreamCopyAssignmentTest aStreamTest2(&aTool, TStandardText("TCanvasLineCreationTool") ); aTool.CreatePaletteGraphic(); TStandardText theText; aTool.GetPaletteText(theText); } catch ( ... ) { pass = 0; DEBUGSTRING("TTestGrafEditClass::HandleTestCanvasLine"); } return pass; } int TTestGrafEditClass::HandleTestBasicCanvasGraphic() { int pass = 1; try { MCanvasGraphic* theGraphic = GetCanvasGraphic(); TBasicCanvasGraphic aBasic( ::Copy(*theGraphic) ) ; TBasicCanvasGraphic aBasic2( ::Copy(*theGraphic) ) ; aBasic2.operator=(aBasic2); TBasicCanvasGraphicCreationTool aTool(*theGraphic ); TBasicCanvasGraphicCreationTool aTool2; aTool2.operator=(aTool); delete theGraphic; } catch ( ... ) { pass = 0; DEBUGSTRING("TTestGrafEditClass::HandleTestBasicCanvasGraphic"); } return pass; } int TTestGrafEditClass::HandleTestCanvasTextGraphic() { int pass = 1; try { TCanvasTextGraphic aTextGraphic; TStreamCopyAssignmentTest aStreamTest( &aTextGraphic, TStandardText("TCanvasTextGraphic") ); TCanvasTextGraphicCreationTool aTool; TStreamCopyAssignmentTest aStreamTest2( &aTool, TStandardText("TCanvasTextGraphicCreationTool") ); aTool.CreatePaletteGraphic(); TStandardText theText; aTool.GetPaletteText(theText); } catch ( ... ) { pass = 0; DEBUGSTRING("TTestGrafEditClass::HandleTestCanvasTextGraphic"); } return pass; } int TTestGrafEditClass::HandleTestSRTFeedbacker() { int pass = 1; try { { // TSRTBoxFeedbacker MCanvasGraphic *theCurve = GetCanvasGraphic(); theCurve->HandleCreateFeedbacker(); theCurve->CreateFeedbacker(); { const MCanvasGraphic* constGraph = theCurve; constGraph->Hash(); constGraph->CreateFeedbacker(); } TSRTBoxFeedbacker aBoxFeed( *theCurve ); TStreamCopyAssignmentTest aStreamTest( &aBoxFeed, TStandardText("TSRTBoxFeedbacker") ); delete theCurve; } { MCanvasGraphic *theCurve = GetCanvasGraphic(); TSRTHandleFeedbacker aHandleFeed( *theCurve ); TSRTHandleFeedbacker aHandleFeed2; aHandleFeed2.SetGraphic(theCurve); TStreamCopyAssignmentTest aStreamTest( &aHandleFeed, TStandardText("TSRTHandleFeedbacker") ); delete theCurve; } } catch ( ... ) { DEBUGSTRING("TTestGrafEditClass::HandleTestSRTFeedbacker"); pass = 0; } return pass; } TStandardCanvasModelSelection* TTestGrafEditClass::GetModelSelection() { TStandardCanvasModelSelection* theSelection = NIL; TStandardCanvasModel* realModel = NIL; TDocumentComponentWriteEntry theSourceDoc( fGUIBundle->GetModelReference() ); TModel *theModel = TModel::LookupForWriting( fGUIBundle->GetModelReference() ); DynamicCastTo(realModel, theModel); if (realModel) { theSelection = new TStandardCanvasModelSelection(*realModel); } return theSelection; } const TStandardCanvasModel* TTestGrafEditClass::GetModel() const { const TStandardCanvasModel* realModel = NIL; TDocumentComponentReadEntry theSourceDoc( fGUIBundle->GetModelReference() ); const TModel *theModel = TModel::LookupForReading( fGUIBundle->GetModelReference() ); DynamicCastTo(realModel, theModel); return realModel; } TStandardCanvasModel* TTestGrafEditClass::GetModel() { TStandardCanvasModel* realModel = NIL; TDocumentComponentWriteEntry theSourceDoc( fGUIBundle->GetModelReference() ); TModel *theModel = TModel::LookupForWriting( fGUIBundle->GetModelReference() ); DynamicCastTo(realModel, theModel); if (!realModel) realModel = new TStandardCanvasModel(); return new TStandardCanvasModel(*realModel); } TModelInterest TTestGrafEditClass::GetModelInterest() { TStandardCanvasModel* realModel = GetModel(); TModelInterest interest = realModel->GetGraphicsChangedInterest (); return interest; } void TTestGrafEditClass::TestCommands(TCommandOn& aCommand) { TStandardCanvasModelSelection* theSelection = GetModelSelection(); theSelection->SelectAllGraphics(); TToolCommandBindingTo* binding = new TToolCommandBindingTo (::Copy(aCommand), theSelection); fView->AdoptAndDo(binding); } void TTestGrafEditClass::TestIncrementCommands(TCommandOn& aCommand) { { aCommand.SetState(TCommonCommand::kNew); TStandardCanvasModelSelection *theSelection = GetModelSelection(); theSelection->SelectAllGraphics(); // qprintf("NumberOfSelectedGraphics: %d\n",theSelection->NumberOfSelectedGraphics()); TToolCommandBindingTo* binding = new TToolCommandBindingTo (::Copy(aCommand), theSelection); fView->DoBegin(*binding); } { aCommand.SetState(TCommonCommand::kBegun); TStandardCanvasModelSelection *theSelection = GetModelSelection(); theSelection->SelectAllGraphics(); TToolCommandBindingTo* binding2 = new TToolCommandBindingTo (::Copy(aCommand), theSelection ); fView->DoIncrement(*binding2); } { aCommand.SetState(TCommonCommand::kBegun); TStandardCanvasModelSelection *theSelection = GetModelSelection(); theSelection->SelectAllGraphics(); TToolCommandBindingTo* binding3 = new TToolCommandBindingTo (::Copy(aCommand), theSelection ); fView->AdoptAndDoEnd(binding3); } } void TTestGrafEditClass::TestUndoRedoCommand(bool doUndo) { TCompoundDocumentSurrogate theDocument( fPresenter->GetModelReference() ); bool undo, redo; theDocument.GetUndoRedoStatus( undo, redo ); if ( doUndo && undo ) { theDocument.HistoryUndo(); } else if (redo) { theDocument.HistoryRedo(); } } void TTestGrafEditClass::AddGraphics() { static int i = 0; TGPointArray points(3); points.SetPoint(0, TGPoint(10+i, 10+i)); points.SetPoint(1, TGPoint(100+i, 10+i)); points.SetPoint(2, TGPoint(10+i, 100+i)); TGCurve c( 3, TGRPointArray(points) ); TCanvasCurve *theCurve = new TCanvasCurve (c); TAdoptCanvasGraphicCmd aCommand(theCurve); TestCommands(aCommand); i+=10; }