summaryrefslogtreecommitdiff
path: root/qadevOOo/tests/java/ifc/awt/tree/_XTreeNode.java
blob: 53f8f8c0303827b1312a3009790c57be3d9919d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

package ifc.awt.tree;

import com.sun.star.awt.tree.XTreeNode;
import com.sun.star.uno.AnyConverter;
import lib.MultiMethodTest;
import lib.Status;
import lib.StatusException;

/**
 * Testing <code>com.sun.star.awt.tree.XTreeDataModel</code>
 * interface methods :
 * <ul>
 *  <li><code> getChildAt()</code></li>
 *  <li><code> getChildCount()</code></li>
 *  <li><code> getParent()</code></li>
 *  <li><code> getIndex()</code></li>
 *  <li><code> hasChildrenOnDemand()</code></li>
 *  <li><code> getDisplayValue()</code></li>
 *  <li><code> getNodeGraphicURL()</code></li>
 *  <li><code> getExpandedGraphicURL()</code></li>
 *  <li><code> getCollapsedGraphicURL()</code></li> * </ul> <p>
 * Test is <b> NOT </b> multithread compliant. <p>
 *
 * @see com.sun.star.awt.tree.XTreeDataModel
 */
public class _XTreeNode extends MultiMethodTest {

    public XTreeNode oObj = null;

    private int mCount = 0;

    String msDisplayValue = null;
    String msExpandedGraphicURL = null;
    String msCollapsedGraphicURL = null;
    String msNodeGraphicURL = null;


    @Override
    public void before(){
        msDisplayValue = (String) tEnv.getObjRelation("XTreeNode_DisplayValue");
        if (msDisplayValue == null){
            throw new StatusException(Status.failed(
                "Couldn't get relation 'XTreeNode_DisplayValue'"));
        }

        msExpandedGraphicURL = (String) tEnv.getObjRelation("XTreeNode_ExpandedGraphicURL");
        if (msExpandedGraphicURL == null){
            throw new StatusException(Status.failed(
                "Couldn't get relation 'XTreeNode_ExpandedGraphicURL'"));
        }

        msCollapsedGraphicURL = (String) tEnv.getObjRelation("XTreeNode_CollapsedGraphicURL");
        if (msCollapsedGraphicURL == null){
            throw new StatusException(Status.failed(
                "Couldn't get relation 'XTreeNode_CollapsedGraphicURL'"));
        }

        msNodeGraphicURL = (String) tEnv.getObjRelation("XTreeNode_NodeGraphicURL");
        if(msNodeGraphicURL == null){
            throw new StatusException(Status.failed(
                "Couldn't get relation 'XTreeNode_NodeGraphicURL'"));
        }

    }

    /**
     * Gets the title and compares it to the value set in
     * <code>setTitle</code> method test. <p>
     * Has <b>OK</b> status is set/get values are equal.
     * The following method tests are to be completed successfully before :
     * <ul>
     *  <li> <code> setTitle </code>  </li>
     * </ul>
     */
    public void _getChildAt(){
        this.requiredMethod("getChildCount()");
        boolean bOK = true;

        for (int i=0; i < mCount ; i++){
            XTreeNode xNode = null;
            try {
                xNode = oObj.getChildAt(i);
            } catch (com.sun.star.lang.IndexOutOfBoundsException ex) {
                log.println("ERROR: getChildAt(" + i + "): " + ex.toString());
            }
            if (xNode == null){
                log.println("ERROR: getChildAt(" + i + ") returns null => FAILED");
                bOK = false;
            }
        }

        tRes.tested("getChildAt()", bOK);
    }


    public void _getChildCount(){

        boolean bOK = true;
        mCount = oObj.getChildCount();
        log.println("got count '" + mCount + "' of children");
        if (mCount < 1 ) {
            log.println("ERROR: got a count < 1. The test object must support more than zero children => FAILED");
            bOK = false;
        }
        tRes.tested("getChildCount()", bOK);
    }


