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