Crossfire JXClient, Trunk
RenderStateTest.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.log;
24 
26 import java.awt.Color;
27 import org.junit.Assert;
28 import org.junit.Test;
29 
34 @SuppressWarnings("JavaDoc")
35 public class RenderStateTest {
36 
40  public static final int MAX_LINES = 1000;
41 
45  @Test
46  public void test1() {
47  final RenderStateTestRec rec = new RenderStateTestRec(MAX_LINES);
48  final Parser parser = new Parser(Color.BLACK);
49 
50  for (int i = 0; i < RenderStateTestRec.HEIGHT+10; i++) {
51  parser.parse("xxx"+i, MessageType.MSG_TYPE_BOOK, MessageType.MSG_SUBTYPE_BOOK_CLASP_1, Color.BLACK, rec.getBuffer());
52  }
53  rec.checkState(110, 0);
54 
55  // scroll to valid positions
56  rec.scrollTo(0);
57  rec.checkState(0, 0);
59  rec.checkState(5, 3);
61  rec.checkState(10, 0);
62 
63  // scroll to invalid positions
64  rec.scrollTo(-1);
65  rec.checkState(0, 0);
66  rec.scrollTo(-10);
67  rec.checkState(0, 0);
68 
69  // scroll to invalid positions
73  rec.checkState(110, 0);
74  }
75 
79  @Test
80  public void test2() {
81  final RenderStateTestRec rec = new RenderStateTestRec(MAX_LINES);
82  final Parser parser = new Parser(Color.BLACK);
83 
85 
86  rec.checkState(0, 0);
87  parser.parse("xxx1", MessageType.MSG_TYPE_BOOK, MessageType.MSG_SUBTYPE_BOOK_CLASP_1, Color.BLACK, rec.getBuffer());
88  rec.checkState(0, 0);
89  parser.parse("xxx2", MessageType.MSG_TYPE_BOOK, MessageType.MSG_SUBTYPE_BOOK_CLASP_1, Color.BLACK, rec.getBuffer());
90  rec.checkState(0, 0);
91 
92  // add lines to completely fill visible area
93  for (int i = 2; i < RenderStateTestRec.HEIGHT/RenderStateTestRec.FONT_HEIGHT; i++) {
94  parser.parse("xxx3"+i, MessageType.MSG_TYPE_BOOK, MessageType.MSG_SUBTYPE_BOOK_CLASP_1, Color.BLACK, rec.getBuffer());
95  }
96  rec.checkState(0, 0);
97 
98  // add one more line ==> buffer sticks at bottom
99  parser.parse("xxx4", MessageType.MSG_TYPE_BOOK, MessageType.MSG_SUBTYPE_BOOK_CLASP_1, Color.BLACK, rec.getBuffer());
100  rec.checkState(1, 0);
101 
102  // add one more line ==> buffer sticks at bottom
103  parser.parse("xxx5", MessageType.MSG_TYPE_BOOK, MessageType.MSG_SUBTYPE_BOOK_CLASP_1, Color.BLACK, rec.getBuffer());
104  rec.checkState(2, 0);
105 
106  // scroll up one line
108  rec.checkState(1, 0);
109 
110  // add one more line ==> buffer sticks at scroll position
111  parser.parse("xxx6", MessageType.MSG_TYPE_BOOK, MessageType.MSG_SUBTYPE_BOOK_CLASP_1, Color.BLACK, rec.getBuffer());
112  rec.checkState(1, 0);
113 
114  // scroll back to bottom
116  rec.checkState(3, 0);
117 
118  // add one more line ==> buffer sticks at bottom
119  parser.parse("xxx7", MessageType.MSG_TYPE_BOOK, MessageType.MSG_SUBTYPE_BOOK_CLASP_1, Color.BLACK, rec.getBuffer());
120  rec.checkState(4, 0);
121 
122  // completely fill buffer
123  for (int i = RenderStateTestRec.HEIGHT/RenderStateTestRec.FONT_HEIGHT+4; i < MAX_LINES; i++) {
124  parser.parse("xxx8"+i, MessageType.MSG_TYPE_BOOK, MessageType.MSG_SUBTYPE_BOOK_CLASP_1, Color.BLACK, rec.getBuffer());
125  }
127 
128  // add one more line ==> buffer sticks at bottom
129  parser.parse("xxx9", MessageType.MSG_TYPE_BOOK, MessageType.MSG_SUBTYPE_BOOK_CLASP_1, Color.BLACK, rec.getBuffer());
131 
132  // scroll one line up
135 
136  // fill more lines ==> scroll position sticks
137  for (int i = 0; i < MAX_LINES-RenderStateTestRec.HEIGHT/RenderStateTestRec.FONT_HEIGHT-2; i++) {
138  parser.parse("xxx0"+i, MessageType.MSG_TYPE_BOOK, MessageType.MSG_SUBTYPE_BOOK_CLASP_1, Color.BLACK, rec.getBuffer());
139  }
140  rec.checkState(1, 0);
141  parser.parse("xxx1", MessageType.MSG_TYPE_BOOK, MessageType.MSG_SUBTYPE_BOOK_CLASP_1, Color.BLACK, rec.getBuffer());
142  rec.checkState(0, 0);
143 
144  // add one more line ==> scroll position hits top
145  parser.parse("xxx2", MessageType.MSG_TYPE_BOOK, MessageType.MSG_SUBTYPE_BOOK_CLASP_1, Color.BLACK, rec.getBuffer());
146  rec.checkState(0, 0);
147  }
148 
149  @Test
150  public void coordinateToPosition() {
151  final RenderStateTestRec rec = new RenderStateTestRec(MAX_LINES);
152 
153  Assert.assertEquals(0, rec.getBuffer().coordinateToPosition(0, 0));
154  Assert.assertEquals(0, rec.getBuffer().coordinateToPosition(100, 0));
155  Assert.assertEquals(0, rec.getBuffer().coordinateToPosition(0, 100));
156  Assert.assertEquals(0, rec.getBuffer().coordinateToPosition(100, 100));
157 
158  final Parser parser = new Parser(Color.BLACK);
159  parser.parse("xxx1", MessageType.MSG_TYPE_BOOK, MessageType.MSG_SUBTYPE_BOOK_CLASP_1, Color.BLACK, rec.getBuffer());
160 
161  Assert.assertEquals(0, rec.getBuffer().coordinateToPosition(0, 0));
162  Assert.assertEquals(0, rec.getBuffer().coordinateToPosition(1, 0));
163  Assert.assertEquals(0, rec.getBuffer().coordinateToPosition(2, 0));
164  Assert.assertEquals(0, rec.getBuffer().coordinateToPosition(3, 0));
165  Assert.assertEquals(0, rec.getBuffer().coordinateToPosition(4, 0));
166  Assert.assertEquals(1, rec.getBuffer().coordinateToPosition(5, 0));
167  Assert.assertEquals(1, rec.getBuffer().coordinateToPosition(6, 0));
168  Assert.assertEquals(1, rec.getBuffer().coordinateToPosition(7, 0));
169  Assert.assertEquals(1, rec.getBuffer().coordinateToPosition(8, 0));
170  Assert.assertEquals(1, rec.getBuffer().coordinateToPosition(9, 0));
171  Assert.assertEquals(2, rec.getBuffer().coordinateToPosition(10, 0));
172  Assert.assertEquals(2, rec.getBuffer().coordinateToPosition(11, 0));
173  Assert.assertEquals(2, rec.getBuffer().coordinateToPosition(12, 0));
174  Assert.assertEquals(2, rec.getBuffer().coordinateToPosition(13, 0));
175  Assert.assertEquals(2, rec.getBuffer().coordinateToPosition(14, 0));
176  Assert.assertEquals(3, rec.getBuffer().coordinateToPosition(15, 0));
177  Assert.assertEquals(3, rec.getBuffer().coordinateToPosition(16, 0));
178  Assert.assertEquals(3, rec.getBuffer().coordinateToPosition(17, 0));
179  Assert.assertEquals(3, rec.getBuffer().coordinateToPosition(18, 0));
180  Assert.assertEquals(3, rec.getBuffer().coordinateToPosition(19, 0));
181  Assert.assertEquals(4, rec.getBuffer().coordinateToPosition(20, 0));
182  Assert.assertEquals(4, rec.getBuffer().coordinateToPosition(21, 0));
183  Assert.assertEquals(4, rec.getBuffer().coordinateToPosition(22, 0));
184  Assert.assertEquals(4, rec.getBuffer().coordinateToPosition(23, 0));
185  Assert.assertEquals(20, rec.getBuffer().coordinateToPosition(100, 0));
186  Assert.assertEquals(0, rec.getBuffer().coordinateToPosition(0, 1));
187  Assert.assertEquals(0, rec.getBuffer().coordinateToPosition(0, 2));
188  Assert.assertEquals(0, rec.getBuffer().coordinateToPosition(0, 3));
189  Assert.assertEquals(0, rec.getBuffer().coordinateToPosition(0, 4));
190  Assert.assertEquals(0, rec.getBuffer().coordinateToPosition(0, 5));
191  Assert.assertEquals(0, rec.getBuffer().coordinateToPosition(0, 6));
192  Assert.assertEquals(0, rec.getBuffer().coordinateToPosition(0, 7));
193  Assert.assertEquals(0, rec.getBuffer().coordinateToPosition(0, 8));
194  Assert.assertEquals(0, rec.getBuffer().coordinateToPosition(0, 9));
195  Assert.assertEquals(0, rec.getBuffer().coordinateToPosition(0, 10));
196  Assert.assertEquals(24, rec.getBuffer().coordinateToPosition(0, 11));
197  Assert.assertEquals(24, rec.getBuffer().coordinateToPosition(0, 12));
198  Assert.assertEquals(24, rec.getBuffer().coordinateToPosition(0, 13));
199  Assert.assertEquals(24, rec.getBuffer().coordinateToPosition(0, 14));
200  Assert.assertEquals(24, rec.getBuffer().coordinateToPosition(0, 15));
201  Assert.assertEquals(24, rec.getBuffer().coordinateToPosition(0, 16));
202  Assert.assertEquals(24, rec.getBuffer().coordinateToPosition(0, 17));
203  Assert.assertEquals(24, rec.getBuffer().coordinateToPosition(0, 18));
204  Assert.assertEquals(24, rec.getBuffer().coordinateToPosition(0, 19));
205  Assert.assertEquals(24, rec.getBuffer().coordinateToPosition(0, 20));
206  Assert.assertEquals(24, rec.getBuffer().coordinateToPosition(0, 100));
207  Assert.assertEquals(24, rec.getBuffer().coordinateToPosition(100, 100));
208  }
209 
210 }
com.realtime.crossfire.jxclient
com.realtime.crossfire.jxclient.gui.log.RenderStateTest.test1
void test1()
Definition: RenderStateTest.java:46
com.realtime.crossfire.jxclient.gui.log.RenderStateTestRec.HEIGHT
static final int HEIGHT
Definition: RenderStateTestRec.java:20
com.realtime.crossfire.jxclient.gui.log.Parser.parse
void parse(@NotNull final CharSequence text, final int type, final int subtype, @NotNull final Color defaultColor, @NotNull final Buffer buffer)
Definition: Parser.java:138
com.realtime.crossfire.jxclient.gui.log.RenderStateTestRec.getBuffer
Buffer getBuffer()
Definition: RenderStateTestRec.java:78
com.realtime.crossfire.jxclient.protocol
Definition: MagicMap.java:23
com.realtime.crossfire.jxclient.protocol.MessageType
Definition: MessageType.java:33
com.realtime.crossfire.jxclient.gui.log.RenderStateTest
Definition: RenderStateTest.java:35
com.realtime.crossfire.jxclient.gui.log.RenderStateTestRec
Definition: RenderStateTestRec.java:10
com.realtime.crossfire.jxclient.gui.log.RenderStateTest.test2
void test2()
Definition: RenderStateTest.java:80
com.realtime.crossfire.jxclient.gui.log.RenderStateTestRec.FONT_HEIGHT
static final int FONT_HEIGHT
Definition: RenderStateTestRec.java:15
com.realtime.crossfire.jxclient.gui.log.RenderStateTest.coordinateToPosition
void coordinateToPosition()
Definition: RenderStateTest.java:150
com.realtime.crossfire
com.realtime
com.realtime.crossfire.jxclient.gui.log.RenderStateTestRec.scrollTo
void scrollTo(final int y)
Definition: RenderStateTestRec.java:86
com
com.realtime.crossfire.jxclient.gui.log.RenderStateTestRec.checkState
void checkState(final int expectedTopIndex, final int expectedTopOffset)
Definition: RenderStateTestRec.java:95
com.realtime.crossfire.jxclient.gui.log.Buffer.coordinateToPosition
int coordinateToPosition(final int x, final int y)
Definition: Buffer.java:413
com.realtime.crossfire.jxclient.protocol.MessageType.MSG_SUBTYPE_BOOK_CLASP_1
static final int MSG_SUBTYPE_BOOK_CLASP_1
Definition: MessageType.java:145
com.realtime.crossfire.jxclient.gui.log.Parser
Definition: Parser.java:40
com.realtime.crossfire.jxclient.protocol.MessageType.MSG_TYPE_BOOK
static final int MSG_TYPE_BOOK
Definition: MessageType.java:38