bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / util / _XImportable.java
blob5224cee08a1d47bddf315b238a93360a9105045a
1 /*
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 .
18 package ifc.util;
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;
29 /**
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)
43 /**
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() {
50 boolean res = true;
51 boolean locResult = false;
53 descriptor = oObj.createImportDescriptor(true);
54 log.print("Getting when calling createImportDescriptor(true) --");
57 //printPropertyValue(descriptor);
58 log.println("done");
60 log.print("Checking PropertyNames -- ");
61 locResult = checkPropertyNames(descriptor, names);
62 log.println("Worked: " + locResult);
63 res &= locResult;
65 log.print("Checking PropertyTypes -- ");
66 locResult = checkPropertyTypes(descriptor, types);
67 log.println("Worked: " + locResult);
68 res &= locResult;
70 descriptor = oObj.createImportDescriptor(false);
71 log.print("Getting when calling createImportDescriptor(false) -- ");
74 //printPropertyValue(descriptor);
75 log.println("done");
77 log.print("Checking PropertyNames -- ");
78 locResult = checkPropertyNames(descriptor, names);
79 log.println("Worked: " + locResult);
80 res &= locResult;
82 log.print("Checking PropertyTypes -- ");
83 locResult = checkPropertyTypes(descriptor, types);
84 log.println("Worked - " + locResult);
85 res &= locResult;
87 tRes.tested("createImportDescriptor()", res);
90 public void _doImport() {
91 requiredMethod("createImportDescriptor()");
92 boolean res = true;
94 log.print("Setting the ImportDescriptor (Bibliograpy, Table, biblio) -- ");
95 descriptor[0].Value = "Bibliography";
96 descriptor[1].Value = com.sun.star.sheet.DataImportMode.TABLE;
97 descriptor[2].Value = "biblio";
98 log.println("done");
100 log.print("Importing data (Bibliograpy, Table, biblio) -- ");
101 oObj.doImport(descriptor);
102 log.println("done");
104 log.println("Checking data");
105 res &= checkA1("Identifier");
107 log.print("Setting the ImportDescriptor (Bibliograpy, SQL, select Author from biblio) -- ");
108 descriptor[0].Value = "Bibliography";
109 descriptor[1].Value = com.sun.star.sheet.DataImportMode.SQL;
110 descriptor[2].Value = "select Author from biblio";
111 log.println("done");
113 log.print("Importing data (Bibliograpy, SQL, select Author from biblio) -- ");
114 oObj.doImport(descriptor);
115 log.println("done");
117 log.println("Checking data");
118 res &= checkA1("Author");
120 tRes.tested("doImport()",res);
123 protected void printPropertyValue(PropertyValue[] props) {
124 for (int i = 0; i < props.length; i++) {
125 log.println("\tName: " + props[i].Name);
126 log.println("\tValue: " + props[i].Value);
130 protected boolean checkPropertyNames(PropertyValue[] props, String[] names) {
131 boolean res = true;
133 for (int i = 0; i < props.length; i++) {
134 boolean locResult = props[i].Name.equals(names[i]);
136 if (!locResult) {
137 log.println("PropertyName differs for index " + i);
138 log.println("\tGetting: " + props[i].Name);
139 log.println("\tExpected: " + names[i]);
142 res &= locResult;
145 return res;
148 protected boolean checkPropertyTypes(PropertyValue[] props, Type[] types) {
149 boolean res = true;
151 for (int i = 0; i < props.length; i++) {
152 Type ValueType = new Type(props[i].Value.getClass());
153 boolean locResult = ValueType.equals(types[i]);
155 if (!locResult) {
156 log.println("PropertyType differs for " + props[i].Name);
157 log.println("\tGetting: " + ValueType.getTypeName());
158 log.println("\tExpected: " + types[i].getTypeName());
161 res &= locResult;
164 return res;
167 protected boolean checkA1(String expected) {
168 XCellRange range = UnoRuntime.queryInterface(XCellRange.class, tEnv.getTestObject());
169 boolean res = false;
170 try{
171 String a1 = range.getCellByPosition(0,0).getFormula();
172 res = a1.equals(expected);
173 if (!res) {
174 log.println("\tResult differs from expectation");
175 log.println("\tGetting: "+a1);
176 log.println("\tExpected: "+expected);
177 } else {
178 log.println("successful");
180 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
181 log.println("Couldn't get Cell to check");
183 return res;
187 * Dispose environment.
189 protected void after() {
190 disposeEnvironment();