Crossfire JXClient, Trunk  R20561
OrientationTest.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.gui.gauge;
23 
24 import org.jetbrains.annotations.NotNull;
25 import org.junit.Assert;
26 import org.junit.Test;
27 
33 public class OrientationTest {
34 
40  @Test
41  public void testOrientations() throws IllegalAccessException, InstantiationException {
42  check(OrientationWE.class, true, false);
43  check(OrientationEW.class, true, true);
44  check(OrientationNS.class, false, false);
45  check(OrientationSN.class, false, true);
46  }
47 
56  private static void check(@NotNull final Class<? extends Orientation> class_, final boolean useX, final boolean flip) throws IllegalAccessException, InstantiationException {
57  checkPositive(class_, useX, flip);
58  checkNegative(class_, useX, flip);
59  }
60 
70  private static void checkPositive(@NotNull final Class<? extends Orientation> class_, final boolean useX, final boolean flip) throws IllegalAccessException, InstantiationException {
71  final Orientation o = class_.newInstance();
72  o.setHasNegativeImage(false);
73  o.setExtends(useX ? 100 : 32, useX ? 32 : 100);
74  check(o, useX, flip, false, 0, 0, 0, 32, false);
75 
76  // 0%
77  o.setValues(50, 50, 90);
78  check(o, useX, flip, true, 0, 0, 0, 32, false);
79 
80  // 25%
81  o.setValues(60, 50, 90);
82  check(o, useX, flip, true, 0, 0, 25, 32, false);
83 
84  // 100%
85  o.setValues(90, 50, 90);
86  check(o, useX, flip, true, 0, 0, 100, 32, false);
87 
88  // 150%
89  o.setValues(110, 50, 90);
90  check(o, useX, flip, true, 0, 0, 100, 32, false);
91 
92  // -50%
93  o.setValues(30, 50, 90);
94  check(o, useX, flip, true, 0, 0, 0, 32, false);
95 
96  // -150%
97  o.setValues(-10, 50, 90);
98  check(o, useX, flip, true, 0, 0, 0, 32, false);
99  }
100 
110  private static void checkNegative(@NotNull final Class<? extends Orientation> class_, final boolean useX, final boolean flip) throws IllegalAccessException, InstantiationException {
111  final Orientation o = class_.newInstance();
112  o.setHasNegativeImage(true);
113  o.setExtends(useX ? 100 : 32, useX ? 32 : 100);
114  check(o, useX, flip, false, 0, 0, 0, 32, false);
115 
116  // 0%
117  o.setValues(50, 50, 90);
118  check(o, useX, flip, true, 0, 0, 0, 32, false);
119 
120  // 25%
121  o.setValues(60, 50, 90);
122  check(o, useX, flip, true, 0, 0, 25, 32, false);
123 
124  // 100%
125  o.setValues(90, 50, 90);
126  check(o, useX, flip, true, 0, 0, 100, 32, false);
127 
128  // 150%
129  o.setValues(110, 50, 90);
130  check(o, useX, flip, true, 0, 0, 100, 32, false);
131 
132  // -50%
133  o.setValues(30, 50, 90);
134  check(o, useX, flip, true, 0, 0, 50, 32, true);
135 
136  // -150%
137  o.setValues(-10, 50, 90);
138  check(o, useX, flip, true, 0, 0, 100, 32, true);
139  }
140 
153  private static void check(@NotNull final Orientation o, final boolean useX, final boolean flip, final boolean valid, final int x, final int y, final int w, final int h, final boolean negativeImage) {
154  final int isX = useX ? o.getX() : o.getY();
155  final int isY = useX ? o.getY() : o.getX();
156  final int isW = useX ? o.getW() : o.getH();
157  final int isH = useX ? o.getH() : o.getW();
158  Assert.assertEquals(valid, o.isValid());
159  Assert.assertEquals(flip ? 100-x-w : x, isX);
160  Assert.assertEquals(y, isY);
161  Assert.assertEquals(w, isW);
162  Assert.assertEquals(h, isH);
163  Assert.assertEquals(negativeImage, o.isNegativeImage());
164  }
165 
166 }
Regression tests for class Orientation and implementing classes.
static void checkNegative(@NotNull final Class<? extends Orientation > class_, final boolean useX, final boolean flip)
Checks that negative values are correctly handled by an Orientation instance.
Implements an Orientation which grows west to east.
Implements an Orientation which grows north to south.
static void check(@NotNull final Orientation o, final boolean useX, final boolean flip, final boolean valid, final int x, final int y, final int w, final int h, final boolean negativeImage)
Checks that a value is correctly handled.
boolean setValues(int cur, int min, int max)
Sets the gauge&#39;s values.
static void check(@NotNull final Class<? extends Orientation > class_, final boolean useX, final boolean flip)
Checks an Orientation instance.
void setHasNegativeImage(boolean hasNegativeImage)
Sets whether the gauge can display negative images.
boolean setExtends(int width, int height)
Sets the extends of the image.
static void checkPositive(@NotNull final Class<? extends Orientation > class_, final boolean useX, final boolean flip)
Checks that positive values are correctly handled by an Orientation instance.
void testOrientations()
Checks that Orientation instances work correctly.
Implements an Orientation which grows south to north.
Implements an Orientation which grows east to west.