01: /*
02: * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
03: *
04: * The program is provided "as is" without any warranty express or
05: * implied, including the warranty of non-infringement and the implied
06: * warranties of merchantibility and fitness for a particular purpose.
07: * IBM will not be liable for any damages suffered by you as a result
08: * of using the Program. In no event will IBM be liable for any
09: * special, indirect or consequential damages or lost profits even if
10: * IBM has been advised of the possibility of their occurrence. IBM
11: * will not be liable for any third party claims against you.
12: */
13: package com.ibm.richtext.textapps;
14:
15: import com.ibm.richtext.styledtext.MConstText;
16: import java.io.File;
17:
18: public final class TestMTextToString {
19:
20: static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
21:
22: public static void main(String[] args) {
23:
24: if (args.length != 2 || args[0].equals(args[1])) {
25: usage();
26: } else {
27: boolean success = testMTextToString(args[0], args[1]);
28: System.out.println(success ? "PASSED" : "FAILED");
29: }
30: }
31:
32: private static void usage() {
33:
34: System.out
35: .println("Usage: TestMTextToString mtextFile stringFile");
36: System.out
37: .println("Compares the characters in mtextFile to the");
38: System.out.println("String in stringFile.");
39: System.exit(0);
40: }
41:
42: public static boolean testMTextToString(String mtextFile,
43: String stringFile) {
44:
45: boolean success = false;
46:
47: File mtext = new File(mtextFile);
48: MConstText text = FileUtils.loadMText(mtext);
49: if (text != null) {
50: String str = StringToMText.loadString(new File(stringFile));
51: if (str != null) {
52: success = compareMTextToString(text, str);
53: } else {
54: System.out.println("Couldn't load String.");
55: }
56: } else {
57: System.out.println("Couldn't load MText.");
58: }
59:
60: return success;
61: }
62:
63: public static boolean compareMTextToString(MConstText text,
64: String str) {
65:
66: if (text.length() != str.length()) {
67: return false;
68: }
69: for (int i = str.length() - 1; i >= 0; i--) {
70: if (text.at(i) != str.charAt(i)) {
71: return false;
72: }
73: }
74: return true;
75: }
76: }
|