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   * <p>
22   * @author Bruno D'Avanzo
23   ***/
24  public class WindowSizeOptionHandlerTest extends TelnetOptionHandlerTestAbstract
25  {
26      /***
27       * setUp for the test.
28       ***/
29      @Override
30      protected void setUp()
31      {
32          opthand1 = new WindowSizeOptionHandler(80, 24);
33          opthand2 = new WindowSizeOptionHandler(255, 255, true, true, true, true);
34          opthand3 = new WindowSizeOptionHandler(0xFFFF, 0x00FF, false, false, false, false);
35      }
36  
37      /***
38       * test of the constructors.
39       ***/
40      @Override
41      public void testConstructors()
42      {
43          assertEquals(TelnetOption.WINDOW_SIZE, opthand1.getOptionCode());
44          super.testConstructors();
45      }
46  
47      /***
48       * test of client-driven subnegotiation.
49       * Checks that no subnegotiation is made.
50       ***/
51      @Override
52      public void testStartSubnegotiation()
53      {
54          assertNull(opthand1.startSubnegotiationRemote());
55          assertNull(opthand2.startSubnegotiationRemote());
56          assertNull(opthand3.startSubnegotiationRemote());
57      }
58  
59      /***
60       * test of client-driven subnegotiation.
61       *
62       ***/
63      public void testStartSubnegotiationLocal()
64      {
65          int[] exp1 = {31, 0, 80, 0, 24};
66          int[] start1 = opthand1.startSubnegotiationLocal();
67          assertEquals(5, start1.length);
68          equalInts(exp1, start1);
69  
70          int[] exp2 = {31, 0, 255, 255, 0, 255, 255};
71          int[] start2 = opthand2.startSubnegotiationLocal();
72          equalInts(exp2, start2);
73  
74          int[] exp3 = {31, 255, 255, 255, 255, 0, 255, 255};
75          int[] start3 = opthand3.startSubnegotiationLocal();
76          equalInts(exp3, start3);
77      }
78  
79  
80  
81      /***
82       * test of client-driven subnegotiation.
83       * Checks that nothing is sent
84       ***/
85      @Override
86      public void testAnswerSubnegotiation()
87      {
88          int subn[] =
89          {
90              TelnetOption.WINDOW_SIZE, 24, 80
91          };
92  
93          int resp1[] = opthand1.answerSubnegotiation(subn, subn.length);
94          int resp2[] = opthand2.answerSubnegotiation(subn, subn.length);
95          int resp3[] = opthand3.answerSubnegotiation(subn, subn.length);
96  
97          assertNull(resp1);
98          assertNull(resp2);
99          assertNull(resp3);
100     }
101 
102     /***
103      * compares two arrays of int
104      ***/
105     private void equalInts(int a1[], int a2[])
106     {
107         assertEquals("Arrays should be the same length", a1.length, a2.length);
108         for(int ii=0; ii<a1.length; ii++)
109         {
110             assertEquals("Array entry "+ii+" should match",a1[ii], a2[ii]);
111         }
112     }
113 }