Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / embeddedobj / qa / embedding / Test01.java
blob3a8b425bbccb3ab862b8d72b9c8968ab1ac13c2a
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package complex.embedding;
21 import com.sun.star.uno.XInterface;
22 import com.sun.star.lang.XMultiServiceFactory;
23 import com.sun.star.lang.XSingleServiceFactory;
25 import com.sun.star.bridge.XUnoUrlResolver;
26 import com.sun.star.uno.UnoRuntime;
27 import com.sun.star.uno.XInterface;
28 import com.sun.star.beans.XPropertySet;
29 import com.sun.star.frame.XLoadable;
30 import com.sun.star.drawing.XDrawPagesSupplier;
31 import com.sun.star.drawing.XDrawPages;
32 import com.sun.star.drawing.XDrawPage;
33 import com.sun.star.drawing.XShape;
34 import com.sun.star.graphic.XGraphic;
36 import com.sun.star.embed.*;
38 import share.LogWriter;
39 import complex.embedding.TestHelper;
40 import complex.embedding.EmbeddingTest;
42 public class Test01 implements EmbeddingTest {
44 XMultiServiceFactory m_xMSF;
45 TestHelper m_aTestHelper;
47 public Test01( XMultiServiceFactory xMSF, LogWriter aLogWriter )
49 m_xMSF = xMSF;
50 m_aTestHelper = new TestHelper( aLogWriter, "Test01: " );
53 public boolean test()
55 try
57 Object oDoc = m_xMSF.createInstance( "com.sun.star.comp.Draw.DrawingDocument" );
58 XLoadable xLoad = (XLoadable) UnoRuntime.queryInterface( XLoadable.class, oDoc );
59 if ( xLoad == null )
61 m_aTestHelper.Error( "Can not get XLoadable!" );
62 return false;
65 xLoad.initNew();
67 XDrawPagesSupplier xDPSupply = (XDrawPagesSupplier) UnoRuntime.queryInterface( XDrawPagesSupplier.class, oDoc );
68 if ( xDPSupply == null )
70 m_aTestHelper.Error( "Can not get XDrawPagesSupplier!" );
71 return false;
74 XDrawPages xDrawPages = xDPSupply.getDrawPages();
75 if ( xDrawPages == null )
77 m_aTestHelper.Error( "Can not get XDrawPages object!" );
78 return false;
81 if ( xDrawPages.getCount() == 0 )
83 m_aTestHelper.Error( "There must be at least one page in the document!" );
84 return false;
87 Object oPage = xDrawPages.getByIndex( 0 );
88 XDrawPage xPage = (XDrawPage) UnoRuntime.queryInterface( XDrawPage.class, oPage );
89 if ( xPage == null )
91 m_aTestHelper.Error( "Can not get access to drawing page!" );
92 return false;
95 XMultiServiceFactory xDrFactory = ( XMultiServiceFactory ) UnoRuntime.queryInterface( XMultiServiceFactory.class,
96 oDoc );
97 if ( xDrFactory == null )
99 m_aTestHelper.Error( "Can not get drawing factory!" );
100 return false;
103 Object oShape = xDrFactory.createInstance( "com.sun.star.drawing.OLE2Shape" );
104 XShape xShape = ( XShape ) UnoRuntime.queryInterface( XShape.class, oShape );
105 if ( xShape == null )
107 m_aTestHelper.Error( "Can not create new shape!" );
108 return false;
111 XPropertySet xShapeProps = ( XPropertySet ) UnoRuntime.queryInterface( XPropertySet.class, oShape );
112 if ( xShapeProps == null )
114 m_aTestHelper.Error( "Can not get access to shapes properties!" );
115 return false;
118 xPage.add( xShape );
119 xShapeProps.setPropertyValue( "CLSID", "078B7ABA-54FC-457F-8551-6147e776a997" );
121 Object oEmbObj = xShapeProps.getPropertyValue( "EmbeddedObject" );
122 XEmbeddedObject xEmbObj = ( XEmbeddedObject ) UnoRuntime.queryInterface( XEmbeddedObject.class, oEmbObj );
123 if ( xEmbObj == null )
125 m_aTestHelper.Error( "Embedded object can not be accessed!" );
126 return false;
129 XEmbeddedClient xClient = xEmbObj.getClientSite();
130 if ( xClient == null )
132 m_aTestHelper.Error( "The client for the object must be set!" );
133 return false;
136 Object oReplacement = xShapeProps.getPropertyValue( "Graphic" );
137 XGraphic xReplGraph = ( XGraphic ) UnoRuntime.queryInterface( XGraphic.class, oReplacement );
138 if ( xReplGraph == null )
140 m_aTestHelper.Error( "The replacement graphic should be available!" );
141 return false;
144 return true;
146 catch( Exception e )
148 m_aTestHelper.Error( "Exception: " + e );
149 return false;