View Javadoc
1   package com.healthmarketscience.jackcess.impl;
2   
3   import java.io.File;
4   import java.io.IOException;
5   
6   import com.healthmarketscience.jackcess.Database;
7   import com.healthmarketscience.jackcess.DatabaseBuilder;
8   import static com.healthmarketscience.jackcess.impl.JetFormatTest.*;
9   import junit.framework.TestCase;
10  
11  /**
12   * @author Dan Rollo
13   *         Date: Mar 5, 2010
14   *         Time: 2:21:22 PM
15   */
16  public final class UsageMapTest extends TestCase {
17  
18      public void testRead() throws Exception {
19          for (final TestDB testDB : SUPPORTED_DBS_TEST) {
20              final int expectedFirstPage;
21              final int expectedLastPage;
22              final Database.FileFormat expectedFileFormat = testDB.getExpectedFileFormat();
23              if (Database.FileFormat.V2000.equals(expectedFileFormat)) {
24                  expectedFirstPage = 743;
25                  expectedLastPage = 767;
26              } else if (Database.FileFormat.V2003.equals(expectedFileFormat)) {
27                  expectedFirstPage = 16;
28                  expectedLastPage = 799;
29              } else if (Database.FileFormat.V2007.equals(expectedFileFormat)) {
30                  expectedFirstPage = 94;
31                  expectedLastPage = 511;
32              } else if (Database.FileFormat.V2010.equals(expectedFileFormat)) {
33                  expectedFirstPage = 109;
34                  expectedLastPage = 511;
35              } else {
36                  throw new IllegalAccessException("Unknown file format: " + expectedFileFormat);
37              }
38              checkUsageMapRead(testDB.getFile(), expectedFirstPage, expectedLastPage);
39          }
40      }
41  
42      private static void checkUsageMapRead(final File dbFile,
43                                            final int expectedFirstPage, final int expectedLastPage)
44              throws IOException {
45  
46          final Database db = DatabaseBuilder.open(dbFile);
47          final UsageMap usageMap = UsageMap.read((DatabaseImpl)db,
48                  PageChannel.PAGE_GLOBAL_USAGE_MAP,
49                  PageChannel.ROW_GLOBAL_USAGE_MAP,
50                  true);
51          assertEquals("Unexpected FirstPageNumber.", expectedFirstPage, usageMap.getFirstPageNumber());
52          assertEquals("Unexpected LastPageNumber.", expectedLastPage, usageMap.getLastPageNumber());
53      }
54  }