aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/org/connectbot/SelectionAreaTest.java
blob: 93e0293b46ccfc2266b6734c7c3417940accd7d1 (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
/*
 * ConnectBot: simple, powerful, open-source SSH client for Android
 * Copyright 2007 Kenny Root, Jeffrey Sharkey
 *
 * Licensed 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
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.connectbot;

import org.connectbot.bean.SelectionArea;

import android.test.AndroidTestCase;

/**
 * @author Kenny Root
 * 
 */
public class SelectionAreaTest extends AndroidTestCase {
	private static final int WIDTH = 80;
	private static final int HEIGHT = 24;

	public void testCreate() {
		SelectionArea sa = new SelectionArea();

		assertTrue(sa.getLeft() == 0);
		assertTrue(sa.getRight() == 0);
		assertTrue(sa.getTop() == 0);
		assertTrue(sa.getBottom() == 0);
		assertTrue(sa.isSelectingOrigin());
	}

	public void testCheckMovement() {
		SelectionArea sa = new SelectionArea();

		sa.setBounds(WIDTH, HEIGHT);

		sa.incrementColumn();

		// Should be (1,0) to (1,0)
		assertTrue(sa.getLeft() == 1);
		assertTrue(sa.getTop() == 0);
		assertTrue(sa.getRight() == 1);
		assertTrue(sa.getBottom() == 0);

		sa.finishSelectingOrigin();
		assertFalse(sa.isSelectingOrigin());

		sa.incrementColumn();
		sa.incrementColumn();

		// Should be (1,0) to (3,0)
		assertTrue(sa.getLeft() == 1);
		assertTrue(sa.getTop() == 0);
		assertTrue(sa.getRight() == 3);
		assertTrue(sa.getBottom() == 0);
	}

	public void testBounds() {
		SelectionArea sa = new SelectionArea();

		sa.setBounds(WIDTH, HEIGHT);

		for (int i = 0; i <= WIDTH; i++)
			sa.decrementColumn();
		assertTrue("Left bound should be 0, but instead is " + sa.getLeft(),
				sa.getLeft() == 0);

		for (int i = 0; i <= HEIGHT; i++)
			sa.decrementRow();
		assertTrue("Top bound should be 0, but instead is " + sa.getLeft(),
				sa.getTop() == 0);

		sa.finishSelectingOrigin();

		for (int i = 0; i <= WIDTH * 2; i++)
			sa.incrementColumn();

		assertTrue("Left bound should be 0, but instead is " + sa.getLeft(),
				sa.getLeft() == 0);
		assertTrue("Right bound should be " + (WIDTH - 1) + ", but instead is " + sa.getRight(),
				sa.getRight() == (WIDTH - 1));

		for (int i = 0; i <= HEIGHT * 2; i++)
			sa.incrementRow();

		assertTrue("Bottom bound should be " + (HEIGHT - 1) + ", but instead is " + sa.getBottom(),
				sa.getBottom() == (HEIGHT - 1));
		assertTrue("Top bound should be 0, but instead is " + sa.getTop(),
				sa.getTop() == 0);
	}

	public void testSetThenMove() {
		SelectionArea sa = new SelectionArea();

		sa.setBounds(WIDTH, HEIGHT);

		int targetColumn = WIDTH / 2;
		int targetRow = HEIGHT / 2;

		sa.setColumn(targetColumn);
		sa.setRow(targetRow);

		sa.incrementRow();
		assertTrue("Row should be " + (targetRow + 1) + ", but instead is " + sa.getTop(),
				sa.getTop() == (targetRow + 1));

		sa.decrementColumn();
		assertTrue("Column shold be " + (targetColumn - 1) + ", but instead is " + sa.getLeft(), 
				sa.getLeft() == (targetColumn - 1));

		sa.finishSelectingOrigin();

		sa.setRow(0);
		sa.setColumn(0);

		sa.incrementRow();
		sa.decrementColumn();

		assertTrue("Top row should be 1, but instead is " + sa.getTop(),
				sa.getTop() == 1);

		assertTrue("Left column shold be 0, but instead is " + sa.getLeft(), 
				sa.getLeft() == 0);

		assertTrue("Bottom row should be " + (targetRow + 1) + ", but instead is " + sa.getBottom(),
				sa.getBottom() == (targetRow + 1));

		assertTrue("Right column shold be " + (targetColumn - 1) + ", but instead is " + sa.getRight(), 
				sa.getRight() == (targetColumn - 1));
	}
}