update standards version
[debian/freetts] / tests / LetterToSoundTest.java
1 /**
2  * Copyright 2001 Sun Microsystems, Inc.
3  * 
4  * See the file "license.terms" for information on usage and
5  * redistribution of this file, and for a DISCLAIMER OF ALL 
6  * WARRANTIES.
7  */
8 package tests;
9 import junit.framework.*;
10 import java.util.*;
11 import java.io.*;
12 import java.net.URL;
13 import com.sun.speech.freetts.*;
14 import com.sun.speech.freetts.lexicon.LetterToSound;
15 import com.sun.speech.freetts.lexicon.LetterToSoundImpl;
16
17 /**
18  * Provides junit tests for the LetterToSound class
19  * 
20  * @version 1.0
21  */
22 public class LetterToSoundTest extends TestCase {
23     BufferedReader reader = null;
24     LetterToSound lts = null;
25
26     /**
27      * Creates the set of LetterToSoundTest
28      * 
29      * @param  name the name of the test.
30      */
31     public LetterToSoundTest(String name) {
32         super(name);
33     }
34
35
36     /**
37      * Common code run before each test
38      */
39     protected void setUp() {
40         try {
41             lts = new LetterToSoundImpl( 
42              new URL("file:../bld/classes/com/sun/speech/freetts/en/us/cmulex_lts.bin"), true);
43             assertTrue("LTS Rules created", lts != null);
44             reader = new BufferedReader(new FileReader("LTS.txt"));
45             assertTrue("Data File opened", reader != null);
46         } catch (IOException e) {
47                 e.printStackTrace();
48         }
49     
50     }
51     
52     /**
53      * Common code run after each test
54      */
55     protected void tearDown() {
56     } 
57
58
59     /**
60      * Tests to see that we succeed
61      */
62     public void testSuccess() {
63         assertTrue("Should succeed", true);
64     }
65
66
67     /**
68      * Tests that LTS generated match those from the standard results.
69      */
70     public void testLTS() {
71         String word;
72         int i;
73         String flite_phones;
74         String[] lts_phone_array;
75         StringBuffer lts_phones;
76         String line;
77         try {
78             while ((line = reader.readLine()) != null) {
79                 if (line.startsWith("***")) {
80                     continue;
81                 }
82                 i = line.indexOf(' ');
83                 word = line.substring(0,i);
84                 flite_phones = line.substring(i+1);
85                 lts_phone_array = lts.getPhones(word, null);
86                 assertTrue("Phones returned for " + word + " is not null: ",
87                            lts_phone_array != null);
88                 lts_phones = new StringBuffer("(");
89                 for (i = 0; i < lts_phone_array.length; i++) {
90                     if (i != 0) {
91                         lts_phones.append(" ");
92                     }
93                     lts_phones.append(lts_phone_array[i]);
94                 }
95                 lts_phones.append(")");
96                 assertTrue("Phones returned for " + word + " are identical "
97                            + "(Our phones: " + lts_phones + ", "
98                            + "Flite phones: " + flite_phones + "): ",
99                            flite_phones.equals(lts_phones.toString()));
100             }
101         } catch (IOException e) {
102             assertTrue("FILE IO problem: ", false);
103         }
104     }
105
106     /*
107      * Tests to see if the binary version of the database matches
108      * that of the text database.
109     public void testBinaryLoad() {
110         try {
111             LetterToSoundImpl text = new LetterToSoundImpl(
112                     new URL("file:../en/us/cmulex_lts.txt"),  false);
113             LetterToSoundImpl binary = new LetterToSoundImpl(
114                     new URL("file:../en/us/cmulex_lts.bin"),  true);
115             
116             assertTrue("text binary compare", text.compare(binary));
117         } catch (IOException ioe) {
118             fail("Can't load lts " + ioe);
119         }
120     }
121             
122     /**
123      * Factory method that creates the test suite.
124      * 
125      * @return the test suite.
126      */
127     public static Test suite() {
128         return new TestSuite(LetterToSoundTest.class);
129     } 
130
131
132
133     /**
134      * Main entry point for this test suite.
135      * 
136      * @param  args    the command line arguments.
137      */
138     public static void main(String[] args) {
139         junit.textui.TestRunner.run(suite());
140     } 
141 }