update dev300-m58
[ooovba.git] / embeddedobj / qa / embedding / Test01.java
blobe962316d316ae02fa3a349d8a63992a2df3f558d
1 package complex.embedding;
3 import com.sun.star.uno.XInterface;
4 import com.sun.star.lang.XMultiServiceFactory;
5 import com.sun.star.lang.XSingleServiceFactory;
7 import com.sun.star.bridge.XUnoUrlResolver;
8 import com.sun.star.uno.UnoRuntime;
9 import com.sun.star.uno.XInterface;
10 import com.sun.star.beans.XPropertySet;
11 import com.sun.star.frame.XLoadable;
12 import com.sun.star.drawing.XDrawPagesSupplier;
13 import com.sun.star.drawing.XDrawPages;
14 import com.sun.star.drawing.XDrawPage;
15 import com.sun.star.drawing.XShape;
16 import com.sun.star.graphic.XGraphic;
18 import com.sun.star.embed.*;
20 import share.LogWriter;
21 import complex.embedding.TestHelper;
22 import complex.embedding.EmbeddingTest;
24 public class Test01 implements EmbeddingTest {
26 XMultiServiceFactory m_xMSF;
27 TestHelper m_aTestHelper;
29 public Test01( XMultiServiceFactory xMSF, LogWriter aLogWriter )
31 m_xMSF = xMSF;
32 m_aTestHelper = new TestHelper( aLogWriter, "Test01: " );
35 public boolean test()
37 try
39 Object oDoc = m_xMSF.createInstance( "com.sun.star.comp.Draw.DrawingDocument" );
40 XLoadable xLoad = (XLoadable) UnoRuntime.queryInterface( XLoadable.class, oDoc );
41 if ( xLoad == null )
43 m_aTestHelper.Error( "Can not get XLoadable!" );
44 return false;
47 xLoad.initNew();
49 XDrawPagesSupplier xDPSupply = (XDrawPagesSupplier) UnoRuntime.queryInterface( XDrawPagesSupplier.class, oDoc );
50 if ( xDPSupply == null )
52 m_aTestHelper.Error( "Can not get XDrawPagesSupplier!" );
53 return false;
56 XDrawPages xDrawPages = xDPSupply.getDrawPages();
57 if ( xDrawPages == null )
59 m_aTestHelper.Error( "Can not get XDrawPages object!" );
60 return false;
63 if ( xDrawPages.getCount() == 0 )
65 m_aTestHelper.Error( "There must be at least one page in the document!" );
66 return false;
69 Object oPage = xDrawPages.getByIndex( 0 );
70 XDrawPage xPage = (XDrawPage) UnoRuntime.queryInterface( XDrawPage.class, oPage );
71 if ( xPage == null )
73 m_aTestHelper.Error( "Can not get access to drawing page!" );
74 return false;
77 XMultiServiceFactory xDrFactory = ( XMultiServiceFactory ) UnoRuntime.queryInterface( XMultiServiceFactory.class,
78 oDoc );
79 if ( xDrFactory == null )
81 m_aTestHelper.Error( "Can not get drawing factory!" );
82 return false;
85 Object oShape = xDrFactory.createInstance( "com.sun.star.drawing.OLE2Shape" );
86 XShape xShape = ( XShape ) UnoRuntime.queryInterface( XShape.class, oShape );
87 if ( xShape == null )
89 m_aTestHelper.Error( "Can not create new shape!" );
90 return false;
93 XPropertySet xShapeProps = ( XPropertySet ) UnoRuntime.queryInterface( XPropertySet.class, oShape );
94 if ( xShapeProps == null )
96 m_aTestHelper.Error( "Can not get access to shapes properties!" );
97 return false;
100 xPage.add( xShape );
101 xShapeProps.setPropertyValue( "CLSID", "078B7ABA-54FC-457F-8551-6147e776a997" );
103 Object oEmbObj = xShapeProps.getPropertyValue( "EmbeddedObject" );
104 XEmbeddedObject xEmbObj = ( XEmbeddedObject ) UnoRuntime.queryInterface( XEmbeddedObject.class, oEmbObj );
105 if ( xEmbObj == null )
107 m_aTestHelper.Error( "Embedded object can not be accessed!" );
108 return false;
111 XEmbeddedClient xClient = xEmbObj.getClientSite();
112 if ( xClient == null )
114 m_aTestHelper.Error( "The client for the object must be set!" );
115 return false;
118 Object oReplacement = xShapeProps.getPropertyValue( "Graphic" );
119 XGraphic xReplGraph = ( XGraphic ) UnoRuntime.queryInterface( XGraphic.class, oReplacement );
120 if ( xReplGraph == null )
122 m_aTestHelper.Error( "The replacement graphic should be available!" );
123 return false;
126 return true;
128 catch( Exception e )
130 m_aTestHelper.Error( "Exception: " + e );
131 return false;