Branch libreoffice-5-0-4
[LibreOffice.git] / qadevOOo / tests / java / ifc / util / _XImportable.java
blob6a36526db9e6cb8d30e212d0220747963a542a1d
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 log.println("done");
59 log.print("Checking PropertyNames -- ");
60 locResult = checkPropertyNames(descriptor, names);
61 log.println("Worked: " + locResult);
62 res &= locResult;
64 log.print("Checking PropertyTypes -- ");
65 locResult = checkPropertyTypes(descriptor, types);
66 log.println("Worked: " + locResult);
67 res &= locResult;
69 descriptor = oObj.createImportDescriptor(false);
70 log.print("Getting when calling createImportDescriptor(false) -- ");
73 log.println("done");
75 log.print("Checking PropertyNames -- ");
76 locResult = checkPropertyNames(descriptor, names);
77 log.println("Worked: " + locResult);
78 res &= locResult;
80 log.print("Checking PropertyTypes -- ");
81 locResult = checkPropertyTypes(descriptor, types);
82 log.println("Worked - " + locResult);
83 res &= locResult;
85 tRes.tested("createImportDescriptor()", res);
88 public void _doImport() {
89 requiredMethod("createImportDescriptor()");
90 boolean res = true;
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";
96 log.println("done");
98 log.print("Importing data (Bibliograpy, Table, biblio) -- ");
99 oObj.doImport(descriptor);
100 log.println("done");
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";
109 log.println("done");
111 log.print("Importing data (Bibliograpy, SQL, select Author from biblio) -- ");
112 oObj.doImport(descriptor);
113 log.println("done");
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) {
129 boolean res = true;
131 for (int i = 0; i < props.length; i++) {
132 boolean locResult = props[i].Name.equals(names[i]);
134 if (!locResult) {
135 log.println("PropertyName differs for index " + i);
136 log.println("\tGetting: " + props[i].Name);
137 log.println("\tExpected: " + names[i]);
140 res &= locResult;
143 return res;
146 protected boolean checkPropertyTypes(PropertyValue[] props, Type[] types) {
147 boolean res = true;
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]);
153 if (!locResult) {
154 log.println("PropertyType differs for " + props[i].Name);
155 log.println("\tGetting: " + ValueType.getTypeName());
156 log.println("\tExpected: " + types[i].getTypeName());
159 res &= locResult;
162 return res;
165 protected boolean checkA1(String expected) {
166 XCellRange range = UnoRuntime.queryInterface(XCellRange.class, tEnv.getTestObject());
167 boolean res = false;
168 try{
169 String a1 = range.getCellByPosition(0,0).getFormula();
170 res = a1.equals(expected);
171 if (!res) {
172 log.println("\tResult differs from expectation");
173 log.println("\tGetting: "+a1);
174 log.println("\tExpected: "+expected);
175 } else {
176 log.println("successful");
178 } catch (com.sun.star.lang.IndexOutOfBoundsException e) {
179 log.println("Couldn't get Cell to check");
181 return res;
185 * Dispose environment.
187 @Override
188 protected void after() {
189 disposeEnvironment();