Update ooo320-m1
[ooovba.git] / qadevOOo / tests / java / ifc / document / _XViewDataSupplier.java
blob9b9c967dc36e93cc59834c8f3ffe55ba7b323e83
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: _XViewDataSupplier.java,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 package ifc.document;
32 import com.sun.star.beans.PropertyValue;
33 import com.sun.star.container.XIndexAccess;
34 import com.sun.star.container.XIndexContainer;
35 import com.sun.star.document.XViewDataSupplier;
36 import com.sun.star.uno.UnoRuntime;
37 import lib.MultiMethodTest;
38 import lib.Status;
40 /**
41 * Check the XViewDataSupplier interface.
42 * Test idea: take the property values from the index access, change one
43 * property value, put this into the index access and write it back.
44 * Get the property value again and check that the change made it.
46 public class _XViewDataSupplier extends MultiMethodTest {
47 public XViewDataSupplier oObj = null;
48 XIndexAccess xAccess = null;
49 PropertyValue[] newProps = null;
50 PropertyValue[] oldProps = null;
51 String myview = "myview1";
53 public void _getViewData() {
54 xAccess = oObj.getViewData();
55 // util.dbg.printInterfaces(xAccess);
56 if (xAccess != null) {
57 setViewID(xAccess, myview);
59 tRes.tested("getViewData()", true);
62 public void _setViewData() {
63 if (xAccess == null) {
64 log.println("No view data to change available");
65 tRes.tested("setViewData()", Status.skipped(true));
67 else {
68 // 2do: provide an own implementation of the XIndexAccess to set.
69 // this will work without "setViewData()", it just checks that a
70 // setViewData can be done.
71 oObj.setViewData(xAccess);
72 XIndexAccess xAccess2 = oObj.getViewData();
73 String newView = getViewID(xAccess2);
74 tRes.tested("setViewData()", newView.equals(myview));
78 private void setViewID(XIndexAccess xAccess, String value) {
79 XIndexContainer xIndexContainer = (XIndexContainer)UnoRuntime.queryInterface(XIndexContainer.class, xAccess);
80 int count = xAccess.getCount();
81 try {
82 if (count > 0) {
83 oldProps = (PropertyValue[])xAccess.getByIndex(0);
84 newProps = new PropertyValue[oldProps.length];
85 for (int j=0; j<oldProps.length; j++) {
86 // log.println("Name: " + oldProps[j].Name);
87 // log.println("Value: " + oldProps[j].Value.toString());
88 newProps[j] = new PropertyValue();
89 newProps[j].Name = oldProps[j].Name;
90 newProps[j].Handle = oldProps[j].Handle;
91 newProps[j].State = oldProps[j].State;
92 if (oldProps[j].Name.equals("ViewId")) {
93 newProps[j].Value = value;
97 xIndexContainer.insertByIndex(0, newProps);
100 catch(Exception e) {
101 e.printStackTrace((java.io.PrintWriter)log);
105 private String getViewID(XIndexAccess xAccess) {
106 String retValue = null;
107 int count = xAccess.getCount();
108 try {
109 if (count > 0) {
110 oldProps = (PropertyValue[])xAccess.getByIndex(0);
111 for (int j=0; j<oldProps.length; j++) {
112 // log.println("Name: " + oldProps[j].Name);
113 // log.println("Value: " + oldProps[j].Value.toString());
114 if (oldProps[j].Name.equals("ViewId")) {
115 retValue = (String)newProps[j].Value;
121 catch(Exception e) {
122 e.printStackTrace((java.io.PrintWriter)log);
124 return retValue;