xref: /AOO41X/main/qadevOOo/tests/java/ifc/util/_XImportable.java (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package ifc.util;
28 
29 import lib.MultiMethodTest;
30 
31 import com.sun.star.beans.PropertyValue;
32 import com.sun.star.table.XCellRange;
33 import com.sun.star.uno.Type;
34 import com.sun.star.uno.UnoRuntime;
35 import com.sun.star.util.XImportable;
36 
37 
38 /**
39  * checks the Interface XImportable
40  */
41 public class _XImportable extends MultiMethodTest {
42     public XImportable oObj;
43     protected PropertyValue[] descriptor = null;
44     protected String[] names = new String[] {
45         "DatabaseName", "SourceType", "SourceObject", "IsNative"
46     };
47     protected Type[] types = new Type[] {
48         new Type(String.class), new Type(com.sun.star.sheet.DataImportMode.class),
49         new Type(String.class), new Type(Boolean.class)
50     };
51 
52     /**
53      * creates an ImportDescriptor, the gained PropertyValues can be found
54      * in com.sun.star.sheet.DatabaseImportDescriptor.<br>
55      * Returns OK state is all propertynames and types are the specified.
56      */
57 
58     public void _createImportDescriptor() {
59         boolean res = true;
60         boolean locResult = false;
61 
62         descriptor = oObj.createImportDescriptor(true);
63         log.print("Getting when calling createImportDescriptor(true) --");
64 
65 
66         //printPropertyValue(descriptor);
67         log.println("done");
68 
69         log.print("Checking PropertyNames -- ");
70         locResult = checkPropertyNames(descriptor, names);
71         log.println("Worked: " + locResult);
72         res &= locResult;
73 
74         log.print("Checking PropertyTypes -- ");
75         locResult = checkPropertyTypes(descriptor, types);
76         log.println("Worked: " + locResult);
77         res &= locResult;
78 
79         descriptor = oObj.createImportDescriptor(false);
80         log.print("Getting when calling createImportDescriptor(false) -- ");
81 
82 
83         //printPropertyValue(descriptor);
84         log.println("done");
85 
86         log.print("Checking PropertyNames -- ");
87         locResult = checkPropertyNames(descriptor, names);
88         log.println("Worked: " + locResult);
89         res &= locResult;
90 
91         log.print("Checking PropertyTypes -- ");
92         locResult = checkPropertyTypes(descriptor, types);
93         log.println("Worked - " + locResult);
94         res &= locResult;
95 
96         tRes.tested("createImportDescriptor()", res);
97     }
98 
99     public void _doImport() {
100         requiredMethod("createImportDescriptor()");
101         boolean res = true;
102 
103         log.print("Setting the ImportDescriptor (Bibliograpy, Table, biblio) -- ");
104         descriptor[0].Value = "Bibliography";
105         descriptor[1].Value = com.sun.star.sheet.DataImportMode.TABLE;
106         descriptor[2].Value = "biblio";
107         log.println("done");
108 
109         log.print("Importing data (Bibliograpy, Table, biblio) -- ");
110         oObj.doImport(descriptor);
111         log.println("done");
112 
113         log.println("Checking data");
114         res &= checkA1("Identifier");
115 
116         log.print("Setting the ImportDescriptor (Bibliograpy, SQL, select Author from biblio) -- ");
117         descriptor[0].Value = "Bibliography";
118         descriptor[1].Value = com.sun.star.sheet.DataImportMode.SQL;
119         descriptor[2].Value = "select Author from biblio";
120         log.println("done");
121 
122         log.print("Importing data (Bibliograpy, SQL, select Author from biblio) -- ");
123         oObj.doImport(descriptor);
124         log.println("done");
125 
126         log.println("Checking data");
127         res &= checkA1("Author");
128 
129         tRes.tested("doImport()",res);
130     }
131 
132     protected void printPropertyValue(PropertyValue[] props) {
133         for (int i = 0; i < props.length; i++) {
134             log.println("\tName: " + props[i].Name);
135             log.println("\tValue: " + props[i].Value);
136         }
137     }
138 
139     protected boolean checkPropertyNames(PropertyValue[] props, String[] names) {
140         boolean res = true;
141 
142         for (int i = 0; i < props.length; i++) {
143             boolean locResult = props[i].Name.equals(names[i]);
144 
145             if (!locResult) {
146                 log.println("PropertyName differs for index " + i);
147                 log.println("\tGetting: " + props[i].Name);
148                 log.println("\tExpected: " + names[i]);
149             }
150 
151             res &= locResult;
152         }
153 
154         return res;
155     }
156 
157     protected boolean checkPropertyTypes(PropertyValue[] props, Type[] types) {
158         boolean res = true;
159 
160         for (int i = 0; i < props.length; i++) {
161             Type ValueType = new Type(props[i].Value.getClass());
162             boolean locResult = ValueType.equals(types[i]);
163 
164             if (!locResult) {
165                 log.println("PropertyType differs for " + props[i].Name);
166                 log.println("\tGetting: " + ValueType.getTypeName());
167                 log.println("\tExpected: " + types[i].getTypeName());
168             }
169 
170             res &= locResult;
171         }
172 
173         return res;
174     }
175 
176     protected boolean checkA1(String expected) {
177         XCellRange range = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, tEnv.getTestObject());
178         boolean res = false;
179         try{
180             String a1 = range.getCellByPosition(0,0).getFormula();
181             res = a1.equals(expected);
182             if (!res) {
183                 log.println("\tResult differs from expectation");
184                 log.println("\tGetting: "+a1);
185                 log.println("\tExpected: "+expected);
186             } else {
187                 log.println("successful");
188             }
189         } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
190             log.println("Couldn't get Cell to check");
191         }
192         return res;
193     }
194 
195     /**
196      * Dispose environment.
197      */
198     protected void after() {
199         disposeEnvironment();
200     }
201 
202 }