View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  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  package org.apache.commons.net.telnet;
18  
19  /**
20   * JUnit test class for TerminalTypeOptionHandler
21   */
22  public class WindowSizeOptionHandlerTest extends AbstractTelnetOptionHandlerTest {
23      /**
24       * compares two arrays of int
25       */
26      private void equalInts(final int a1[], final int a2[]) {
27          assertEquals("Arrays should be the same length", a1.length, a2.length);
28          for (int ii = 0; ii < a1.length; ii++) {
29              assertEquals("Array entry " + ii + " should match", a1[ii], a2[ii]);
30          }
31      }
32  
33      /**
34       * setUp for the test.
35       */
36      @Override
37      protected void setUp() {
38          opthand1 = new WindowSizeOptionHandler(80, 24);
39          opthand2 = new WindowSizeOptionHandler(255, 255, true, true, true, true);
40          opthand3 = new WindowSizeOptionHandler(0xFFFF, 0x00FF, false, false, false, false);
41      }
42  
43      /**
44       * test of client-driven subnegotiation. Checks that nothing is sent
45       */
46      @Override
47      public void testAnswerSubnegotiation() {
48          final int[] subn = { TelnetOption.WINDOW_SIZE, 24, 80 };
49  
50          final int[] resp1 = opthand1.answerSubnegotiation(subn, subn.length);
51          final int[] resp2 = opthand2.answerSubnegotiation(subn, subn.length);
52          final int[] resp3 = opthand3.answerSubnegotiation(subn, subn.length);
53  
54          assertNull(resp1);
55          assertNull(resp2);
56          assertNull(resp3);
57      }
58  
59      /**
60       * test of the constructors.
61       */
62      @Override
63      public void testConstructors() {
64          assertEquals(TelnetOption.WINDOW_SIZE, opthand1.getOptionCode());
65          super.testConstructors();
66      }
67  
68      /**
69       * test of client-driven subnegotiation. Checks that no subnegotiation is made.
70       */
71      @Override
72      public void testStartSubnegotiation() {
73          assertNull(opthand1.startSubnegotiationRemote());
74          assertNull(opthand2.startSubnegotiationRemote());
75          assertNull(opthand3.startSubnegotiationRemote());
76      }
77  
78      /**
79       * test of client-driven subnegotiation.
80       *
81       */
82      public void testStartSubnegotiationLocal() {
83          final int[] exp1 = { 31, 0, 80, 0, 24 };
84          final int[] start1 = opthand1.startSubnegotiationLocal();
85          assertEquals(5, start1.length);
86          equalInts(exp1, start1);
87  
88          final int[] exp2 = { 31, 0, 255, 255, 0, 255, 255 };
89          final int[] start2 = opthand2.startSubnegotiationLocal();
90          equalInts(exp2, start2);
91  
92          final int[] exp3 = { 31, 255, 255, 255, 255, 0, 255, 255 };
93          final int[] start3 = opthand3.startSubnegotiationLocal();
94          equalInts(exp3, start3);
95      }
96  }