KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > poifs > filesystem > TestDocumentDescriptor


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16 ==================================================================== */

17         
18
19 package org.apache.poi.poifs.filesystem;
20
21 import junit.framework.*;
22
23 /**
24  * Class to test DocumentDescriptor functionality
25  *
26  * @author Marc Johnson
27  */

28
29 public class TestDocumentDescriptor
30     extends TestCase
31 {
32
33     /**
34      * Constructor TestDocumentDescriptor
35      *
36      * @param name
37      */

38
39     public TestDocumentDescriptor(String JavaDoc name)
40     {
41         super(name);
42     }
43
44     /**
45      * test equality
46      */

47
48     public void testEquality()
49     {
50         String JavaDoc[] names =
51         {
52             "c1", "c2", "c3", "c4", "c5"
53         };
54         POIFSDocumentPath a1 = new POIFSDocumentPath();
55         POIFSDocumentPath a2 = new POIFSDocumentPath(null);
56         POIFSDocumentPath a3 = new POIFSDocumentPath(new String JavaDoc[ 0 ]);
57         POIFSDocumentPath a4 = new POIFSDocumentPath(a1, null);
58         POIFSDocumentPath a5 = new POIFSDocumentPath(a1,
59                                         new String JavaDoc[ 0 ]);
60         POIFSDocumentPath[] paths =
61         {
62             a1, a2, a3, a4, a5
63         };
64
65         for (int j = 0; j < paths.length; j++)
66         {
67             for (int k = 0; k < paths.length; k++)
68             {
69                 for (int m = 0; m < names.length; m++)
70                 {
71                     DocumentDescriptor d1 = new DocumentDescriptor(paths[ j ],
72                                                 names[ m ]);
73
74                     for (int n = 0; n < names.length; n++)
75                     {
76                         DocumentDescriptor d2 =
77                             new DocumentDescriptor(paths[ k ], names[ n ]);
78
79                         if (m == n)
80                         {
81                             assertEquals("" + j + "," + k + "," + m + ","
82                                          + n, d1, d2);
83                         }
84                         else
85                         {
86                             assertTrue("" + j + "," + k + "," + m + "," + n,
87                                        !d1.equals(d2));
88                         }
89                     }
90                 }
91             }
92         }
93         a2 = new POIFSDocumentPath(a1, new String JavaDoc[]
94         {
95             "foo"
96         });
97         a3 = new POIFSDocumentPath(a2, new String JavaDoc[]
98         {
99             "bar"
100         });
101         a4 = new POIFSDocumentPath(a3, new String JavaDoc[]
102         {
103             "fubar"
104         });
105         a5 = new POIFSDocumentPath(a4, new String JavaDoc[]
106         {
107             "foobar"
108         });
109         POIFSDocumentPath[] builtUpPaths =
110         {
111             a1, a2, a3, a4, a5
112         };
113         POIFSDocumentPath[] fullPaths =
114         {
115             new POIFSDocumentPath(), new POIFSDocumentPath(new String JavaDoc[]
116             {
117                 "foo"
118             }), new POIFSDocumentPath(new String JavaDoc[]
119             {
120                 "foo", "bar"
121             }), new POIFSDocumentPath(new String JavaDoc[]
122             {
123                 "foo", "bar", "fubar"
124             }), new POIFSDocumentPath(new String JavaDoc[]
125             {
126                 "foo", "bar", "fubar", "foobar"
127             })
128         };
129
130         for (int k = 0; k < builtUpPaths.length; k++)
131         {
132             for (int j = 0; j < fullPaths.length; j++)
133             {
134                 for (int m = 0; m < names.length; m++)
135                 {
136                     DocumentDescriptor d1 =
137                         new DocumentDescriptor(fullPaths[ j ], names[ m ]);
138
139                     for (int n = 0; n < names.length; n++)
140                     {
141                         DocumentDescriptor d2 =
142                             new DocumentDescriptor(builtUpPaths[ k ],
143                                                    names[ n ]);
144
145                         if ((k == j) && (m == n))
146                         {
147                             assertEquals("" + j + "," + k + "," + m + ","
148                                          + n, d1, d2);
149                         }
150                         else
151                         {
152                             assertTrue("" + j + "," + k + "," + m + "," + n,
153                                        !(d1.equals(d2)));
154                         }
155                     }
156                 }
157             }
158         }
159         POIFSDocumentPath[] badPaths =
160         {
161             new POIFSDocumentPath(new String JavaDoc[]
162             {
163                 "_foo"
164             }), new POIFSDocumentPath(new String JavaDoc[]
165             {
166                 "foo", "_bar"
167             }), new POIFSDocumentPath(new String JavaDoc[]
168             {
169                 "foo", "bar", "_fubar"
170             }), new POIFSDocumentPath(new String JavaDoc[]
171             {
172                 "foo", "bar", "fubar", "_foobar"
173             })
174         };
175
176         for (int k = 0; k < builtUpPaths.length; k++)
177         {
178             for (int j = 0; j < badPaths.length; j++)
179             {
180                 for (int m = 0; m < names.length; m++)
181                 {
182                     DocumentDescriptor d1 =
183                         new DocumentDescriptor(badPaths[ j ], names[ m ]);
184
185                     for (int n = 0; n < names.length; n++)
186                     {
187                         DocumentDescriptor d2 =
188                             new DocumentDescriptor(builtUpPaths[ k ],
189                                                    names[ n ]);
190
191                         assertTrue("" + j + "," + k + "," + m + "," + n,
192                                    !(d1.equals(d2)));
193                     }
194                 }
195             }
196         }
197     }
198
199     /**
200      * main method to run the unit tests
201      *
202      * @param ignored_args
203      */

204
205     public static void main(String JavaDoc [] ignored_args)
206     {
207         System.out.println(
208             "Testing org.apache.poi.poifs.eventfilesystem.DocumentDescriptor");
209         junit.textui.TestRunner.run(TestDocumentDescriptor.class);
210     }
211 }
212
Popular Tags