001: // jTDS JDBC Driver for Microsoft SQL Server and Sybase
002: // Copyright (C) 2004 The jTDS Project
003: //
004: // This library is free software; you can redistribute it and/or
005: // modify it under the terms of the GNU Lesser General Public
006: // License as published by the Free Software Foundation; either
007: // version 2.1 of the License, or (at your option) any later version.
008: //
009: // This library is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: // Lesser General Public License for more details.
013: //
014: // You should have received a copy of the GNU Lesser General Public
015: // License along with this library; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: //
018: package net.sourceforge.jtds.test;
019:
020: import net.sourceforge.jtds.jdbc.Driver;
021: import net.sourceforge.jtds.jdbc.SharedNamedPipe;
022: import net.sourceforge.jtds.jdbc.Support;
023: import net.sourceforge.jtds.jdbc.TdsCore;
024:
025: /**
026: * Unit tests for the {@link SharedNamedPipe} class.
027: *
028: * @author David D. Kilzer
029: * @version $Id: NamedPipeUnitTest.java,v 1.9 2007/07/08 18:08:54 bheineman Exp $
030: */
031: public class NamedPipeUnitTest extends UnitTestBase {
032:
033: /**
034: * Constructor.
035: *
036: * @param name The name of the test.
037: */
038: public NamedPipeUnitTest(final String name) {
039: super (name);
040: }
041:
042: /**
043: * Test that <code>Support.calculateNamedPipeBufferSize(int, int)</code>
044: * sets the buffer size appropriately for TDS 4.2 when the packet
045: * size is set to 0.
046: */
047: public void testCalculateBufferSize_TDS42() {
048: int length = invoke_calculateBufferSize(Driver.TDS42, 0);
049: assertEquals(TdsCore.MIN_PKT_SIZE, length);
050: }
051:
052: /**
053: * Test that <code>Support.calculateNamedPipeBufferSize(int, int)</code>
054: * sets the buffer size appropriately for TDS 5.0 when the packet
055: * size is set to 0.
056: */
057: public void testCalculateBufferSize_TDS50() {
058: int length = invoke_calculateBufferSize(Driver.TDS50, 0);
059: assertEquals(TdsCore.MIN_PKT_SIZE, length);
060: }
061:
062: /**
063: * Test that <code>Support.calculateNamedPipeBufferSize(int, int)</code>
064: * sets the buffer size appropriately for TDS 7.0 when the packet
065: * size is set to 0.
066: */
067: public void testCalculateBufferSize_TDS70() {
068: int length = invoke_calculateBufferSize(Driver.TDS70, 0);
069: assertEquals(TdsCore.DEFAULT_MIN_PKT_SIZE_TDS70, length);
070: }
071:
072: /**
073: * Test that <code>Support.calculateNamedPipeBufferSize(int, int)</code>
074: * sets the buffer size appropriately for TDS 8.0 when the packet
075: * size is set to 0.
076: */
077: public void testCalculateBufferSize_TDS80() {
078: int length = invoke_calculateBufferSize(Driver.TDS80, 0);
079: assertEquals(TdsCore.DEFAULT_MIN_PKT_SIZE_TDS70, length);
080: }
081:
082: /**
083: * Helper method to invoke {@link Support#calculateNamedPipeBufferSize(int, int)}
084: * using reflection.
085: *
086: * @param tdsVersion The TDS version as an <code>int</code>.
087: * @param packetSize The packet size as an <code>int</code>.
088: * @return Result of calling {@link Support#calculateNamedPipeBufferSize(int, int)}.
089: */
090: private int invoke_calculateBufferSize(int tdsVersion,
091: int packetSize) {
092: Class[] classes = new Class[] { int.class, int.class };
093: Object[] objects = new Object[] { new Integer(tdsVersion),
094: new Integer(packetSize) };
095:
096: return ((Integer) invokeStaticMethod(Support.class,
097: "calculateNamedPipeBufferSize", classes, objects))
098: .intValue();
099: }
100: }
|