/* Copyright (c) 2005 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.xmlman.in.test;


import com.ricebridge.xmlman.in.OutNode;
import com.ricebridge.xmlman.in.OutState;
import com.ricebridge.xmlman.in.OutData;

import org.jostraca.util.*;

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

import java.util.*;


/** Test cases for {@link com.ricebridge.xmlman.in.OutNode}. 
 *    <p>The <b><a href="OutNodeTest.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 OutNodeTest extends TestCase {

  // test framework
  
  public OutNodeTest( String pName ) {
    super( pName );
  }

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

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



  
  // test methods
  
  public void testCreate() throws Exception {
    OutState os = new OutState();

    OutNode root = new OutNode("root",1);
    OutNode a    = new OutNode("a",1);
    root.addChild(a);
    OutNode b    = new OutNode("b",1);
    a.addChild(b);
    OutNode c    = new OutNode("c",1);
    b.addChild(c);
    OutNode d    = new OutNode("d",1);
    b.addChild(d);
    OutNode e    = new OutNode("e",1);
    d.addChild(e);

    OutNode n = root.nextChild( os );
    assertEquals( a, n );
    n = root.nextChild( os );
    assertTrue( n == null );
    n = root.nextChild( os );
    assertEquals( a, n );
    
    n = a.nextChild( os );
    assertEquals( b, n );

    n = b.nextChild( os );
    assertEquals( c, n );
    n = b.nextChild( os );
    assertEquals( d, n );
    n = b.nextChild( os );
    assertTrue( null == n);
    n = b.nextChild( os );
    assertEquals( c, n );
    n = b.nextChild( os );
    assertEquals( d, n );

    n = d.nextChild( os );
    assertEquals( e, n );

  }



  public void testPosition() throws Exception {
    OutState os = new OutState();

    OutNode root = new OutNode("root",1);
    OutNode a1    = new OutNode("a",1);
    a1.addOutData( new OutData( TestUtil.makeNameInfo("a1") ) );
    root.addChild(a1);
    assertEquals( "a1:"+"root-root-N  a[(@a1)]", "a1:"+root.debugString().replace('\n','N') ); 

    OutNode a2 = new OutNode("a",2);
    a2.addOutData( new OutData( TestUtil.makeNameInfo("a2") ) );
    root.addChild(a2);
    assertEquals( "a2:"+"root-root-N  a[(@a1)]N  a[(@a2)]", "a2:"+root.debugString().replace('\n','N') ); 


    OutNode b1a = new OutNode("b",1);
    b1a.addOutData( new OutData( TestUtil.makeNameInfo("b1a") ) );
    a1.addChild(b1a);
    assertEquals( "b1a:"+"root-root-N  a[(@a1)]N    b[(@b1a)]N  a[(@a2)]", "b1a:"+root.debugString().replace('\n','N') ); 

    OutNode b2a = new OutNode("b",2);
    b2a.addOutData( new OutData( TestUtil.makeNameInfo("b2a") ) );
    a1.addChild(b2a);
    assertEquals( "b2a:"+"root-root-N  a[(@a1)]N    b[(@b1a)]N    b[(@b2a)]N  a[(@a2)]", "b2a:"+root.debugString().replace('\n','N') ); 

    OutNode b1b = new OutNode("b",1);
    b1b.addOutData( new OutData( TestUtil.makeNameInfo("b1b") ) );
    a1.addChild(b1b);
    assertEquals( "b1b:"+"root-root-N  a[(@a1)]N    b[(@b1a)]N    b[(@b1b)]N    b[(@b2a)]N  a[(@a2)]", 
                  "b1b:"+root.debugString().replace('\n','N') ); 

    OutNode b3a = new OutNode("b",3);
    b3a.addOutData( new OutData( TestUtil.makeNameInfo("b3a") ) );
    a1.addChild(b3a);
    assertEquals( "b3a:"+"root-root-N  a[(@a1)]N    b[(@b1a)]N    b[(@b1b)]N    b[(@b2a)]N    b[(@b3a)]N  a[(@a2)]", 
                  "b3a:"+root.debugString().replace('\n','N') ); 

    OutNode b2b = new OutNode("b",2);
    b2b.addOutData( new OutData( TestUtil.makeNameInfo("b2b") ) );
    a1.addChild(b2b);
    assertEquals( "b2b:"+"root-root-N  a[(@a1)]N    b[(@b1a)]N    b[(@b1b)]N    b[(@b2a)]N    b[(@b2b)]N    b[(@b3a)]N  a[(@a2)]", 
                  "b2b:"+root.debugString().replace('\n','N') ); 


    OutNode c3a = new OutNode("c",3);
    c3a.addOutData( new OutData( TestUtil.makeNameInfo("c3a") ) );
    a2.addChild(c3a);
    assertEquals( "c3a:"+"root-root-N  a[(@a1)]N    b[(@b1a)]N    b[(@b1b)]N    b[(@b2a)]N    b[(@b2b)]N    b[(@b3a)]"
                  +"N  a[(@a2)]N    c[(@c3a)]", 
                  "c3a:"+root.debugString().replace('\n','N') ); 

    OutNode c2a = new OutNode("c",2);
    c2a.addOutData( new OutData( TestUtil.makeNameInfo("c2a") ) );
    a2.addChild(c2a);
    assertEquals( "c2a:"+"root-root-N  a[(@a1)]N    b[(@b1a)]N    b[(@b1b)]N    b[(@b2a)]N    b[(@b2b)]N    b[(@b3a)]"
                  +"N  a[(@a2)]N    c[(@c2a)]N    c[(@c3a)]", 
                  "c2a:"+root.debugString().replace('\n','N') ); 

    OutNode c2b = new OutNode("c",2);
    c2b.addOutData( new OutData( TestUtil.makeNameInfo("c2b") ) );
    a2.addChild(c2b);
    assertEquals( "c2b:"+"root-root-N  a[(@a1)]N    b[(@b1a)]N    b[(@b1b)]N    b[(@b2a)]N    b[(@b2b)]N    b[(@b3a)]"
                  +"N  a[(@a2)]N    c[(@c2a)]N    c[(@c2b)]N    c[(@c3a)]", 
                  "c2b:"+root.debugString().replace('\n','N') ); 
    
    OutNode c1a = new OutNode("c",1);
    c1a.addOutData( new OutData( TestUtil.makeNameInfo("c1a") ) );
    a2.addChild(c1a);
    assertEquals( "c1a:"+"root-root-N  a[(@a1)]N    b[(@b1a)]N    b[(@b1b)]N    b[(@b2a)]N    b[(@b2b)]N    b[(@b3a)]"
                  +"N  a[(@a2)]N    c[(@c1a)]N    c[(@c2a)]N    c[(@c2b)]N    c[(@c3a)]", 
                  "c1a:"+root.debugString().replace('\n','N') ); 
    
  }

}






Syntax Highlighting created using the com.Ostermiller.Syntax package.
Thursday, February 23 2006 at 16:47