xref: /AOO41X/main/embeddedobj/qa/embedding/Test01.java (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir package complex.embedding;
2*cdf0e10cSrcweir 
3*cdf0e10cSrcweir import com.sun.star.uno.XInterface;
4*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
5*cdf0e10cSrcweir import com.sun.star.lang.XSingleServiceFactory;
6*cdf0e10cSrcweir 
7*cdf0e10cSrcweir import com.sun.star.bridge.XUnoUrlResolver;
8*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime;
9*cdf0e10cSrcweir import com.sun.star.uno.XInterface;
10*cdf0e10cSrcweir import com.sun.star.beans.XPropertySet;
11*cdf0e10cSrcweir import com.sun.star.frame.XLoadable;
12*cdf0e10cSrcweir import com.sun.star.drawing.XDrawPagesSupplier;
13*cdf0e10cSrcweir import com.sun.star.drawing.XDrawPages;
14*cdf0e10cSrcweir import com.sun.star.drawing.XDrawPage;
15*cdf0e10cSrcweir import com.sun.star.drawing.XShape;
16*cdf0e10cSrcweir import com.sun.star.graphic.XGraphic;
17*cdf0e10cSrcweir 
18*cdf0e10cSrcweir import com.sun.star.embed.*;
19*cdf0e10cSrcweir 
20*cdf0e10cSrcweir import share.LogWriter;
21*cdf0e10cSrcweir import complex.embedding.TestHelper;
22*cdf0e10cSrcweir import complex.embedding.EmbeddingTest;
23*cdf0e10cSrcweir 
24*cdf0e10cSrcweir public class Test01 implements EmbeddingTest {
25*cdf0e10cSrcweir 
26*cdf0e10cSrcweir 	XMultiServiceFactory m_xMSF;
27*cdf0e10cSrcweir 	TestHelper m_aTestHelper;
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir 	public Test01( XMultiServiceFactory xMSF, LogWriter aLogWriter )
30*cdf0e10cSrcweir 	{
31*cdf0e10cSrcweir 		m_xMSF = xMSF;
32*cdf0e10cSrcweir 		m_aTestHelper = new TestHelper( aLogWriter, "Test01: " );
33*cdf0e10cSrcweir 	}
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir     public boolean test()
36*cdf0e10cSrcweir 	{
37*cdf0e10cSrcweir 		try
38*cdf0e10cSrcweir 		{
39*cdf0e10cSrcweir 			Object oDoc = m_xMSF.createInstance( "com.sun.star.comp.Draw.DrawingDocument" );
40*cdf0e10cSrcweir 			XLoadable xLoad = (XLoadable) UnoRuntime.queryInterface( XLoadable.class, oDoc );
41*cdf0e10cSrcweir 			if ( xLoad == null )
42*cdf0e10cSrcweir 			{
43*cdf0e10cSrcweir 				m_aTestHelper.Error( "Can not get XLoadable!" );
44*cdf0e10cSrcweir 				return false;
45*cdf0e10cSrcweir 			}
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir 			xLoad.initNew();
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir 			XDrawPagesSupplier xDPSupply = (XDrawPagesSupplier) UnoRuntime.queryInterface( XDrawPagesSupplier.class, oDoc );
50*cdf0e10cSrcweir 			if ( xDPSupply == null )
51*cdf0e10cSrcweir 			{
52*cdf0e10cSrcweir 				m_aTestHelper.Error( "Can not get XDrawPagesSupplier!" );
53*cdf0e10cSrcweir 				return false;
54*cdf0e10cSrcweir 			}
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir 			XDrawPages xDrawPages = xDPSupply.getDrawPages();
57*cdf0e10cSrcweir 			if ( xDrawPages == null )
58*cdf0e10cSrcweir 			{
59*cdf0e10cSrcweir 				m_aTestHelper.Error( "Can not get XDrawPages object!" );
60*cdf0e10cSrcweir 				return false;
61*cdf0e10cSrcweir 			}
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir 			if ( xDrawPages.getCount() == 0 )
64*cdf0e10cSrcweir 			{
65*cdf0e10cSrcweir 				m_aTestHelper.Error( "There must be at least one page in the document!" );
66*cdf0e10cSrcweir 				return false;
67*cdf0e10cSrcweir 			}
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir 			Object oPage = xDrawPages.getByIndex( 0 );
70*cdf0e10cSrcweir 			XDrawPage xPage = (XDrawPage) UnoRuntime.queryInterface( XDrawPage.class, oPage );
71*cdf0e10cSrcweir 			if ( xPage == null )
72*cdf0e10cSrcweir 			{
73*cdf0e10cSrcweir 				m_aTestHelper.Error( "Can not get access to drawing page!" );
74*cdf0e10cSrcweir 				return false;
75*cdf0e10cSrcweir 			}
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir 			XMultiServiceFactory xDrFactory = ( XMultiServiceFactory ) UnoRuntime.queryInterface( XMultiServiceFactory.class,
78*cdf0e10cSrcweir 																								  oDoc );
79*cdf0e10cSrcweir 			if ( xDrFactory == null )
80*cdf0e10cSrcweir 			{
81*cdf0e10cSrcweir 				m_aTestHelper.Error( "Can not get drawing factory!" );
82*cdf0e10cSrcweir 				return false;
83*cdf0e10cSrcweir 			}
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir 			Object oShape = xDrFactory.createInstance( "com.sun.star.drawing.OLE2Shape" );
86*cdf0e10cSrcweir 			XShape xShape = ( XShape ) UnoRuntime.queryInterface( XShape.class, oShape );
87*cdf0e10cSrcweir 			if ( xShape == null )
88*cdf0e10cSrcweir 			{
89*cdf0e10cSrcweir 				m_aTestHelper.Error( "Can not create new shape!" );
90*cdf0e10cSrcweir 				return false;
91*cdf0e10cSrcweir 			}
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 			XPropertySet xShapeProps = ( XPropertySet ) UnoRuntime.queryInterface( XPropertySet.class, oShape );
94*cdf0e10cSrcweir 			if ( xShapeProps == null )
95*cdf0e10cSrcweir 			{
96*cdf0e10cSrcweir 				m_aTestHelper.Error( "Can not get access to shapes properties!" );
97*cdf0e10cSrcweir 				return false;
98*cdf0e10cSrcweir 			}
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 			xPage.add( xShape );
101*cdf0e10cSrcweir 			xShapeProps.setPropertyValue( "CLSID", "078B7ABA-54FC-457F-8551-6147e776a997" );
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 			Object oEmbObj = xShapeProps.getPropertyValue( "EmbeddedObject" );
104*cdf0e10cSrcweir 			XEmbeddedObject xEmbObj = ( XEmbeddedObject ) UnoRuntime.queryInterface( XEmbeddedObject.class, oEmbObj );
105*cdf0e10cSrcweir 			if ( xEmbObj == null )
106*cdf0e10cSrcweir 			{
107*cdf0e10cSrcweir 				m_aTestHelper.Error( "Embedded object can not be accessed!" );
108*cdf0e10cSrcweir 				return false;
109*cdf0e10cSrcweir 			}
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir 			XEmbeddedClient xClient = xEmbObj.getClientSite();
112*cdf0e10cSrcweir 			if ( xClient == null )
113*cdf0e10cSrcweir 			{
114*cdf0e10cSrcweir 				m_aTestHelper.Error( "The client for the object must be set!" );
115*cdf0e10cSrcweir 				return false;
116*cdf0e10cSrcweir 			}
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 			Object oReplacement = xShapeProps.getPropertyValue( "Graphic" );
119*cdf0e10cSrcweir 			XGraphic xReplGraph = ( XGraphic ) UnoRuntime.queryInterface( XGraphic.class, oReplacement );
120*cdf0e10cSrcweir 			if ( xReplGraph == null )
121*cdf0e10cSrcweir 			{
122*cdf0e10cSrcweir 				m_aTestHelper.Error( "The replacement graphic should be available!" );
123*cdf0e10cSrcweir 				return false;
124*cdf0e10cSrcweir 			}
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 			return true;
127*cdf0e10cSrcweir 		}
128*cdf0e10cSrcweir 		catch( Exception e )
129*cdf0e10cSrcweir 		{
130*cdf0e10cSrcweir 			m_aTestHelper.Error( "Exception: " + e );
131*cdf0e10cSrcweir 			return false;
132*cdf0e10cSrcweir 		}
133*cdf0e10cSrcweir     }
134*cdf0e10cSrcweir }
135*cdf0e10cSrcweir 
136