2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 import lib
.MultiMethodTest
;
22 import com
.sun
.star
.beans
.PropertyValue
;
23 import com
.sun
.star
.table
.XCellRange
;
24 import com
.sun
.star
.uno
.Type
;
25 import com
.sun
.star
.uno
.UnoRuntime
;
26 import com
.sun
.star
.util
.XImportable
;
30 * checks the Interface XImportable
32 public class _XImportable
extends MultiMethodTest
{
33 public XImportable oObj
;
34 protected PropertyValue
[] descriptor
= null;
35 protected String
[] names
= new String
[] {
36 "DatabaseName", "SourceType", "SourceObject", "IsNative"
38 protected Type
[] types
= new Type
[] {
39 new Type(String
.class), new Type(com
.sun
.star
.sheet
.DataImportMode
.class),
40 new Type(String
.class), new Type(Boolean
.class)
44 * creates an ImportDescriptor, the gained PropertyValues can be found
45 * in com.sun.star.sheet.DatabaseImportDescriptor.<br>
46 * Returns OK state is all propertynames and types are the specified.
49 public void _createImportDescriptor() {
51 boolean locResult
= false;
53 descriptor
= oObj
.createImportDescriptor(true);
54 log
.print("Getting when calling createImportDescriptor(true) --");
59 log
.print("Checking PropertyNames -- ");
60 locResult
= checkPropertyNames(descriptor
, names
);
61 log
.println("Worked: " + locResult
);
64 log
.print("Checking PropertyTypes -- ");
65 locResult
= checkPropertyTypes(descriptor
, types
);
66 log
.println("Worked: " + locResult
);
69 descriptor
= oObj
.createImportDescriptor(false);
70 log
.print("Getting when calling createImportDescriptor(false) -- ");
75 log
.print("Checking PropertyNames -- ");
76 locResult
= checkPropertyNames(descriptor
, names
);
77 log
.println("Worked: " + locResult
);
80 log
.print("Checking PropertyTypes -- ");
81 locResult
= checkPropertyTypes(descriptor
, types
);
82 log
.println("Worked - " + locResult
);
85 tRes
.tested("createImportDescriptor()", res
);
88 public void _doImport() {
89 requiredMethod("createImportDescriptor()");
92 log
.print("Setting the ImportDescriptor (Bibliograpy, Table, biblio) -- ");
93 descriptor
[0].Value
= "Bibliography";
94 descriptor
[1].Value
= com
.sun
.star
.sheet
.DataImportMode
.TABLE
;
95 descriptor
[2].Value
= "biblio";
98 log
.print("Importing data (Bibliograpy, Table, biblio) -- ");
99 oObj
.doImport(descriptor
);
102 log
.println("Checking data");
103 res
&= checkA1("Identifier");
105 log
.print("Setting the ImportDescriptor (Bibliograpy, SQL, select Author from biblio) -- ");
106 descriptor
[0].Value
= "Bibliography";
107 descriptor
[1].Value
= com
.sun
.star
.sheet
.DataImportMode
.SQL
;
108 descriptor
[2].Value
= "select Author from biblio";
111 log
.print("Importing data (Bibliograpy, SQL, select Author from biblio) -- ");
112 oObj
.doImport(descriptor
);
115 log
.println("Checking data");
116 res
&= checkA1("Author");
118 tRes
.tested("doImport()",res
);
121 protected void printPropertyValue(PropertyValue
[] props
) {
122 for (int i
= 0; i
< props
.length
; i
++) {
123 log
.println("\tName: " + props
[i
].Name
);
124 log
.println("\tValue: " + props
[i
].Value
);
128 protected boolean checkPropertyNames(PropertyValue
[] props
, String
[] names
) {
131 for (int i
= 0; i
< props
.length
; i
++) {
132 boolean locResult
= props
[i
].Name
.equals(names
[i
]);
135 log
.println("PropertyName differs for index " + i
);
136 log
.println("\tGetting: " + props
[i
].Name
);
137 log
.println("\tExpected: " + names
[i
]);
146 protected boolean checkPropertyTypes(PropertyValue
[] props
, Type
[] types
) {
149 for (int i
= 0; i
< props
.length
; i
++) {
150 Type ValueType
= new Type(props
[i
].Value
.getClass());
151 boolean locResult
= ValueType
.equals(types
[i
]);
154 log
.println("PropertyType differs for " + props
[i
].Name
);
155 log
.println("\tGetting: " + ValueType
.getTypeName());
156 log
.println("\tExpected: " + types
[i
].getTypeName());
165 protected boolean checkA1(String expected
) {
166 XCellRange range
= UnoRuntime
.queryInterface(XCellRange
.class, tEnv
.getTestObject());
169 String a1
= range
.getCellByPosition(0,0).getFormula();
170 res
= a1
.equals(expected
);
172 log
.println("\tResult differs from expectation");
173 log
.println("\tGetting: "+a1
);
174 log
.println("\tExpected: "+expected
);
176 log
.println("successful");
178 } catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
) {
179 log
.println("Couldn't get Cell to check");
185 * Dispose environment.
188 protected void after() {
189 disposeEnvironment();