comparison tests/src/com/five_ten_sg/connectbot/SelectionAreaTest.java @ 0:0ce5cc452d02

initial version
author Carl Byington <carl@five-ten-sg.com>
date Thu, 22 May 2014 10:41:19 -0700
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0ce5cc452d02
1 /*
2 * ConnectBot: simple, powerful, open-source SSH client for Android
3 * Copyright 2007 Kenny Root, Jeffrey Sharkey
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package com.five_ten_sg.connectbot;
19
20 import com.five_ten_sg.connectbot.bean.SelectionArea;
21
22 import android.test.AndroidTestCase;
23
24 /**
25 * @author Kenny Root
26 *
27 */
28 public class SelectionAreaTest extends AndroidTestCase {
29 private static final int WIDTH = 80;
30 private static final int HEIGHT = 24;
31
32 public void testCreate() {
33 SelectionArea sa = new SelectionArea();
34 assertTrue(sa.getLeft() == 0);
35 assertTrue(sa.getRight() == 0);
36 assertTrue(sa.getTop() == 0);
37 assertTrue(sa.getBottom() == 0);
38 assertTrue(sa.isSelectingOrigin());
39 }
40
41 public void testCheckMovement() {
42 SelectionArea sa = new SelectionArea();
43 sa.setBounds(WIDTH, HEIGHT);
44 sa.incrementColumn();
45 // Should be (1,0) to (1,0)
46 assertTrue(sa.getLeft() == 1);
47 assertTrue(sa.getTop() == 0);
48 assertTrue(sa.getRight() == 1);
49 assertTrue(sa.getBottom() == 0);
50 sa.finishSelectingOrigin();
51 assertFalse(sa.isSelectingOrigin());
52 sa.incrementColumn();
53 sa.incrementColumn();
54 // Should be (1,0) to (3,0)
55 assertTrue(sa.getLeft() == 1);
56 assertTrue(sa.getTop() == 0);
57 assertTrue(sa.getRight() == 3);
58 assertTrue(sa.getBottom() == 0);
59 }
60
61 public void testBounds() {
62 SelectionArea sa = new SelectionArea();
63 sa.setBounds(WIDTH, HEIGHT);
64
65 for (int i = 0; i <= WIDTH; i++)
66 sa.decrementColumn();
67
68 assertTrue("Left bound should be 0, but instead is " + sa.getLeft(),
69 sa.getLeft() == 0);
70
71 for (int i = 0; i <= HEIGHT; i++)
72 sa.decrementRow();
73
74 assertTrue("Top bound should be 0, but instead is " + sa.getLeft(),
75 sa.getTop() == 0);
76 sa.finishSelectingOrigin();
77
78 for (int i = 0; i <= WIDTH * 2; i++)
79 sa.incrementColumn();
80
81 assertTrue("Left bound should be 0, but instead is " + sa.getLeft(),
82 sa.getLeft() == 0);
83 assertTrue("Right bound should be " + (WIDTH - 1) + ", but instead is " + sa.getRight(),
84 sa.getRight() == (WIDTH - 1));
85
86 for (int i = 0; i <= HEIGHT * 2; i++)
87 sa.incrementRow();
88
89 assertTrue("Bottom bound should be " + (HEIGHT - 1) + ", but instead is " + sa.getBottom(),
90 sa.getBottom() == (HEIGHT - 1));
91 assertTrue("Top bound should be 0, but instead is " + sa.getTop(),
92 sa.getTop() == 0);
93 }
94
95 public void testSetThenMove() {
96 SelectionArea sa = new SelectionArea();
97 sa.setBounds(WIDTH, HEIGHT);
98 int targetColumn = WIDTH / 2;
99 int targetRow = HEIGHT / 2;
100 sa.setColumn(targetColumn);
101 sa.setRow(targetRow);
102 sa.incrementRow();
103 assertTrue("Row should be " + (targetRow + 1) + ", but instead is " + sa.getTop(),
104 sa.getTop() == (targetRow + 1));
105 sa.decrementColumn();
106 assertTrue("Column shold be " + (targetColumn - 1) + ", but instead is " + sa.getLeft(),
107 sa.getLeft() == (targetColumn - 1));
108 sa.finishSelectingOrigin();
109 sa.setRow(0);
110 sa.setColumn(0);
111 sa.incrementRow();
112 sa.decrementColumn();
113 assertTrue("Top row should be 1, but instead is " + sa.getTop(),
114 sa.getTop() == 1);
115 assertTrue("Left column shold be 0, but instead is " + sa.getLeft(),
116 sa.getLeft() == 0);
117 assertTrue("Bottom row should be " + (targetRow + 1) + ", but instead is " + sa.getBottom(),
118 sa.getBottom() == (targetRow + 1));
119 assertTrue("Right column shold be " + (targetColumn - 1) + ", but instead is " + sa.getRight(),
120 sa.getRight() == (targetColumn - 1));
121 }
122 }