1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
29 import lib
.MultiMethodTest
;
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
;
39 * checks the Interface XImportable
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"
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)
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.
58 public void _createImportDescriptor() {
60 boolean locResult
= false;
62 descriptor
= oObj
.createImportDescriptor(true);
63 log
.print("Getting when calling createImportDescriptor(true) --");
66 //printPropertyValue(descriptor);
69 log
.print("Checking PropertyNames -- ");
70 locResult
= checkPropertyNames(descriptor
, names
);
71 log
.println("Worked: " + locResult
);
74 log
.print("Checking PropertyTypes -- ");
75 locResult
= checkPropertyTypes(descriptor
, types
);
76 log
.println("Worked: " + locResult
);
79 descriptor
= oObj
.createImportDescriptor(false);
80 log
.print("Getting when calling createImportDescriptor(false) -- ");
83 //printPropertyValue(descriptor);
86 log
.print("Checking PropertyNames -- ");
87 locResult
= checkPropertyNames(descriptor
, names
);
88 log
.println("Worked: " + locResult
);
91 log
.print("Checking PropertyTypes -- ");
92 locResult
= checkPropertyTypes(descriptor
, types
);
93 log
.println("Worked - " + locResult
);
96 tRes
.tested("createImportDescriptor()", res
);
99 public void _doImport() {
100 requiredMethod("createImportDescriptor()");
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";
109 log
.print("Importing data (Bibliograpy, Table, biblio) -- ");
110 oObj
.doImport(descriptor
);
113 log
.println("Checking data");
114 res
&= checkA1("Identifier");
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";
122 log
.print("Importing data (Bibliograpy, SQL, select Author from biblio) -- ");
123 oObj
.doImport(descriptor
);
126 log
.println("Checking data");
127 res
&= checkA1("Author");
129 tRes
.tested("doImport()",res
);
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
);
139 protected boolean checkPropertyNames(PropertyValue
[] props
, String
[] names
) {
142 for (int i
= 0; i
< props
.length
; i
++) {
143 boolean locResult
= props
[i
].Name
.equals(names
[i
]);
146 log
.println("PropertyName differs for index " + i
);
147 log
.println("\tGetting: " + props
[i
].Name
);
148 log
.println("\tExpected: " + names
[i
]);
157 protected boolean checkPropertyTypes(PropertyValue
[] props
, Type
[] types
) {
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
]);
165 log
.println("PropertyType differs for " + props
[i
].Name
);
166 log
.println("\tGetting: " + ValueType
.getTypeName());
167 log
.println("\tExpected: " + types
[i
].getTypeName());
176 protected boolean checkA1(String expected
) {
177 XCellRange range
= (XCellRange
) UnoRuntime
.queryInterface(XCellRange
.class, tEnv
.getTestObject());
180 String a1
= range
.getCellByPosition(0,0).getFormula();
181 res
= a1
.equals(expected
);
183 log
.println("\tResult differs from expectation");
184 log
.println("\tGetting: "+a1
);
185 log
.println("\tExpected: "+expected
);
187 log
.println("successful");
189 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
190 log
.println("Couldn't get Cell to check");
196 * Dispose environment.
198 protected void after() {
199 disposeEnvironment();