/* Copyright (c) 2003-2004 Ricebridge. All Rights Reserved.
 *
 * This file is available under the terms and conditions of the
 * Ricebridge "Open Source API" policy; Ricebridge grants use of this
 * copyrighted work under the terms of a BSD-style license only. See
 * http://www.opensource.org/licenses/bsd-license.php for more
 * information.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 *  - Redistributions of source code must retain the above copyright
 *  notice, this list of conditions and the following disclaimer.
 *
 *  - Redistributions in binary form must reproduce the above
 *  copyright notice, this list of conditions and the following
 *  disclaimer in the documentation and/or other materials provided
 *  with the distribution.
 *
 *  - Neither the name of the Ricebridge nor the names of its
 *  contributors may be used to endorse or promote products derived
 *  from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.  
 */

package com.ricebridge.csvman.test;


import com.ricebridge.csvman.*;

import junit.framework.*;
import junit.textui.*;

import java.util.*;



/** Test cases for {@link com.ricebridge.csvman.CsvSpec}.
 *    <p>The <b><a href="CsvSpecTest.java.html">Source Code</a></b> of this Java class 
 *    is available under a <a href="http://www.opensource.org/licenses/bsd-license.php">BSD-style license</a>.</p>
 */
public class CsvSpecTest extends TestCase {

  // standard test methods
  
  public CsvSpecTest( String pName ) {
    super( pName );
  }

  public static TestSuite suite() {
    return new TestSuite( CsvSpecTest.class );
  }

  public static void main( String[] pArgs ) {
    TestRunner.run( suite() );
  }


