Started modifying project structure
This commit is contained in:
parent
4e16ed01c2
commit
1e4ee37f89
566 changed files with 3340 additions and 176 deletions
13
src/main/org/libreoffice/example/comp/tests/UnoTests.java
Normal file
13
src/main/org/libreoffice/example/comp/tests/UnoTests.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package org.libreoffice.example.comp.tests;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
import org.libreoffice.example.comp.tests.base.UnoSuite;
|
||||
import org.libreoffice.example.comp.tests.uno.WriterTest;
|
||||
|
||||
@RunWith(UnoSuite.class)
|
||||
@SuiteClasses({WriterTest.class})
|
||||
public class UnoTests {
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package org.libreoffice.example.comp.tests.base;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.runner.Runner;
|
||||
import org.junit.runner.notification.RunNotifier;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.model.InitializationError;
|
||||
import org.junit.runners.model.RunnerBuilder;
|
||||
|
||||
import com.sun.star.frame.XDesktop;
|
||||
import com.sun.star.lang.XMultiComponentFactory;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
import com.sun.star.uno.XComponentContext;
|
||||
|
||||
public class UnoSuite extends Suite {
|
||||
|
||||
private static XComponentContext componentContext;
|
||||
|
||||
public UnoSuite(Class<?> klass, RunnerBuilder builder) throws InitializationError {
|
||||
super(klass, builder);
|
||||
}
|
||||
|
||||
public UnoSuite(RunnerBuilder builder, Class<?>[] classes) throws InitializationError {
|
||||
super(builder, classes);
|
||||
}
|
||||
|
||||
public UnoSuite(Class<?> klass, Class<?>[] suiteClasses) throws InitializationError {
|
||||
super(klass, suiteClasses);
|
||||
}
|
||||
|
||||
public UnoSuite(Class<?> klass, List<Runner> runners) throws InitializationError {
|
||||
super(klass, runners);
|
||||
}
|
||||
|
||||
public UnoSuite(RunnerBuilder builder, Class<?> klass, Class<?>[] suiteClasses) throws InitializationError {
|
||||
super(builder, klass, suiteClasses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(RunNotifier arg0) {
|
||||
try {
|
||||
startOffice();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
super.run(arg0);
|
||||
|
||||
stopOffice();
|
||||
}
|
||||
|
||||
private void startOffice() throws Exception {
|
||||
componentContext = com.sun.star.comp.helper.Bootstrap.bootstrap();
|
||||
}
|
||||
|
||||
private void stopOffice() {
|
||||
try {
|
||||
if (componentContext != null) {
|
||||
// Only the uno test suite which started the office can stop it
|
||||
XMultiComponentFactory xMngr = componentContext.getServiceManager();
|
||||
Object oDesktop = xMngr.createInstanceWithContext("com.sun.star.frame.Desktop", componentContext);
|
||||
XDesktop xDesktop = (XDesktop)UnoRuntime.queryInterface(XDesktop.class, oDesktop);
|
||||
|
||||
xDesktop.terminate();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static XComponentContext getComponentContext() {
|
||||
return componentContext;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package org.libreoffice.example.comp.tests.helper;
|
||||
|
||||
import com.sun.star.beans.PropertyValue;
|
||||
import com.sun.star.frame.FrameSearchFlag;
|
||||
import com.sun.star.frame.XComponentLoader;
|
||||
import com.sun.star.lang.XComponent;
|
||||
import com.sun.star.lang.XMultiComponentFactory;
|
||||
import com.sun.star.text.XTextDocument;
|
||||
import com.sun.star.uno.Exception;
|
||||
import com.sun.star.uno.UnoRuntime;
|
||||
|
||||
import org.libreoffice.example.comp.tests.base.UnoSuite;
|
||||
|
||||
public class UnoHelper {
|
||||
|
||||
public static XTextDocument getWriterDocument() throws Exception {
|
||||
XMultiComponentFactory xMngr = UnoSuite.getComponentContext().getServiceManager();
|
||||
Object oDesktop = xMngr.createInstanceWithContext("com.sun.star.frame.Desktop", UnoSuite.getComponentContext());
|
||||
XComponentLoader xLoader = (XComponentLoader)UnoRuntime.queryInterface(
|
||||
XComponentLoader.class, oDesktop);
|
||||
|
||||
XComponent xDoc = xLoader.loadComponentFromURL("private:factory/swriter", "_default",
|
||||
FrameSearchFlag.ALL, new PropertyValue[0]);
|
||||
|
||||
return (XTextDocument)UnoRuntime.queryInterface(XTextDocument.class, xDoc);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package org.libreoffice.example.comp.tests.uno;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.sun.star.text.XTextDocument;
|
||||
|
||||
import org.libreoffice.example.comp.tests.helper.UnoHelper;
|
||||
|
||||
public class WriterTest {
|
||||
|
||||
private XTextDocument xTextDocument;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
xTextDocument = UnoHelper.getWriterDocument();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertNotNull(xTextDocument);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue