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    *      https://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                  break;
32              }
33          }
34          return result;
35      }
36  
37      @Override
38      protected void setUp() {
39          opthand1 = new TerminalTypeOptionHandler("VT100");
40          opthand2 = new TerminalTypeOptionHandler("ANSI", true, true, true, true);
41          opthand3 = new TerminalTypeOptionHandler("ANSI", false, false, false, false);
42      }
43  
44      /*
45       * test of client-driven subnegotiation. Checks that the terminal type is sent
46       */
47      @Override
48      public void testAnswerSubnegotiation() {
49          final int[] subn = { TelnetOption.TERMINAL_TYPE, 1 };
50  
51          final int[] expected1 = { TelnetOption.TERMINAL_TYPE, 0, 'V', 'T', '1', '0', '0' };
52  
53          final int[] expected2 = { TelnetOption.TERMINAL_TYPE, 0, 'A', 'N', 'S', 'I' };
54  
55          final int[] resp1 = opthand1.answerSubnegotiation(subn, subn.length);
56          final int[] resp2 = opthand2.answerSubnegotiation(subn, subn.length);
57  
58          assertTrue(equalInts(resp1, expected1));
59          assertTrue(equalInts(resp2, expected2));
60      }
61  
62      @Override
63      public void testConstructors() {
64          assertEquals(opthand1.getOptionCode(), TelnetOption.TERMINAL_TYPE);
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  
74          final int[] resp1 = opthand1.startSubnegotiationLocal();
75          final int[] resp2 = opthand1.startSubnegotiationRemote();
76  
77          assertNull(resp1);
78          assertNull(resp2);
79      }
80  }