1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.net.telnet;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertNull;
21
22 import org.junit.jupiter.api.BeforeEach;
23 import org.junit.jupiter.api.Test;
24
25
26
27
28 class WindowSizeOptionHandlerTest extends AbstractTelnetOptionHandlerTest {
29
30
31
32
33 private void equalInts(final int a1[], final int a2[]) {
34 assertEquals(a1.length, a2.length, "Arrays should be the same length");
35 for (int ii = 0; ii < a1.length; ii++) {
36 assertEquals(a1[ii], a2[ii], "Array entry " + ii + " should match");
37 }
38 }
39
40
41
42
43 @BeforeEach
44 protected void setUp() {
45 opthand1 = new WindowSizeOptionHandler(80, 24);
46 opthand2 = new WindowSizeOptionHandler(255, 255, true, true, true, true);
47 opthand3 = new WindowSizeOptionHandler(0xFFFF, 0x00FF, false, false, false, false);
48 }
49
50
51
52
53 @Test
54 void testAnswerSubnegotiation() {
55 final int[] subn = { TelnetOption.WINDOW_SIZE, 24, 80 };
56
57 final int[] resp1 = opthand1.answerSubnegotiation(subn, subn.length);
58 final int[] resp2 = opthand2.answerSubnegotiation(subn, subn.length);
59 final int[] resp3 = opthand3.answerSubnegotiation(subn, subn.length);
60
61 assertNull(resp1);
62 assertNull(resp2);
63 assertNull(resp3);
64 }
65
66
67
68
69 @Override
70 @Test
71 void testConstructors() {
72 assertEquals(TelnetOption.WINDOW_SIZE, opthand1.getOptionCode());
73 super.testConstructors();
74 }
75
76
77
78
79 @Test
80 void testStartSubnegotiation() {
81 assertNull(opthand1.startSubnegotiationRemote());
82 assertNull(opthand2.startSubnegotiationRemote());
83 assertNull(opthand3.startSubnegotiationRemote());
84 }
85
86
87
88
89 @Test
90 void testStartSubnegotiationLocal() {
91 final int[] exp1 = { 31, 0, 80, 0, 24 };
92 final int[] start1 = opthand1.startSubnegotiationLocal();
93 assertEquals(5, start1.length);
94 equalInts(exp1, start1);
95
96 final int[] exp2 = { 31, 0, 255, 255, 0, 255, 255 };
97 final int[] start2 = opthand2.startSubnegotiationLocal();
98 equalInts(exp2, start2);
99
100 final int[] exp3 = { 31, 255, 255, 255, 255, 0, 255, 255 };
101 final int[] start3 = opthand3.startSubnegotiationLocal();
102 equalInts(exp3, start3);
103 }
104 }