1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 package ifc.configuration.backend;
24 
25 import com.sun.star.configuration.backend.XLayer;
26 import com.sun.star.configuration.backend.XLayerHandler;
27 import com.sun.star.io.XActiveDataSink;
28 import com.sun.star.io.XInputStream;
29 import com.sun.star.lang.XMultiServiceFactory;
30 import com.sun.star.ucb.XSimpleFileAccess;
31 import com.sun.star.uno.Type;
32 import com.sun.star.uno.UnoRuntime;
33 
34 import lib.MultiMethodTest;
35 
36 import util.XLayerHandlerImpl;
37 
38 
39 public class _XLayerHandler extends MultiMethodTest {
40     public XLayerHandler oObj = null;
41 
42     /** this method contains the logic for all test methods
43      * the others will be passed OK if this one is
44      */
_endLayer()45     public void _endLayer() {
46         boolean res = false;
47 
48         try {
49             oObj.startLayer();
50             oObj.overrideNode("org.openoffice.Setup", (short) 0, false);
51             oObj.overrideNode("Office", (short) 0, false);
52             oObj.overrideProperty("ooSetupInstCompleted", (short) 0,
53                                   new Type(java.lang.String.class), false);
54             oObj.setPropertyValue(new Boolean(false));
55             oObj.endProperty();
56             oObj.overrideProperty("ooSetupShowIntro", (short) 0,
57                                   new Type(java.lang.String.class), false);
58             oObj.setPropertyValue(new Boolean(true));
59             oObj.endProperty();
60             oObj.overrideProperty("ooSetupLocales", (short) 0,
61                                   new Type(java.lang.String.class), false);
62             oObj.setPropertyValue("en-US");
63             oObj.endProperty();
64             oObj.overrideNode("Factories", (short) 0, false);
65             oObj.addOrReplaceNode("com.sun.star.chart.ChartDocument",
66                                   (short) 0);
67             oObj.overrideProperty("ooSetupFactoryEmptyDocumentURL", (short) 0,
68                                   new Type(java.lang.String.class), false);
69             oObj.setPropertyValue("private:factory/schart");
70             oObj.endProperty();
71             oObj.overrideProperty("ooSetupFactoryIcon", (short) 0,
72                                   new Type(java.lang.Long.class), false);
73             oObj.setPropertyValue(new Integer(13));
74             oObj.endProperty();
75             oObj.overrideProperty("ooSetupFactoryShortName", (short) 0,
76                                   new Type(java.lang.String.class), false);
77             oObj.setPropertyValue("schart");
78             oObj.setPropertyValueForLocale("TemplateFile", "en-US");
79             oObj.endProperty();
80             oObj.overrideProperty("ooSetupFactoryTemplateFile", (short) 0,
81                                   new Type(java.lang.String.class), false);
82             oObj.setPropertyValue("empty");
83             oObj.endProperty();
84             oObj.addProperty("ooSetupFactoryTemplateFile", (short) 0,
85                              new Type(java.lang.String.class));
86             oObj.addPropertyWithValue("ooSetupFactoryTemplateFile", (short) 0,
87                                       "TemplateFile");
88             oObj.endNode();
89 
90             oObj.addOrReplaceNode("dropme", (short) 0);
91             oObj.overrideProperty("anyway", (short) 0,
92                                   new Type(java.lang.String.class), false);
93             oObj.setPropertyValue("nice");
94             oObj.endProperty();
95             oObj.dropNode("dropme");
96             oObj.endNode();
97 
98             oObj.addOrReplaceNodeFromTemplate("FromTemplate",
99                                               new com.sun.star.configuration.backend.TemplateIdentifier(
100                                                       "org.openoffice.Setup",
101                                                       "Setup"), (short) 0);
102             oObj.endNode();
103 
104             oObj.endNode();
105             oObj.endNode();
106             oObj.endNode();
107             oObj.endLayer();
108 
109             Object LayerParser = ((XMultiServiceFactory) tParam.getMSF()).createInstance(
110                                          "com.sun.star.comp.configuration.backend.xml.LayerParser");
111 
112             XActiveDataSink xSink = (XActiveDataSink) UnoRuntime.queryInterface(
113                                             XActiveDataSink.class, LayerParser);
114             Object fileacc = ((XMultiServiceFactory) tParam.getMSF()).createInstance(
115                                      "com.sun.star.comp.ucb.SimpleFileAccess");
116             XSimpleFileAccess simpleAccess = (XSimpleFileAccess) UnoRuntime.queryInterface(
117                                                      XSimpleFileAccess.class,
118                                                      fileacc);
119 
120             String filename = util.utils.getOfficeTemp(
121                                       (XMultiServiceFactory) tParam.getMSF()) +
122                               "LayerWriter.xcu";
123             log.println("Going to parse: " + filename);
124 
125             XInputStream xStream = simpleAccess.openFileRead(filename);
126 
127             xSink.setInputStream(xStream);
128 
129             XLayer xLayer = (XLayer) UnoRuntime.queryInterface(XLayer.class,
130                                                                LayerParser);
131 
132             XLayerHandlerImpl xLayerHandler = new XLayerHandlerImpl();
133 
134             xLayer.readData(xLayerHandler);
135 
136             res = xLayerHandler.getCalls().equals(getExpected());
137 
138             if (!res) {
139                 log.println("#### Getting: ");
140                 log.println(xLayerHandler.getCalls());
141                 log.println("#### Expected: ");
142                 log.println(getExpected());
143             }
144         } catch (com.sun.star.configuration.backend.MalformedDataException e) {
145             log.println("Unexpected Exception " + e);
146         } catch (com.sun.star.lang.WrappedTargetException e) {
147             log.println("Unexpected Exception " + e);
148         } catch (com.sun.star.uno.Exception e) {
149             log.println("Unexpected Exception " + e);
150         }
151 
152         tRes.tested("endLayer()", res);
153     }
154 
_addOrReplaceNode()155     public void _addOrReplaceNode() {
156         requiredMethod("endLayer()");
157         tRes.tested("addOrReplaceNode()", true);
158     }
159 
_addOrReplaceNodeFromTemplate()160     public void _addOrReplaceNodeFromTemplate() {
161         requiredMethod("endLayer()");
162         tRes.tested("addOrReplaceNodeFromTemplate()", true);
163     }
164 
_addProperty()165     public void _addProperty() {
166         requiredMethod("endLayer()");
167         tRes.tested("addProperty()", true);
168     }
169 
_addPropertyWithValue()170     public void _addPropertyWithValue() {
171         requiredMethod("endLayer()");
172         tRes.tested("addPropertyWithValue()", true);
173     }
174 
_dropNode()175     public void _dropNode() {
176         requiredMethod("endLayer()");
177         tRes.tested("dropNode()", true);
178     }
179 
_endNode()180     public void _endNode() {
181         requiredMethod("endLayer()");
182         tRes.tested("endNode()", true);
183     }
184 
_endProperty()185     public void _endProperty() {
186         requiredMethod("endLayer()");
187         tRes.tested("endProperty()", true);
188     }
189 
_overrideNode()190     public void _overrideNode() {
191         requiredMethod("endLayer()");
192         tRes.tested("overrideNode()", true);
193     }
194 
_overrideProperty()195     public void _overrideProperty() {
196         requiredMethod("endLayer()");
197         tRes.tested("overrideProperty()", true);
198     }
199 
_setPropertyValue()200     public void _setPropertyValue() {
201         requiredMethod("endLayer()");
202         tRes.tested("setPropertyValue()", true);
203     }
204 
_setPropertyValueForLocale()205     public void _setPropertyValueForLocale() {
206         requiredMethod("endLayer()");
207         tRes.tested("setPropertyValueForLocale()", true);
208     }
209 
_startLayer()210     public void _startLayer() {
211         requiredMethod("endLayer()");
212         tRes.tested("startLayer()", true);
213     }
214 
getExpected()215     protected String getExpected() {
216         String ls = System.getProperty("line.separator");
217         String expected = "startLayer();" + ls;
218         expected += ("overrideNode(org.openoffice.Setup,0,false);" + ls);
219         expected += ("overrideNode(Office,0,false);" + ls);
220         expected += ("overrideProperty(ooSetupInstCompleted,0,Type[string],false);" + ls);
221         expected += ("setPropertyValue(false);" + ls);
222         expected += ("endProperty();" + ls);
223         expected += ("overrideProperty(ooSetupShowIntro,0,Type[string],false);" + ls);
224         expected += ("setPropertyValue(true);" + ls);
225         expected += ("endProperty();" + ls);
226         expected += ("overrideProperty(ooSetupLocales,0,Type[string],false);" + ls);
227         expected += ("setPropertyValue(en-US);" + ls);
228         expected += ("endProperty();" + ls);
229         expected += ("overrideNode(Factories,0,false);" + ls);
230         expected += ("addOrReplace(com.sun.star.chart.ChartDocument,0);" + ls);
231         expected += ("overrideProperty(ooSetupFactoryEmptyDocumentURL,0,Type[string],false);" + ls);
232         expected += ("setPropertyValue(private:factory/schart);" + ls);
233         expected += ("endProperty();" + ls);
234         expected += ("overrideProperty(ooSetupFactoryIcon,0,Type[hyper],false);" + ls);
235         expected += ("setPropertyValue(13);" + ls);
236         expected += ("endProperty();" + ls);
237         expected += ("overrideProperty(ooSetupFactoryShortName,0,Type[string],false);" + ls);
238         expected += ("setPropertyValue(schart);" + ls);
239         expected += ("setPropertyValueForLocale(TemplateFile,en-US);" + ls);
240         expected += ("endProperty();" + ls);
241         expected += ("overrideProperty(ooSetupFactoryTemplateFile,0,Type[string],false);" + ls);
242         expected += ("setPropertyValue(empty);" + ls);
243         expected += ("endProperty();" + ls);
244         expected += ("addProperty(ooSetupFactoryTemplateFile,0,Type[string]);" + ls);
245         expected += ("addPropertyWithValue(ooSetupFactoryTemplateFile,0,TemplateFile);" + ls);
246         expected += ("endNode();" + ls);
247         expected += ("addOrReplace(dropme,0);" + ls);
248         expected += ("overrideProperty(anyway,0,Type[string],false);" + ls);
249         expected += ("setPropertyValue(nice);" + ls);
250         expected += ("endProperty();" + ls);
251         expected += ("dropNode(dropme);" + ls);
252         expected += ("endNode();" + ls);
253         expected += ("addOrReplace(FromTemplate,0);" + ls);
254         expected += ("endNode();" + ls);
255         expected += ("endNode();" + ls);
256         expected += ("endNode();" + ls);
257         expected += ("endNode();" + ls);
258         expected += ("endLayer();" + ls);
259 
260         return expected;
261     }
262 }