001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.poifs.filesystem;
019:
020: import junit.framework.*;
021:
022: /**
023: * Class to test DocumentDescriptor functionality
024: *
025: * @author Marc Johnson
026: */
027:
028: public class TestDocumentDescriptor extends TestCase {
029:
030: /**
031: * Constructor TestDocumentDescriptor
032: *
033: * @param name
034: */
035:
036: public TestDocumentDescriptor(String name) {
037: super (name);
038: }
039:
040: /**
041: * test equality
042: */
043:
044: public void testEquality() {
045: String[] names = { "c1", "c2", "c3", "c4", "c5" };
046: POIFSDocumentPath a1 = new POIFSDocumentPath();
047: POIFSDocumentPath a2 = new POIFSDocumentPath(null);
048: POIFSDocumentPath a3 = new POIFSDocumentPath(new String[0]);
049: POIFSDocumentPath a4 = new POIFSDocumentPath(a1, null);
050: POIFSDocumentPath a5 = new POIFSDocumentPath(a1, new String[0]);
051: POIFSDocumentPath[] paths = { a1, a2, a3, a4, a5 };
052:
053: for (int j = 0; j < paths.length; j++) {
054: for (int k = 0; k < paths.length; k++) {
055: for (int m = 0; m < names.length; m++) {
056: DocumentDescriptor d1 = new DocumentDescriptor(
057: paths[j], names[m]);
058:
059: for (int n = 0; n < names.length; n++) {
060: DocumentDescriptor d2 = new DocumentDescriptor(
061: paths[k], names[n]);
062:
063: if (m == n) {
064: assertEquals("" + j + "," + k + "," + m
065: + "," + n, d1, d2);
066: } else {
067: assertTrue("" + j + "," + k + "," + m + ","
068: + n, !d1.equals(d2));
069: }
070: }
071: }
072: }
073: }
074: a2 = new POIFSDocumentPath(a1, new String[] { "foo" });
075: a3 = new POIFSDocumentPath(a2, new String[] { "bar" });
076: a4 = new POIFSDocumentPath(a3, new String[] { "fubar" });
077: a5 = new POIFSDocumentPath(a4, new String[] { "foobar" });
078: POIFSDocumentPath[] builtUpPaths = { a1, a2, a3, a4, a5 };
079: POIFSDocumentPath[] fullPaths = {
080: new POIFSDocumentPath(),
081: new POIFSDocumentPath(new String[] { "foo" }),
082: new POIFSDocumentPath(new String[] { "foo", "bar" }),
083: new POIFSDocumentPath(new String[] { "foo", "bar",
084: "fubar" }),
085: new POIFSDocumentPath(new String[] { "foo", "bar",
086: "fubar", "foobar" }) };
087:
088: for (int k = 0; k < builtUpPaths.length; k++) {
089: for (int j = 0; j < fullPaths.length; j++) {
090: for (int m = 0; m < names.length; m++) {
091: DocumentDescriptor d1 = new DocumentDescriptor(
092: fullPaths[j], names[m]);
093:
094: for (int n = 0; n < names.length; n++) {
095: DocumentDescriptor d2 = new DocumentDescriptor(
096: builtUpPaths[k], names[n]);
097:
098: if ((k == j) && (m == n)) {
099: assertEquals("" + j + "," + k + "," + m
100: + "," + n, d1, d2);
101: } else {
102: assertTrue("" + j + "," + k + "," + m + ","
103: + n, !(d1.equals(d2)));
104: }
105: }
106: }
107: }
108: }
109: POIFSDocumentPath[] badPaths = {
110: new POIFSDocumentPath(new String[] { "_foo" }),
111: new POIFSDocumentPath(new String[] { "foo", "_bar" }),
112: new POIFSDocumentPath(new String[] { "foo", "bar",
113: "_fubar" }),
114: new POIFSDocumentPath(new String[] { "foo", "bar",
115: "fubar", "_foobar" }) };
116:
117: for (int k = 0; k < builtUpPaths.length; k++) {
118: for (int j = 0; j < badPaths.length; j++) {
119: for (int m = 0; m < names.length; m++) {
120: DocumentDescriptor d1 = new DocumentDescriptor(
121: badPaths[j], names[m]);
122:
123: for (int n = 0; n < names.length; n++) {
124: DocumentDescriptor d2 = new DocumentDescriptor(
125: builtUpPaths[k], names[n]);
126:
127: assertTrue(
128: "" + j + "," + k + "," + m + "," + n,
129: !(d1.equals(d2)));
130: }
131: }
132: }
133: }
134: }
135:
136: /**
137: * main method to run the unit tests
138: *
139: * @param ignored_args
140: */
141:
142: public static void main(String[] ignored_args) {
143: System.out
144: .println("Testing org.apache.poi.poifs.eventfilesystem.DocumentDescriptor");
145: junit.textui.TestRunner.run(TestDocumentDescriptor.class);
146: }
147: }
|