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  public class TerminalTypeOptionHandlerTest extends AbstractTelnetOptionHandlerTest {
20      /*
21       * compares two arrays of int
22       */
23      protected boolean equalInts(final int a1[], final int a2[]) {
24          if (a1.length != a2.length) {
25              return false;
26          }
27          boolean result = true;
28          for (int ii = 0; ii < a1.length; ii++) {
29              if (a1[ii] != a2[ii]) {
30                  result = false;
31              }
32          }
33          return result;
34      }
35  
36      @Override
37      protected void setUp() {
38          opthand1 = new TerminalTypeOptionHandler("VT100");
39          opthand2 = new TerminalTypeOptionHandler("ANSI", true, true, true, true);
40          opthand3 = new TerminalTypeOptionHandler("ANSI", false, false, false, false);
41      }
42  
43      /*
44       * test of client-driven subnegotiation. Checks that the terminal type is sent
45       */
46      @Override
47      public void testAnswerSubnegotiation() {
48          final int[] subn = { TelnetOption.TERMINAL_TYPE, 1 };
49  
50          final int[] expected1 = { TelnetOption.TERMINAL_TYPE, 0, 'V', 'T', '1', '0', '0' };
51  
52          final int[] expected2 = { TelnetOption.TERMINAL_TYPE, 0, 'A', 'N', 'S', 'I' };
53  
54          final int[] resp1 = opthand1.answerSubnegotiation(subn, subn.length);
55          final int[] resp2 = opthand2.answerSubnegotiation(subn, subn.length);
56  
57          assertTrue(equalInts(resp1, expected1));
58          assertTrue(equalInts(resp2, expected2));
59      }
60  
61      @Override
62      public void testConstructors() {
63          assertEquals(opthand1.getOptionCode(), TelnetOption.TERMINAL_TYPE);
64          super.testConstructors();
65      }
66  
67      /*
68       * test of client-driven subnegotiation. Checks that no subnegotiation is made.
69       */
70      @Override
71      public void testStartSubnegotiation() {
72  
73          final int[] resp1 = opthand1.startSubnegotiationLocal();
74          final int[] resp2 = opthand1.startSubnegotiationRemote();
75  
76          assertNull(resp1);
77          assertNull(resp2);
78      }
79  }