  public void testToString() {
    CsvSpec cs = new CsvSpec();
    assertTrue( 0 < cs.toString().length() );
  }

  
  public void testRetention() {
    CsvSpec cs = new CsvSpec();
    
    HashMap em1 = new HashMap();
    HashMap em2 = new HashMap();
    
    cs.setAllowQuotedLineEnds( false );            assertEquals( false, cs.getAllowQuotedLineEnds() );
    cs.setAllowQuotedLineEnds( true );             assertEquals( true, cs.getAllowQuotedLineEnds() );

    cs.setCloseInputStream(  false );              assertEquals( false, cs.getCloseInputStream() );
    cs.setCloseInputStream(  true );               assertEquals( true, cs.getCloseInputStream() );

    cs.setCloseOutputStream( false );              assertEquals( false, cs.getCloseOutputStream() );
    cs.setCloseOutputStream( true );               assertEquals( true, cs.getCloseOutputStream() );

    cs.setCollectBadLines(   false );              assertEquals( false, cs.getCollectBadLines() );
    cs.setCollectBadLines(   true );               assertEquals( true, cs.getCollectBadLines() );

    cs.setComment(           '~' );                assertEquals( '~', cs.getComment() );
    cs.setComment(           '#' );                assertEquals( '#', cs.getComment() );

    cs.setCommentWithinLine( true );               assertEquals( true, cs.getCommentWithinLine() );
    cs.setCommentWithinLine( false );              assertEquals( false, cs.getCommentWithinLine() );

    cs.setDataFieldMaxLength( 1 );                 assertEquals( 1, cs.getDataFieldMaxLength() );
    cs.setDataFieldMaxLength( 0 );                 assertEquals( 0, cs.getDataFieldMaxLength() );

    cs.setDoubleQuote(       false );              assertEquals( false, cs.getDoubleQuote() );
    cs.setDoubleQuote(       true );               assertEquals( true, cs.getDoubleQuote() );

    cs.setEncoding(          "foo" );              assertEquals( "foo", cs.getEncoding() );
    cs.setEncoding(          null );               assertEquals( null, cs.getEncoding() );

    cs.setEndLine(            1 );                 assertEquals(  1, cs.getEndLine() );
    cs.setEndLine(           -1 );                 assertEquals( -1, cs.getEndLine() );

    cs.setEndOfLine(         "\n" );               assertEquals( "\n", cs.getEndOfLine() );
    cs.setEndOfLine(         "\r\n" );             assertEquals( "\r\n", cs.getEndOfLine() );

    cs.setEscape(            '\'' );               assertEquals( '\'', cs.getEscape() );
    cs.setEscape(            '\\' );               assertEquals( '\\', cs.getEscape() );

    cs.setEscapeMap(         em1 );                assertEquals( em1, cs.getEscapeMap() );
    cs.setEscapeMap(         em2 );                assertEquals( em2, cs.getEscapeMap() );

    cs.setFlushEachLine(     true );               assertEquals( true, cs.getFlushEachLine() );
    cs.setFlushEachLine(     false );              assertEquals( false, cs.getFlushEachLine() );

    cs.setIgnoreBadLines(    true );               assertEquals( true, cs.getIgnoreBadLines() );
    cs.setIgnoreBadLines(    false );              assertEquals( false, cs.getIgnoreBadLines() );

    cs.setIgnoreEmptyLines(  true );               assertEquals( true, cs.getIgnoreEmptyLines() );
    cs.setIgnoreEmptyLines(  false );              assertEquals( false, cs.getIgnoreEmptyLines() );

    cs.setMergeSeparators(   true );               assertEquals( true, cs.getMergeSeparators() );
    cs.setMergeSeparators(   false );              assertEquals( false, cs.getMergeSeparators() );

    cs.setNumFields(         1 );                  assertEquals( 1, cs.getNumFields() );
    cs.setNumFields(         0 );                  assertEquals( 0, cs.getNumFields() );

    cs.setQuote(             '\'' );               assertEquals( '\'', cs.getQuote() );
    cs.setQuote(             '"' );                assertEquals( '"', cs.getQuote() );

    cs.setQuoteType(         QuoteType.All );      assertEquals( QuoteType.All, cs.getQuoteType() );
    cs.setQuoteType(         QuoteType.AsNeeded ); assertEquals( QuoteType.AsNeeded, cs.getQuoteType() );

    cs.setSeparator(         ";" );                assertEquals( ";", cs.getSeparator() );
    cs.setSeparator(         "," );                assertEquals( ",", cs.getSeparator() );

    cs.setStartLine(         2 );                  assertEquals( 2, cs.getStartLine() );
    cs.setStartLine(         1 );                  assertEquals( 1, cs.getStartLine() );

    cs.setTrim(              "\t" );               assertEquals( "\t", cs.getTrim() );
    cs.setTrim(              " \t" );              assertEquals( " \t", cs.getTrim() );

    cs.setTrimType(          TrimType.None );      assertEquals( TrimType.None, cs.getTrimType() );
    cs.setTrimType(          TrimType.Full );      assertEquals( TrimType.Full, cs.getTrimType() );

    cs.setUseComment(        true );               assertEquals( true, cs.getUseComment() );
    cs.setUseComment(        false );              assertEquals( false, cs.getUseComment() );

    cs.setUseEscape(         true );               assertEquals( true, cs.getUseEscape() );
    cs.setUseEscape(         false );              assertEquals( false, cs.getUseEscape() );

    cs.setUseEscapeMap(      true );               assertEquals( true, cs.getUseEscapeMap() );
    cs.setUseEscapeMap(      false );              assertEquals( false, cs.getUseEscapeMap() );

    cs.setUseQuote(          false );              assertEquals( false, cs.getUseQuote() );
    cs.setUseQuote(          true );               assertEquals( true, cs.getUseQuote() );

    cs.setVerbatimEndOfLine( true );               assertEquals( true, cs.getVerbatimEndOfLine() );
    cs.setVerbatimEndOfLine( false );              assertEquals( false, cs.getVerbatimEndOfLine() );   
  }
  
}





Syntax Highlighting created using the com.Ostermiller.Syntax package.
Wednesday, June 20 2007 at 22:16