TreeManagerin modulitestauksessa käytettiin seuraavia
testiluokkia, Test3 ja Test4
Test3.java:
import java.io.*;
public class Test3 {
private TreeManager man;
public Test3(File dtd, File doc) {
man = new TreeManager();
try {
man.createDTD(dtd);
}
catch (Exception e) {
e.printStackTrace(System.out); System.exit(0);
}
man.printAllFirstPaths();
man.createTree();
System.out.println("An empty valid tree:");
System.out.println(man.toString());
try {
man.createTree(doc);
}
catch (Exception e) {
e.printStackTrace(System.out); System.exit(0);
}
System.out.println(man.toString());
}
public static void main(String[] args) {
Test3 test = new Test3(new File(args[0]), new File(args[1]));
}
}
Test4.java:
import java.util.*;
import java.io.*;
public class Test4 {
private TreeManager man;
private void say(String s) {
System.out.println(s);
}
public Test4(File f) {
man = new TreeManager();
try {
man.createDTD(f);
}
catch (Exception e) {
e.printStackTrace(System.out); System.exit(0);
}
man.printAllFirstPaths();
say("> Here's an empty valid tree:\n");
man.createTree();
say(man.toString());
say("\n> Let's get
and let's build a valid .\n");
Element head = man.getHead();
Element title = man.buildValidElement("title", head);
say("\n> man.canAdd(head, title) yields " + man.canAdd(head, title) +
", so let's do man.add(head, title):\n");
man.add(head, title);
say("\n> Now looks like this:\n\n" +
head.toString());
say("\n> And man.toString() yields:\n" +
man.toString());
say("\n> Let's try adding a PCData under .\n" +
"> man.canAdd(head, new PCData(\"Otsikko\") yields " +
man.canAdd(head, new PCData("Otsikko")) + "\n");
say("Can we add a PCData under ? -" +
man.canAdd(head, new PCData("Otsikko")));
say("Let's try adding a PCData under . Success? -" +
man.add(title, new PCData("Otsikko")));
say("\n> Now man.toString() yields:\n" +
man.toString());
say("\n> OK. From now on, refer to the source code.");
say("man.isBlock(\"body\")"+man.isBlock("body"));
Block body = man.getBody();
Block bodyHead = (Block)man.buildValidElement("body.head", body);
Vector tmp = new Vector(); tmp.add(bodyHead);
man.add(body, 0, 0, tmp);
Block hedline = (Block)man.buildValidElement("hedline", bodyHead);
man.add(bodyHead, hedline);
Block hl2 = (Block)man.buildValidElement("hl2", hedline);
say("man.add(hedline, hl2)="+man.add(hedline, hl2));
Element location = man.buildValidElement("location", hl2);
say("man.add(hl1, location): "+man.add(hl2, location));
man.add(location, new PCData("hedline-otsikko"));
say(man.toString());
Vector tmp2 = new Vector();
tmp2.add(new PCData("XXXXXX"));
man.replace(location, 0, 4, 0, 6, tmp2);
say(man.toString());
}
public static void main(String[] args) {
Test4 test = new Test4(new File(args[0]));
}
}
*******************************************************************************
Näiden testien tulokset ovat seuraavat
Test3-testiluokan tulos:
java Test3 jouto2.dtd koe3.xml >test3
-------- getFirstPaths ---------
ul:
li
evloc:
tobject.subject:
media-caption:
a:
body.head:
doc-id:
person:
media:
media-reference
byline:
story.date:
keyword:
pre:
head:
doc.copyright:
body.content:
hedline:
hl1
abstract:
p
nitf:
head body
tobject:
tobject.subject
title:
key-list:
location:
br:
li:
hl2:
hl1:
distributor:
org:
body:
ol:
li
media-reference:
q:
p:
docdata:
doc-id date.issue
em:
dateline:
date.issue:
object.title:
An empty valid tree: