xref: /AOO41X/main/qadevOOo/tests/java/ifc/configuration/backend/_XSingleLayerStratum.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*
2  * _XSingleLayerStratum.java
3  *
4  * Created on 23. March 2004, 16:37
5  */
6 package ifc.configuration.backend;
7 import com.sun.star.configuration.backend.XLayer;
8 import com.sun.star.configuration.backend.XSingleLayerStratum;
9 import com.sun.star.configuration.backend.XUpdatableLayer;
10 
11 import lib.MultiMethodTest;
12 
13 import util.XLayerHandlerImpl;
14 
15 
16 public class _XSingleLayerStratum extends MultiMethodTest {
17     public XSingleLayerStratum oObj;
18 
19     public void _getLayer() {
20         String aLayerID = "org.openoffice.Office.Common";
21         boolean res = true;
22 
23         try {
24             XLayer aLayer = oObj.getLayer("", "");
25             log.println("Exception expected -- FAILED");
26             res = false;
27         } catch (com.sun.star.configuration.backend.BackendAccessException e) {
28             log.println("unexpected Exception " + e + " -- FAILED");
29             res = false;
30         } catch (com.sun.star.lang.IllegalArgumentException e) {
31             log.println("expected Exception -- OK");
32         }
33 
34         try {
35             XLayer aLayer = oObj.getLayer(aLayerID, "");
36             res &= (aLayer != null);
37 
38             if (aLayer == null) {
39                 log.println("\treturned Layer is NULL -- FAILED");
40             }
41 
42             res &= checkLayer(aLayer);
43         } catch (com.sun.star.configuration.backend.BackendAccessException e) {
44             log.println("unexpected Exception -- FAILED");
45             res = false;
46         } catch (com.sun.star.lang.IllegalArgumentException e) {
47             log.println("unexpected Exception -- FAILED");
48             res = false;
49         }
50 
51         tRes.tested("getLayer()", res);
52     }
53 
54     public void _getUpdatableLayer() {
55         String aLayerID = "org.openoffice.Office.Common";
56         boolean res = true;
57 
58         try {
59             XUpdatableLayer aLayer = oObj.getUpdatableLayer("");
60             log.println("Exception expected -- FAILED");
61             res = false;
62         } catch (com.sun.star.configuration.backend.BackendAccessException e) {
63             log.println("unexpected Exception " + e + " -- FAILED");
64             res = false;
65         } catch (com.sun.star.lang.IllegalArgumentException e) {
66             log.println("expected Exception -- OK");
67         } catch (com.sun.star.lang.NoSupportException e) {
68             log.println("unexpected Exception -- FAILED");
69             res = false;
70         }
71 
72         try {
73             XUpdatableLayer aLayer = oObj.getUpdatableLayer(aLayerID);
74             res &= (aLayer != null);
75 
76             if (aLayer == null) {
77                 log.println("\treturned Layer is NULL -- FAILED");
78             }
79 
80             res &= checkLayer(aLayer);
81         } catch (com.sun.star.configuration.backend.BackendAccessException e) {
82             log.println("unexpected Exception -- FAILED");
83             res = false;
84         } catch (com.sun.star.lang.IllegalArgumentException e) {
85             log.println("unexpected Exception -- FAILED");
86             res = false;
87         } catch (com.sun.star.lang.NoSupportException e) {
88             log.println("unexpected Exception -- FAILED");
89             res = false;
90         }
91 
92         tRes.tested("getUpdatableLayer()", res);
93     }
94 
95     protected boolean checkLayer(XLayer aLayer) {
96         boolean res = false;
97 
98         log.println("Checking for Exception in case of null argument");
99 
100         try {
101             aLayer.readData(null);
102         } catch (com.sun.star.lang.NullPointerException e) {
103             log.println("Expected Exception -- OK");
104             res = true;
105         } catch (com.sun.star.lang.WrappedTargetException e) {
106             log.println("Unexpected Exception (" + e + ") -- FAILED");
107         } catch (com.sun.star.configuration.backend.MalformedDataException e) {
108             log.println("Unexpected Exception (" + e + ") -- FAILED");
109         }
110 
111         log.println("checking read data with own XLayerHandler implementation");
112 
113         try {
114             XLayerHandlerImpl xLayerHandler = new XLayerHandlerImpl();
115             aLayer.readData(xLayerHandler);
116 
117             String implCalled = xLayerHandler.getCalls();
118             log.println(implCalled);
119 
120             int sl = implCalled.indexOf("startLayer");
121 
122             if (sl < 0) {
123                 log.println("startLayer wasn't called -- FAILED");
124                 res &= false;
125             } else {
126                 log.println("startLayer was called -- OK");
127                 res &= true;
128             }
129 
130             int el = implCalled.indexOf("endLayer");
131 
132             if (el < 0) {
133                 log.println("endLayer wasn't called -- FAILED");
134                 res &= false;
135             } else {
136                 log.println("endLayer was called -- OK");
137                 res &= true;
138             }
139         } catch (com.sun.star.lang.NullPointerException e) {
140             log.println("Unexpected Exception (" + e + ") -- FAILED");
141             res &= false;
142         } catch (com.sun.star.lang.WrappedTargetException e) {
143             log.println("Unexpected Exception (" + e + ") -- FAILED");
144             res &= false;
145         } catch (com.sun.star.configuration.backend.MalformedDataException e) {
146             log.println("Unexpected Exception (" + e + ") -- FAILED");
147             res &= false;
148         }
149 
150         return res;
151     }
152 }
153