Kaydet (Commit) deb9e36c authored tarafından Robert Antoni Buj i Gelonch's avatar Robert Antoni Buj i Gelonch Kaydeden (comit) Stephan Bergmann

javaunohelper: migrate ComponentContext_Test to JUnit

$ make JunitTest_juh_ComponentContext

Change-Id: Ibcd8ed7b1da7da82593e51b6f25a53763e9455f7
Signed-off-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst ce5dd864
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
$(eval $(call gb_JunitTest_JunitTest,juh_ComponentContext))
$(eval $(call gb_JunitTest_use_jars,juh_ComponentContext,\
ridl \
jurt \
))
$(eval $(call gb_JunitTest_use_jar_classset,juh_ComponentContext,ridljar))
$(eval $(call gb_JunitTest_add_sourcefiles,juh_ComponentContext,\
javaunohelper/com/sun/star/comp/helper/Bootstrap \
javaunohelper/com/sun/star/comp/helper/BootstrapException \
javaunohelper/com/sun/star/comp/helper/ComponentContext \
javaunohelper/com/sun/star/comp/helper/ComponentContextEntry \
javaunohelper/test/com/sun/star/comp/helper/ComponentContext_Test \
))
$(eval $(call gb_JunitTest_add_classes,juh_ComponentContext,\
com.sun.star.comp.helper.ComponentContext_Test \
))
# vim:set noet sw=4 ts=4:
...@@ -16,6 +16,10 @@ $(eval $(call gb_Module_add_targets,javaunohelper,\ ...@@ -16,6 +16,10 @@ $(eval $(call gb_Module_add_targets,javaunohelper,\
Jar_juh \ Jar_juh \
)) ))
$(eval $(call gb_Module_add_subsequentcheck_targets,javaunohelper,\
JunitTest_juh_ComponentContext \
))
ifneq ($(DISABLE_DYNLOADING),TRUE) ifneq ($(DISABLE_DYNLOADING),TRUE)
$(eval $(call gb_Module_add_targets,javaunohelper,\ $(eval $(call gb_Module_add_targets,javaunohelper,\
Library_juhx \ Library_juhx \
......
...@@ -24,64 +24,44 @@ import com.sun.star.lang.XMultiComponentFactory; ...@@ -24,64 +24,44 @@ import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext; import com.sun.star.uno.XComponentContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
public class ComponentContext_Test { public class ComponentContext_Test {
public static void main(String args[]) {
try {
HashMap<String,Object> table = new HashMap<String,Object>();
table.put( "bla1", new ComponentContextEntry( null, Integer.valueOf( 1 ) ) );
XComponentContext xInitialContext = Bootstrap.createInitialComponentContext( table );
table = new HashMap<String,Object>(); @Test public void test() throws Exception {
table.put( "bla2", new ComponentContextEntry( Integer.valueOf( 2 ) ) ); HashMap<String, Object> table = new HashMap<String, Object>();
table.put( "bla3", Integer.valueOf( 3 ) ); table.put("bla1", new ComponentContextEntry(null, Integer.valueOf(1)));
XComponentContext xContext = new ComponentContext( table, xInitialContext ); XComponentContext xInitialContext = Bootstrap.createInitialComponentContext(table);
XMultiComponentFactory xSMgr = xContext.getServiceManager(); table = new HashMap<String, Object>();
Object o = xSMgr.createInstanceWithContext( "com.sun.star.loader.Java", xContext ); table.put("bla2", new ComponentContextEntry(Integer.valueOf(2)));
if (o == null) table.put("bla3", Integer.valueOf(3));
System.err.println( "### failed raising service: 1!" ); XComponentContext xContext = new ComponentContext(table, xInitialContext);
o = xSMgr.createInstanceWithContext( "com.sun.star.bridge.BridgeFactory", xContext );
if (o == null)
System.err.println( "### failed raising service: 2!" );
o = xSMgr.createInstanceWithContext( "com.sun.star.bridge.UnoUrlResolver", xContext );
if (o == null)
System.err.println( "### failed raising service: 3!" );
o = xSMgr.createInstanceWithContext( "com.sun.star.connection.Connector", xContext );
if (o == null)
System.err.println( "### failed raising service: 4!" );
o = xSMgr.createInstanceWithContext( "com.sun.star.connection.Acceptor", xContext );
if (o == null)
System.err.println( "### failed raising service: 5!" );
o = xSMgr.createInstanceWithContext( "com.sun.star.lang.ServiceManager", xContext );
if (o == null)
System.err.println( "### failed raising service: 6!" );
if (xContext.getValueByName( "bla1" ) == null || XMultiComponentFactory xSMgr = xContext.getServiceManager();
xContext.getValueByName( "bla2" ) == null ||
xContext.getValueByName( "bla3" ) == null ||
xInitialContext.getValueByName( "bla2" ) != null ||
xInitialContext.getValueByName( "bla3" ) != null)
{
System.err.println( "### bootstrap context test failed: 1!" );
}
if (((Integer)xContext.getValueByName( "bla1" )).intValue() != 1 ||
((Integer)xContext.getValueByName( "bla2" )).intValue() != 2 ||
((Integer)xContext.getValueByName( "bla3" )).intValue() != 3 ||
((Integer)xInitialContext.getValueByName( "bla1" )).intValue() != 1)
{
System.err.println( "### bootstrap context test failed: 2!" );
}
XComponent xComp = UnoRuntime.queryInterface( assertNotNull(xSMgr.createInstanceWithContext("com.sun.star.loader.Java", xContext));
XComponent.class, xInitialContext ); assertNotNull(xSMgr.createInstanceWithContext("com.sun.star.bridge.BridgeFactory", xContext));
xComp.dispose(); assertNotNull(xSMgr.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", xContext));
} assertNotNull(xSMgr.createInstanceWithContext("com.sun.star.connection.Connector", xContext));
catch(Exception exception) { assertNotNull(xSMgr.createInstanceWithContext("com.sun.star.connection.Acceptor", xContext));
System.err.println("exception occurred:" + exception); // assertNotNull(xSMgr.createInstanceWithContext("com.sun.star.lang.ServiceManager", xContext));
exception.printStackTrace();
} assertNotNull(xContext.getValueByName("bla1"));
} assertNotNull(xContext.getValueByName("bla2"));
} assertNotNull(xContext.getValueByName("bla3"));
assertNotNull(xInitialContext.getValueByName("bla2"));
assertNotNull(xInitialContext.getValueByName("bla3"));
assertEquals(((Integer) xContext.getValueByName("bla1")).intValue(), 1);
assertEquals(((Integer) xContext.getValueByName("bla2")).intValue(), 2);
assertEquals(((Integer) xContext.getValueByName("bla3")).intValue(), 3);
assertEquals(((Integer) xInitialContext.getValueByName("bla1")).intValue(), 1);
XComponent xComp = UnoRuntime.queryInterface(
XComponent.class, xInitialContext);
xComp.dispose();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment