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 TerminalTypeOptionHandlerTest extends TelnetOptionHandlerTestAbstract
25  {
26      /***
27       * setUp for the test.
28       ***/
29      @Override
30      protected void setUp()
31      {
32          opthand1 = new TerminalTypeOptionHandler("VT100");
33          opthand2 = new TerminalTypeOptionHandler("ANSI", true, true, true, true);
34          opthand3 = new TerminalTypeOptionHandler("ANSI", false, false, false, false);
35      }
36  
37      /***
38       * test of the constructors.
39       ***/
40      @Override
41      public void testConstructors()
42      {
43          assertEquals(opthand1.getOptionCode(), TelnetOption.TERMINAL_TYPE);
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  
55          int resp1[] = opthand1.startSubnegotiationLocal();
56          int resp2[] = opthand1.startSubnegotiationRemote();
57  
58          assertEquals(resp1, null);
59          assertEquals(resp2, null);
60      }
61  
62  
63      /***
64       * test of client-driven subnegotiation.
65       * Checks that the terminal type is sent
66       ***/
67      @Override
68      public void testAnswerSubnegotiation()
69      {
70          int subn[] =
71          {
72              TelnetOption.TERMINAL_TYPE, 1
73          };
74  
75          int expected1[] =
76          {
77              TelnetOption.TERMINAL_TYPE, 0, 'V', 'T', '1', '0', '0'
78          };
79  
80          int expected2[] =
81          {
82              TelnetOption.TERMINAL_TYPE, 0, 'A', 'N', 'S', 'I'
83          };
84  
85          int resp1[] = opthand1.answerSubnegotiation(subn, subn.length);
86          int resp2[] = opthand2.answerSubnegotiation(subn, subn.length);
87  
88          assertTrue(equalInts(resp1, expected1));
89          assertTrue(equalInts(resp2, expected2));
90      }
91  
92  
93      /***
94       * compares two arrays of int
95       ***/
96      protected boolean equalInts(int a1[], int a2[])
97      {
98          if(a1.length != a2.length)
99          {
100             return(false);
101         }
102         else
103         {
104             boolean result = true;
105             for(int ii=0; ii<a1.length; ii++)
106             {
107                 if(a1[ii]!= a2[ii]) {
108                     result = false;
109                 }
110             }
111             return(result);
112         }
113     }
114 }