Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sanity/client/SwingSet/src/TreeDemoTest.java
41153 views
1
/*
2
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import com.sun.swingset3.demos.tree.TreeDemo;
25
import static com.sun.swingset3.demos.tree.TreeDemo.DEMO_TITLE;
26
27
import java.awt.Component;
28
import javax.swing.UIManager;
29
import javax.swing.tree.TreePath;
30
31
import org.jtregext.GuiTestListener;
32
33
import org.netbeans.jemmy.ClassReference;
34
import org.netbeans.jemmy.ComponentChooser;
35
import org.netbeans.jemmy.operators.JFrameOperator;
36
import org.netbeans.jemmy.operators.JTreeOperator;
37
38
import org.testng.annotations.Listeners;
39
import org.testng.annotations.Test;
40
import static org.testng.AssertJUnit.*;
41
42
/*
43
* @test
44
* @key headful
45
* @summary Verifies SwingSet3 TreeDemo by expanding all collapsed nodes in the
46
* tree and then collapsing all the expanded nodes in the tree. It
47
* verifies the number of nodes expanded, number of nodes collapsed and
48
* number of rows in the tree in the begininng, after expanding and
49
* after collapsing the nodes. It also checks that the tree grows
50
* vertically (as ScrollPane allows it).
51
*
52
* @library /sanity/client/lib/jemmy/src
53
* @library /sanity/client/lib/Extensions/src
54
* @library /sanity/client/lib/SwingSet3/src
55
* @modules java.desktop
56
* java.logging
57
* @build org.jemmy2ext.JemmyExt
58
* @build com.sun.swingset3.demos.tree.TreeDemo
59
* @run testng/timeout=600 TreeDemoTest
60
*/
61
@Listeners(GuiTestListener.class)
62
public class TreeDemoTest {
63
64
private static final int NODES_TO_EXPAND = 75;
65
private static final int NODES_TOTAL = 616;
66
67
private void waitRowCount(JTreeOperator tree, int count) {
68
tree.waitState(new ComponentChooser() {
69
public boolean checkComponent(Component comp) {
70
return tree.getRowCount() == count;
71
}
72
73
public String getDescription() {
74
return "A tree to have " + count + " rows";
75
}
76
});
77
}
78
79
@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)
80
public void test(String lookAndFeel) throws Exception {
81
UIManager.setLookAndFeel(lookAndFeel);
82
83
new ClassReference(TreeDemo.class.getCanonicalName()).startApplication();
84
85
JFrameOperator frame = new JFrameOperator(DEMO_TITLE);
86
87
JTreeOperator tree = new JTreeOperator(frame);
88
89
assertEquals("Initial number of rows in the tree", 4, tree.getRowCount());
90
91
int initialTreeHeight = tree.getHeight();
92
93
// expand all nodes
94
int expandsCount = 0;
95
for (int i = 0; i < tree.getRowCount(); i++) {
96
TreePath tp = tree.getPathForRow(i);
97
if (tree.getChildCount(tp) > 0 && !tree.isExpanded(tp)) {
98
tree.expandRow(i);
99
expandsCount++;
100
}
101
}
102
103
assertEquals("Number of rows expanded", NODES_TO_EXPAND, expandsCount);
104
waitRowCount(tree, NODES_TOTAL);
105
106
int expandedTreeHeight = tree.getHeight();
107
assertTrue("Expanded tree height has increased, current "
108
+ expandedTreeHeight + " > initial " + initialTreeHeight,
109
expandedTreeHeight > initialTreeHeight);
110
111
// collapse all nodes
112
int collapsesCount = 0;
113
for (int i = tree.getRowCount() - 1; i >= 0; i--) {
114
TreePath tp = tree.getPathForRow(i);
115
if (tree.getChildCount(tp) > 0 && tree.isExpanded(tp)) {
116
tree.collapseRow(i);
117
collapsesCount++;
118
}
119
}
120
121
assertEquals("Number of rows collapsed", NODES_TO_EXPAND + 1, collapsesCount);
122
waitRowCount(tree, 1);
123
124
int collapsedTreeHeight = tree.getHeight();
125
assertTrue("Collpased tree height is not longer than initial, "
126
+ "current " + collapsedTreeHeight + " <= initial "
127
+ initialTreeHeight,
128
collapsedTreeHeight <= initialTreeHeight);
129
130
}
131
132
}
133
134