Crossfire JXClient, Trunk
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-2017,2019-2023 Andreas Kirschbaum
20  * Copyright (C) 2010-2012,2014-2018,2020-2023 Nicolas Weeger
21  */
22 
23 package com.realtime.crossfire.jxclient.gui.gauge;
24 
25 import java.lang.reflect.InvocationTargetException;
26 import org.jetbrains.annotations.NotNull;
27 import org.junit.Assert;
28 import org.junit.Test;
29 
34 public class OrientationTest {
35 
40  @Test
41  public void testOrientations() throws Exception {
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 
58  private static void check(@NotNull final Class<? extends Orientation> class_, final boolean useX, final boolean flip) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
59  checkPositive(class_, useX, flip);
60  checkNegative(class_, useX, flip);
61  }
62 
74  private static void checkPositive(@NotNull final Class<? extends Orientation> class_, final boolean useX, final boolean flip) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
75  final Orientation o = class_.getConstructor().newInstance();
76  o.setHasNegativeImage(false);
77  o.setExtends(useX ? 100 : 32, useX ? 32 : 100);
78  check(o, useX, flip, false, 0, 0, 0, 32, false);
79 
80  // 0%
81  o.setValues(50, 50, 90);
82  check(o, useX, flip, true, 0, 0, 0, 32, false);
83 
84  // 25%
85  o.setValues(60, 50, 90);
86  check(o, useX, flip, true, 0, 0, 25, 32, false);
87 
88  // 100%
89  o.setValues(90, 50, 90);
90  check(o, useX, flip, true, 0, 0, 100, 32, false);
91 
92  // 150%
93  o.setValues(110, 50, 90);
94  check(o, useX, flip, true, 0, 0, 100, 32, false);
95 
96  // -50%
97  o.setValues(30, 50, 90);
98  check(o, useX, flip, true, 0, 0, 0, 32, false);
99 
100  // -150%
101  o.setValues(-10, 50, 90);
102  check(o, useX, flip, true, 0, 0, 0, 32, false);
103  }
104 
116  private static void checkNegative(@NotNull final Class<? extends Orientation> class_, final boolean useX, final boolean flip) throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
117  final Orientation o = class_.getConstructor().newInstance();
118  o.setHasNegativeImage(true);
119  o.setExtends(useX ? 100 : 32, useX ? 32 : 100);
120  check(o, useX, flip, false, 0, 0, 0, 32, false);
121 
122  // 0%
123  o.setValues(50, 50, 90);
124  check(o, useX, flip, true, 0, 0, 0, 32, false);
125 
126  // 25%
127  o.setValues(60, 50, 90);
128  check(o, useX, flip, true, 0, 0, 25, 32, false);
129 
130  // 100%
131  o.setValues(90, 50, 90);
132  check(o, useX, flip, true, 0, 0, 100, 32, false);
133 
134  // 150%
135  o.setValues(110, 50, 90);
136  check(o, useX, flip, true, 0, 0, 100, 32, false);
137 
138  // -50%
139  o.setValues(30, 50, 90);
140  check(o, useX, flip, true, 0, 0, 50, 32, true);
141 
142  // -150%
143  o.setValues(-10, 50, 90);
144  check(o, useX, flip, true, 0, 0, 100, 32, true);
145  }
146 
159  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) {
160  final int isX = useX ? o.getX() : o.getY();
161  final int isY = useX ? o.getY() : o.getX();
162  final int isW = useX ? o.getW() : o.getH();
163  final int isH = useX ? o.getH() : o.getW();
164  Assert.assertEquals(valid, o.isValid());
165  Assert.assertEquals(flip ? 100-x-w : x, isX);
166  Assert.assertEquals(y, isY);
167  Assert.assertEquals(w, isW);
168  Assert.assertEquals(h, isH);
169  Assert.assertEquals(negativeImage, o.isNegativeImage());
170  }
171 
172 }
com.realtime.crossfire.jxclient.gui.gauge.OrientationSN
Definition: OrientationSN.java:29
com.realtime.crossfire.jxclient.gui.gauge.OrientationEW
Definition: OrientationEW.java:29
com.realtime.crossfire.jxclient.gui.gauge.Orientation.setExtends
boolean setExtends(int width, int height)
com.realtime.crossfire.jxclient.gui.gauge.OrientationTest.testOrientations
void testOrientations()
Definition: OrientationTest.java:41
com.realtime.crossfire.jxclient.gui.gauge.OrientationTest.check
static void check(@NotNull final Class<? extends Orientation > class_, final boolean useX, final boolean flip)
Definition: OrientationTest.java:58
com.realtime.crossfire.jxclient.gui.gauge.OrientationTest
Definition: OrientationTest.java:34
com.realtime.crossfire.jxclient.gui.gauge.Orientation.setHasNegativeImage
void setHasNegativeImage(boolean hasNegativeImage)
com.realtime.crossfire.jxclient.gui.gauge.Orientation.setValues
boolean setValues(int cur, int min, int max)
com.realtime.crossfire.jxclient.gui.gauge.OrientationTest.checkPositive
static void checkPositive(@NotNull final Class<? extends Orientation > class_, final boolean useX, final boolean flip)
Definition: OrientationTest.java:74
com.realtime.crossfire.jxclient.gui.gauge.Orientation
Definition: Orientation.java:29
com.realtime.crossfire.jxclient.gui.gauge.OrientationTest.checkNegative
static void checkNegative(@NotNull final Class<? extends Orientation > class_, final boolean useX, final boolean flip)
Definition: OrientationTest.java:116
com.realtime.crossfire.jxclient.gui.gauge.OrientationNS
Definition: OrientationNS.java:29
com.realtime.crossfire.jxclient.gui.gauge.OrientationTest.check
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)
Definition: OrientationTest.java:159
com.realtime.crossfire.jxclient.gui.gauge.OrientationWE
Definition: OrientationWE.java:29