poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1207422 - in /poi/trunk/src: java/org/apache/poi/poifs/filesystem/EntryUtils.java testcases/org/apache/poi/poifs/filesystem/TestEntryUtils.java
Date Mon, 28 Nov 2011 16:51:07 GMT
Author: nick
Date: Mon Nov 28 16:51:06 2011
New Revision: 1207422

URL: http://svn.apache.org/viewvc?rev=1207422&view=rev
Log:
Add unit test for using FilteringDirectoryNode with EntryUtils.areDirectoriesIdentical

Modified:
    poi/trunk/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java
    poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestEntryUtils.java

Modified: poi/trunk/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java?rev=1207422&r1=1207421&r2=1207422&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java (original)
+++ poi/trunk/src/java/org/apache/poi/poifs/filesystem/EntryUtils.java Mon Nov 28 16:51:06
2011
@@ -104,8 +104,9 @@ public class EntryUtils
      * Checks to see if the two Directories hold the same contents.
      * For this to be true, they must have entries with the same names,
      *  no entries in one but not the other, and the size+contents
-     *  of each entry must match, and they must share names
-     * TODO Some sort of excepts support
+     *  of each entry must match, and they must share names.
+     * To exclude certain parts of the Directory from being checked,
+     *  use a {@link FilteringDirectoryNode}
      */
     public static boolean areDirectoriesIdentical(DirectoryEntry dirA, DirectoryEntry dirB)
{
        // First, check names
@@ -162,10 +163,10 @@ public class EntryUtils
              boolean match;
              if (a.isDirectoryEntry()) {
                 match = areDirectoriesIdentical(
-                      (DirectoryNode)a, (DirectoryNode)b);
+                      (DirectoryEntry)a, (DirectoryEntry)b);
              } else {
                 match = areDocumentsIdentical(
-                      (DocumentNode)a, (DocumentNode)b);
+                      (DocumentEntry)a, (DocumentEntry)b);
              }
              if (!match) return false;
           } catch(FileNotFoundException e) {

Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestEntryUtils.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestEntryUtils.java?rev=1207422&r1=1207421&r2=1207422&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestEntryUtils.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestEntryUtils.java Mon Nov 28
16:51:06 2011
@@ -20,13 +20,12 @@ package org.apache.poi.poifs.filesystem;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 
 import junit.framework.TestCase;
 
-import org.apache.poi.POIDataSamples;
-
 public class TestEntryUtils extends TestCase {
-    private static final POIDataSamples dataSamples = POIDataSamples.getPOIFSInstance();
     private byte[] dataSmallA = new byte[] { 12, 42, 11, -12, -121 };
     private byte[] dataSmallB = new byte[] { 11, 73, 21, -92, -103 };
 
@@ -160,6 +159,33 @@ public class TestEntryUtils extends Test
        assertEquals(true, EntryUtils.areDirectoriesIdentical(dirA1, dirB1));
        
        
-       // TODO Excludes support
+       // Excludes support
+       List<String> excl = Arrays.asList(new String[] {"Ignore1", "IgnDir/Ign2"});
+       FilteringDirectoryNode fdA = new FilteringDirectoryNode(dirA1, excl);
+       FilteringDirectoryNode fdB = new FilteringDirectoryNode(dirB1, excl);
+       
+       assertEquals(true, EntryUtils.areDirectoriesIdentical(fdA, fdB));
+       
+       // Add an ignored doc, no notice is taken
+       fdA.createDocument("Ignore1", new ByteArrayInputStream(dataSmallA));
+       assertEquals(true, EntryUtils.areDirectoriesIdentical(fdA, fdB));
+       
+       // Add a directory with filtered contents, not the same
+       DirectoryEntry dirAI = dirA1.createDirectory("IgnDir");
+       assertEquals(false, EntryUtils.areDirectoriesIdentical(fdA, fdB));
+       
+       DirectoryEntry dirBI = dirB1.createDirectory("IgnDir");
+       assertEquals(true, EntryUtils.areDirectoriesIdentical(fdA, fdB));
+       
+       // Add something to the filtered subdir that gets ignored
+       dirAI.createDocument("Ign2", new ByteArrayInputStream(dataSmallA));
+       assertEquals(true, EntryUtils.areDirectoriesIdentical(fdA, fdB));
+       
+       // And something that doesn't
+       dirAI.createDocument("IgnZZ", new ByteArrayInputStream(dataSmallA));
+       assertEquals(false, EntryUtils.areDirectoriesIdentical(fdA, fdB));
+       
+       dirBI.createDocument("IgnZZ", new ByteArrayInputStream(dataSmallA));
+       assertEquals(true, EntryUtils.areDirectoriesIdentical(fdA, fdB));
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message