[Nodal-cvs] j-test/src/test/org/nodal/util Suite.java,NONE,1.1 TestGraphIterator.java,NONE,1.1
Status: Pre-Alpha
Brought to you by:
leei
From: Lee I. <le...@us...> - 2004-10-03 19:44:07
|
Update of /cvsroot/nodal/j-test/src/test/org/nodal/util In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12471/src/test/org/nodal/util Added Files: Suite.java TestGraphIterator.java Log Message: First commit separating j-test from j-src --- NEW FILE: Suite.java --- /* * Distributed under the Apache Software License, Version 1.1 * (see below, or the file LICENSE for terms and conditions) * * Copyright (c) 2004 University of British Columbia. All rights reserved. * * Created on Jul 16, 2004 by leei */ package test.org.nodal.util; import junit.framework.Test; import junit.framework.TestSuite; /** JUnit TestSuite. * @testfamily JUnit * @testkind testsuite * @testsetup Default TestSuite * @testpackage test.storage*/ public class Suite extends TestSuite { public Suite(String name) { super (name); } public static Test suite() { TestSuite result = new TestSuite ("Test storage.file"); // Add calls to test cases here! result.addTestSuite(TestGraphIterator.class); return result; } public static void main(String[] args) { junit.textui.TestRunner.run (suite()); } } --- NEW FILE: TestGraphIterator.java --- /* * Distributed under the Apache Software License, Version 1.1 * (see below, or the file LICENSE for terms and conditions) * * Copyright (c) 2004 University of British Columbia. All rights reserved. * * Created on Jul 16, 2004 by leei */ package test.org.nodal.util; import java.net.URL; import org.nodal.Nodal; import org.nodal.filesystem.Document; import org.nodal.model.Getter; import org.nodal.model.Node; import org.nodal.nav.Path; import org.nodal.nav.Paths; import org.nodal.util.GraphIterator; import junit.framework.TestCase; /** * @author leei */ public class TestGraphIterator extends TestCase { /* * @see TestCase#setUp() */ protected void setUp() throws Exception { super.setUp(); } /* * @see TestCase#tearDown() */ protected void tearDown() throws Exception { super.tearDown(); } private void checkResource (String rname) throws Path.Failure { URL url = Nodal.class.getClassLoader().getResource(rname); Document doc = Nodal.openDocument(url.toExternalForm()); checkDocument (doc); } private void checkDocument (Document doc) throws Path.Failure { Node root = doc.root(); Path rootPath = doc.path().apply(Paths.createOp("root")); checkIterator (root, rootPath); } private void checkIterator (Node node, Path path) throws Path.Failure { GraphIterator i = new GraphIterator (node); //System.err.println ("BFS { "+path); while (i.hasNext()) { Path relPath = i.nextPath(); Path absPath = path.apply(relPath); Node rel = i.nextNode (); //System.err.println (" + "+relPath+" => "+rel); Getter binding = absPath.bind(); Node bound = binding.getNode(); assertTrue (bound.bareNode() == rel.bareNode()); } //System.err.println("} BFS"); } public void testIterator () { try { checkResource ("baseTypes.nls"); checkResource ("xml.nls"); } catch (Path.Failure e) { e.printStackTrace(); fail (); } } } |