001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 package org.apache.commons.net.telnet; 018 019 /*** 020 * JUnit test class for TerminalTypeOptionHandler 021 * <p> 022 * @author Bruno D'Avanzo 023 ***/ 024 public class TerminalTypeOptionHandlerTest extends TelnetOptionHandlerTestAbstract 025 { 026 /*** 027 * main for running the test. 028 ***/ 029 public static void main(String args[]) 030 { 031 junit.textui.TestRunner.run(TerminalTypeOptionHandlerTest.class); 032 } 033 034 /*** 035 * setUp for the test. 036 ***/ 037 @Override 038 protected void setUp() 039 { 040 opthand1 = new TerminalTypeOptionHandler("VT100"); 041 opthand2 = new TerminalTypeOptionHandler("ANSI", true, true, true, true); 042 opthand3 = new TerminalTypeOptionHandler("ANSI", false, false, false, false); 043 } 044 045 /*** 046 * test of the constructors. 047 ***/ 048 @Override 049 public void testConstructors() 050 { 051 assertEquals(opthand1.getOptionCode(), TelnetOption.TERMINAL_TYPE); 052 super.testConstructors(); 053 } 054 055 /*** 056 * test of client-driven subnegotiation. 057 * Checks that no subnegotiation is made. 058 ***/ 059 @Override 060 public void testStartSubnegotiation() 061 { 062 063 int resp1[] = opthand1.startSubnegotiationLocal(); 064 int resp2[] = opthand1.startSubnegotiationRemote(); 065 066 assertEquals(resp1, null); 067 assertEquals(resp2, null); 068 } 069 070 071 /*** 072 * test of client-driven subnegotiation. 073 * Checks that the terminal type is sent 074 ***/ 075 @Override 076 public void testAnswerSubnegotiation() 077 { 078 int subn[] = 079 { 080 TelnetOption.TERMINAL_TYPE, 1 081 }; 082 083 int expected1[] = 084 { 085 TelnetOption.TERMINAL_TYPE, 0, 'V', 'T', '1', '0', '0' 086 }; 087 088 int expected2[] = 089 { 090 TelnetOption.TERMINAL_TYPE, 0, 'A', 'N', 'S', 'I' 091 }; 092 093 int resp1[] = opthand1.answerSubnegotiation(subn, subn.length); 094 int resp2[] = opthand2.answerSubnegotiation(subn, subn.length); 095 096 assertTrue(equalInts(resp1, expected1)); 097 assertTrue(equalInts(resp2, expected2)); 098 } 099 100 101 /*** 102 * compares two arrays of int 103 ***/ 104 protected boolean equalInts(int a1[], int a2[]) 105 { 106 if(a1.length != a2.length) 107 { 108 return(false); 109 } 110 else 111 { 112 boolean result = true; 113 for(int ii=0; ii<a1.length; ii++) 114 { 115 if(a1[ii]!= a2[ii]) 116 result = false; 117 } 118 return(result); 119 } 120 } 121 }