    public void _getParent(){
        this.requiredMethod("getChildAt()");

        boolean bOK = true;
        XTreeNode xNode = null;
        try {
            log.println("try to getChildAt(0)");
            xNode = oObj.getChildAt(0);
        } catch (com.sun.star.lang.IndexOutOfBoundsException ex) {
            log.println("ERROR: getChildAt(0): " + ex.toString());
        }

        log.println("try to get parent of children");
        if (xNode == null) {
            log.println("missing xNode");
            tRes.tested("getParent()", false);
        }
        else {
            XTreeNode xParrent = xNode.getParent();


            bOK = oObj.equals(xParrent);
            log.println("original object and parent should be the same: " + bOK);
            tRes.tested("getParent()", bOK);
        }
    }


    public void _getIndex(){
        this.requiredMethod("getChildAt()");

        boolean bOK = true;
        XTreeNode xNode = null;
        try {
            log.println("try to getChildAt(0)");
            xNode = oObj.getChildAt(0);
        } catch (com.sun.star.lang.IndexOutOfBoundsException ex) {
            log.println("ERROR: getChildAt(0): " + ex.toString());
        }

        log.println("try to get index from child...");
        int index = oObj.getIndex(xNode);

        if (index != 0){
            log.println("ERROR: getIndex() does not return '0' => FAILED");
            bOK = false;
        }

        tRes.tested("getIndex()", bOK);
    }


    public void _hasChildrenOnDemand(){

        boolean bOK = true;

        bOK = oObj.hasChildrenOnDemand();
        tRes.tested("hasChildrenOnDemand()", bOK);
    }


    public void _getDisplayValue(){

        boolean bOK = true;
        String DisplayValue = null;
        Object dispVal = oObj.getDisplayValue();

        try {
            DisplayValue = AnyConverter.toString(dispVal);
        } catch (com.sun.star.lang.IllegalArgumentException ex) {
            log.println("ERROR: could not convert the returned object of 'getDisplyValue()' " +
                "to String with AnyConverter: " + ex.toString());
        }

        if ( ! this.msDisplayValue.equals(DisplayValue)){
            log.println("ERROR: getNodeGraphicURL() does not return expected value:\n" +
                "\tExpected: " + this.msDisplayValue +"\n" +
                "\tGot: " + DisplayValue);
            bOK = false;
        }

        tRes.tested("getDisplayValue()", bOK);
    }


    public void _getNodeGraphicURL(){

        boolean bOK = true;
        String graphicURL = oObj.getNodeGraphicURL();

        if ( ! this.msNodeGraphicURL.equals(graphicURL)){
            log.println("ERROR: getNodeGraphicURL() does not return expected value:\n" +
                "\tExpected: " + this.msNodeGraphicURL +"\n" +
                "\tGot: " + graphicURL);
            bOK = false;
        }
        tRes.tested("getNodeGraphicURL()", bOK);
    }


    public void _getExpandedGraphicURL(){

        boolean bOK = true;
        String ExpandedGraphicURL = oObj.getExpandedGraphicURL();

        if ( ! this.msExpandedGraphicURL.equals(ExpandedGraphicURL)){
            log.println("ERROR: getExpandedGraphicURL() does not return expected value:\n" +
                "\tExpected: " + this.msExpandedGraphicURL +"\n" +
                "\tGot: " + ExpandedGraphicURL);
            bOK = false;
        }

        tRes.tested("getExpandedGraphicURL()", bOK);
    }


    public void _getCollapsedGraphicURL(){

        boolean bOK = true;

        String CollapsedGraphicURL = oObj.getCollapsedGraphicURL();

        if ( ! this.msCollapsedGraphicURL.equals(CollapsedGraphicURL)){
            log.println("ERROR: getExpandedGraphicURL() does not return expected value:\n" +
                "\tExpected: " + this.msCollapsedGraphicURL +"\n" +
                "\tGot: " + CollapsedGraphicURL);
            bOK = false;
        }

        tRes.tested("getCollapsedGraphicURL()", bOK);
    }

}