bump product version to 4.2.0.1
[LibreOffice.git] / qadevOOo / tests / java / ifc / document / _XViewDataSupplier.java
blob62a56e1d1a56b227df8459c6a3b4f1f15ddf77c5
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.document;
20 import com.sun.star.beans.PropertyValue;
21 import com.sun.star.container.XIndexAccess;
22 import com.sun.star.container.XIndexContainer;
23 import com.sun.star.document.XViewDataSupplier;
24 import com.sun.star.uno.UnoRuntime;
25 import lib.MultiMethodTest;
26 import lib.Status;
28 /**
29 * Check the XViewDataSupplier interface.
30 * Test idea: take the property values from the index access, change one
31 * property value, put this into the index access and write it back.
32 * Get the property value again and check that the change made it.
34 public class _XViewDataSupplier extends MultiMethodTest {
35 public XViewDataSupplier oObj = null;
36 XIndexAccess xAccess = null;
37 PropertyValue[] newProps = null;
38 PropertyValue[] oldProps = null;
39 String myview = "myview1";
41 public void _getViewData() {
42 xAccess = oObj.getViewData();
43 // util.dbg.printInterfaces(xAccess);
44 if (xAccess != null) {
45 setViewID(xAccess, myview);
47 tRes.tested("getViewData()", true);
50 public void _setViewData() {
51 if (xAccess == null) {
52 log.println("No view data to change available");
53 tRes.tested("setViewData()", Status.skipped(true));
55 else {
56 // 2do: provide an own implementation of the XIndexAccess to set.
57 // this will work without "setViewData()", it just checks that a
58 // setViewData can be done.
59 oObj.setViewData(xAccess);
60 XIndexAccess xAccess2 = oObj.getViewData();
61 String newView = getViewID(xAccess2);
62 tRes.tested("setViewData()", newView.equals(myview));
66 private void setViewID(XIndexAccess xAccess, String value) {
67 XIndexContainer xIndexContainer = UnoRuntime.queryInterface(XIndexContainer.class, xAccess);
68 int count = xAccess.getCount();
69 try {
70 if (count > 0) {
71 oldProps = (PropertyValue[])xAccess.getByIndex(0);
72 newProps = new PropertyValue[oldProps.length];
73 for (int j=0; j<oldProps.length; j++) {
74 // log.println("Name: " + oldProps[j].Name);
75 // log.println("Value: " + oldProps[j].Value.toString());
76 newProps[j] = new PropertyValue();
77 newProps[j].Name = oldProps[j].Name;
78 newProps[j].Handle = oldProps[j].Handle;
79 newProps[j].State = oldProps[j].State;
80 if (oldProps[j].Name.equals("ViewId")) {
81 newProps[j].Value = value;
85 xIndexContainer.insertByIndex(0, newProps);
88 catch(Exception e) {
89 e.printStackTrace(log);
93 private String getViewID(XIndexAccess xAccess) {
94 String retValue = null;
95 int count = xAccess.getCount();
96 try {
97 if (count > 0) {
98 oldProps = (PropertyValue[])xAccess.getByIndex(0);
99 for (int j=0; j<oldProps.length; j++) {
100 // log.println("Name: " + oldProps[j].Name);
101 // log.println("Value: " + oldProps[j].Value.toString());
102 if (oldProps[j].Name.equals("ViewId")) {
103 retValue = (String)newProps[j].Value;
109 catch(Exception e) {
110 e.printStackTrace(log);
112 return retValue;