package mil.nga.geopackage.dgiwg;

import java.io.File;
import java.io.IOException;

import org.junit.Test;

import mil.nga.geopackage.BaseTestCase;
import mil.nga.geopackage.BoundingBox;
import mil.nga.geopackage.GeoPackageManager;
import mil.nga.geopackage.tiles.matrixset.TileMatrixSet;
import mil.nga.geopackage.tiles.user.TileDao;

/**
 * Test DGIWG GeoPackage methods
 * 
 * @author osbornb
 */
public class DGIWGGeoPackageTest extends BaseTestCase {

	/**
	 * Test creating tiles
	 * 
	 * @throws IOException
	 *             upon error
	 */
	@Test
	public void testCreateTiles() throws IOException {

		final String table = "dgiwg_tiles";
		final String identifier = "dgiwg identifier";
		final String description = "dgiwg description";
		final BoundingBox informativeBounds = null; // TODO
		final CoordinateReferenceSystem crs = CoordinateReferenceSystem.EPSG_3395;
		final long minZoom = 8;
		final long maxZoom = 10;
		final long matrixWidth = 3;
		final long matrixHeight = 2;

		File dbFile = new File(folder.newFolder(), GeoPackageManager
				.addExtension(DGIWGGeoPackageManagerTest.FILE_NAME));
		GeoPackageFile file = DGIWGGeoPackageManager.create(dbFile);
		DGIWGGeoPackage geoPackage = DGIWGGeoPackageManager.open(file);

		TileMatrixSet tileMatrixSet = geoPackage.createTiles(table, identifier,
				description, informativeBounds, crs);

		geoPackage.createTileMatrices(tileMatrixSet, minZoom, maxZoom,
				matrixWidth, matrixHeight);

		TileDao tileDao = geoPackage.getTileDao(tileMatrixSet);

		geoPackage.close();

	}

}

@@ -102,16 +102,49 @@
 .Test;%0A%0A
+import junit.framework.TestCase;%0A
 import m
@@ -167,32 +167,32 @@
 e.BaseTestCase;%0A
-
 import mil.nga.g
@@ -259,16 +259,149 @@
 anager;%0A
+import mil.nga.geopackage.TestUtils;%0Aimport mil.nga.geopackage.tiles.TileBoundingBoxUtils;%0Aimport mil.nga.geopackage.tiles.TileGrid;%0A
 import m
@@ -494,16 +494,62 @@
 TileDao;
+%0Aimport mil.nga.geopackage.tiles.user.TileRow;
 %0A%0A/**%0A *
@@ -994,20 +994,66 @@
  = n
-ull; // TODO
+ew BoundingBox(-8922952, 4539748,%0A%09%09%09%09-8453324, 4696291);%0A
 %0A%09%09f
@@ -1206,17 +1206,58 @@
 Width = 
-3
+TileBoundingBoxUtils.tilesPerSide(minZoom)
 ;%0A%09%09fina
@@ -1278,17 +1278,27 @@
 eight = 
-2
+matrixWidth
 ;%0A%0A%09%09Fil
@@ -1823,25 +1823,1064 @@
 %0A%0A%09%09
-geoPackage.close(
+BoundingBox bounds = tileMatrixSet.getBoundingBox();%0A%09%09TileGrid tileGrid = TileBoundingBoxUtils.getTileGrid(bounds,%0A%09%09%09%09matrixWidth, matrixHeight, informativeBounds);%0A%09%09BoundingBox tileBounds = TileBoundingBoxUtils.getBoundingBox(bounds,%0A%09%09%09%09matrixWidth, matrixHeight, tileGrid);%0A%0A%09%09for (long zoom = minZoom; zoom %3C= maxZoom; zoom++) %7B%0A%0A%09%09%09for (long row = tileGrid.getMinY(); row %3C= tileGrid%0A%09%09%09%09%09.getMaxY(); row++) %7B%0A%0A%09%09%09%09for (long column = tileGrid.getMinX(); column %3C= tileGrid%0A%09%09%09%09%09%09.getMaxX(); column++) %7B%0A%0A%09%09%09%09%09TileRow tile = tileDao.newRow();%0A%0A%09%09%09%09%09tile.setZoomLevel(zoom);%0A%09%09%09%09%09tile.setTileColumn(column);%0A%09%09%09%09%09tile.setTileRow(row);%0A%09%09%09%09%09tile.setTileData(TestUtils.getTileBytes());%0A%0A%09%09%09%09%09tileDao.create(tile);%0A%0A%09%09%09%09%7D%0A%0A%09%09%09%7D%0A%0A%09%09%09tileGrid = TileBoundingBoxUtils.tileGridZoomIncrease(tileGrid, 1);%0A%0A%09%09%7D%0A%0A%09%09for (long zoom = minZoom; zoom %3C= maxZoom; zoom++) %7B%0A%09%09%09TestCase.assertEquals(tileBounds, tileDao.getBoundingBox(zoom));%0A%09%09%7D%0A%0A%09%09geoPackage.validate();%0A%0A%09%09geoPackage.close();%0A%0A%09%09// TODO%0A%09%09// GeoPackageIOUtils.copyFile(dbFile, new File(%22temp.gpkg%22)
 );%0A%0A

create tiles test