1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
package complex.checkColor;
import com.sun.star.awt.Rectangle;
import com.sun.star.awt.Size;
import com.sun.star.awt.WindowDescriptor;
import com.sun.star.awt.XControlModel;
import com.sun.star.awt.XToolkit;
import com.sun.star.awt.XWindow;
import com.sun.star.awt.XWindowPeer;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.XPropertySet;
import com.sun.star.container.XNameAccess;
import com.sun.star.container.XNameContainer;
import com.sun.star.drawing.XControlShape;
import com.sun.star.drawing.XShape;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.frame.XController;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.style.XStyleFamiliesSupplier;
import com.sun.star.text.XTextDocument;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XInterface;
import com.sun.star.view.XControlAccess;
import complexlib.ComplexTestCase;
import java.io.PrintWriter;
import util.FormTools;
import util.SOfficeFactory;
import util.WriterTools;
/**
* Created because of complaint on dev@openoffice.org: check the changing of
* BackColor and IsLandscape properties on the PageStyle service.
*/
public class CheckChangeColor extends ComplexTestCase {
private XToolkit xToolkit = null;
private XWindowPeer xWinPeer = null;
/**
* Get all test method names.
* @return The test methods.
*/
public String[] getTestMethodNames() {
return new String[] {"checkChangeColor"};
}
/**
* Check BackColor and IsLandscape properties, wait for an exception: test
* is ok if no exception happened.
*/
public void checkChangeColor() {
try {
XMultiServiceFactory m_xMSF_ = (XMultiServiceFactory)param.getMSF();
XComponentLoader aLoader = (XComponentLoader)UnoRuntime.queryInterface(XComponentLoader.class,m_xMSF_.createInstance( "com.sun.star.frame.Desktop" ));
XComponent xDocument = (XComponent)UnoRuntime.queryInterface(XComponent.class, aLoader.loadComponentFromURL( "private:factory/swriter", "_blank", 0, new PropertyValue[ 0 ] ) );
// xDocument.addEventListener( this );
XTextDocument oDoc = (XTextDocument) UnoRuntime.queryInterface(XTextDocument.class, xDocument);
XMultiServiceFactory oDocMSF = (XMultiServiceFactory) UnoRuntime.queryInterface(XMultiServiceFactory.class, oDoc );
// XInterface xInterface = (XInterface) oDocMSF.createInstance( "com.sun.star.style.PageStyle" );
// create a supplier to get the Style family collection
XStyleFamiliesSupplier xSupplier = ( XStyleFamiliesSupplier ) UnoRuntime.queryInterface(XStyleFamiliesSupplier.class, oDoc );
// get the NameAccess interface from the Style family collection
XNameAccess xNameAccess = xSupplier.getStyleFamilies();
XNameContainer xPageStyleCollection = (XNameContainer) UnoRuntime.queryInterface(XNameContainer.class, xNameAccess.getByName( "PageStyles" ));
// create a PropertySet to set the properties for the new Pagestyle
XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xPageStyleCollection.getByName("Standard") );
log.println("BackColor @ "+xPropertySet.getPropertyValue("BackColor").toString());
log.println("IsLandscape @ "+xPropertySet.getPropertyValue("IsLandscape").toString());
log.println("Size @ H:"+((Size)xPropertySet.getPropertyValue("Size")).Height+" W:"+((Size)xPropertySet.getPropertyValue("Size")).Width);
log.println("Set Landscape");
xPropertySet.setPropertyValue("IsLandscape",new Boolean(true) );
log.println("Set BackColor");
xPropertySet.setPropertyValue("BackColor",new Integer((int)255000000) );
}
catch(Exception e) {
e.printStackTrace();
failed("Exception.");
}
}
}
|