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
)
50 m_aTestHelper
= new TestHelper( aLogWriter
, "Test01: " );
57 Object oDoc
= m_xMSF
.createInstance( "com.sun.star.comp.Draw.DrawingDocument" );
58 XLoadable xLoad
= (XLoadable
) UnoRuntime
.queryInterface( XLoadable
.class, oDoc
);
61 m_aTestHelper
.Error( "Can not get XLoadable!" );
67 XDrawPagesSupplier xDPSupply
= (XDrawPagesSupplier
) UnoRuntime
.queryInterface( XDrawPagesSupplier
.class, oDoc
);
68 if ( xDPSupply
== null )
70 m_aTestHelper
.Error( "Can not get XDrawPagesSupplier!" );
74 XDrawPages xDrawPages
= xDPSupply
.getDrawPages();
75 if ( xDrawPages
== null )
77 m_aTestHelper
.Error( "Can not get XDrawPages object!" );
81 if ( xDrawPages
.getCount() == 0 )
83 m_aTestHelper
.Error( "There must be at least one page in the document!" );
87 Object oPage
= xDrawPages
.getByIndex( 0 );
88 XDrawPage xPage
= (XDrawPage
) UnoRuntime
.queryInterface( XDrawPage
.class, oPage
);
91 m_aTestHelper
.Error( "Can not get access to drawing page!" );
95 XMultiServiceFactory xDrFactory
= ( XMultiServiceFactory
) UnoRuntime
.queryInterface( XMultiServiceFactory
.class,
97 if ( xDrFactory
== null )
99 m_aTestHelper
.Error( "Can not get drawing factory!" );
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!" );
111 XPropertySet xShapeProps
= ( XPropertySet
) UnoRuntime
.queryInterface( XPropertySet
.class, oShape
);
112 if ( xShapeProps
== null )
114 m_aTestHelper
.Error( "Can not get access to shapes properties!" );
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!" );
129 XEmbeddedClient xClient
= xEmbObj
.getClientSite();
130 if ( xClient
== null )
132 m_aTestHelper
.Error( "The client for the object must be set!" );
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!" );
148 m_aTestHelper
.Error( "Exception: " + e
);