Search in sources :

Example 1 with MapBlock

use of uk.me.parabola.imgfmt.mps.MapBlock in project mkgmap by openstreetmap.

the class GmapsuppTest method testDifferentFamilies.

/**
 * Test the case where we are combining img files with different family
 * and product ids.
 */
@Test
public void testDifferentFamilies() throws IOException {
    Main.mainNoSystemExit(Args.TEST_STYLE_ARG, "--gmapsupp", "--family-id=101", "--product-id=1", "--series-name=tst series1", Args.TEST_RESOURCE_IMG + "63240001.img", "--family-id=102", "--product-id=2", "--series-name=tst series2", Args.TEST_RESOURCE_IMG + "63240002.img");
    MpsFileReader reader = getMpsFile();
    List<MapBlock> list = reader.getMaps();
    reader.close();
    assertEquals("number of map blocks", 2, list.size());
    // Directly check the family id's
    assertEquals("family in map1", 101, list.get(0).getFamilyId());
    assertEquals("family in map2", 102, list.get(1).getFamilyId());
    // Check more things
    int count = 0;
    for (MapBlock map : list) {
        count++;
        assertEquals("family in map" + count, 100 + count, map.getFamilyId());
        assertEquals("product in map" + count, count, map.getProductId());
        assertEquals("series name in map" + count, "tst series" + count, map.getSeriesName());
    }
}
Also used : MapBlock(uk.me.parabola.imgfmt.mps.MapBlock) MpsFileReader(uk.me.parabola.imgfmt.mps.MpsFileReader) Test(org.junit.Test)

Example 2 with MapBlock

use of uk.me.parabola.imgfmt.mps.MapBlock in project mkgmap by openstreetmap.

the class GmapsuppTest method testMpsFile.

/**
 * Check the values inside the MPS file, when the family id etc is
 * common to all files.
 */
@Test
public void testMpsFile() throws IOException {
    Main.mainNoSystemExit(Args.TEST_STYLE_ARG, "--gmapsupp", "--family-id=150", "--product-id=24", "--series-name=tst series", "--family-name=tst family", "--area-name=tst area", Args.TEST_RESOURCE_IMG + "63240001.img", Args.TEST_RESOURCE_IMG + "63240002.img");
    MpsFileReader reader = getMpsFile();
    List<MapBlock> list = reader.getMaps();
    reader.close();
    assertEquals("number of map blocks", 2, list.size());
    // All maps will have the same parameters apart from map name here
    int count = 0;
    for (MapBlock map : list) {
        assertEquals("map number", 63240001 + count++, map.getMapNumber());
        assertEquals("family id", 150, map.getFamilyId());
        assertEquals("product id", 24, map.getProductId());
        assertEquals("series name", "tst series", map.getSeriesName());
        assertEquals("area name", "tst area", map.getAreaName());
        assertEquals("map description", "uk test " + count, map.getMapDescription());
    }
}
Also used : MapBlock(uk.me.parabola.imgfmt.mps.MapBlock) MpsFileReader(uk.me.parabola.imgfmt.mps.MpsFileReader) Test(org.junit.Test)

Example 3 with MapBlock

use of uk.me.parabola.imgfmt.mps.MapBlock in project mkgmap by openstreetmap.

the class FileCopier method makeMapBlock.

private MapBlock makeMapBlock(FileInfo info) {
    MapBlock mb = new MapBlock(info.getCodePage());
    mb.setMapNumber(info.getMapnameAsInt());
    mb.setHexNumber(info.getHexname());
    mb.setMapDescription(info.getDescription());
    mb.setAreaName(areaName != null ? areaName : "Area " + info.getMapname());
    mb.setSeriesName(info.getSeriesName());
    mb.setIds(info.getFamilyId(), info.getProductId());
    return mb;
}
Also used : MapBlock(uk.me.parabola.imgfmt.mps.MapBlock)

Example 4 with MapBlock

use of uk.me.parabola.imgfmt.mps.MapBlock in project mkgmap by openstreetmap.

the class GmapsuppTest method testCombiningSupps.

/**
 * Test combining gmapsupp files.  The family id etc should be taken from
 * the MPS file in the gmapsupp.
 */
@Test
public void testCombiningSupps() throws IOException {
    TestUtils.registerFile("g1.img", "g2.img");
    Main.mainNoSystemExit(Args.TEST_STYLE_ARG, "--gmapsupp", "--family-id=150", "--product-id=24", "--series-name=tst series", "--family-name=tst family", "--area-name=tst area", Args.TEST_RESOURCE_IMG + "63240001.img");
    File f = new File("gmapsupp.img");
    f.renameTo(new File("g1.img"));
    Main.mainNoSystemExit(Args.TEST_STYLE_ARG, "--gmapsupp", "--family-id=152", "--product-id=26", "--series-name=tst series 2", "--family-name=tst family 2", "--area-name=tst area 2", Args.TEST_RESOURCE_IMG + "63240002.img");
    f.renameTo(new File("g2.img"));
    Main.mainNoSystemExit(Args.TEST_STYLE_ARG, "--gmapsupp", "g1.img", "g2.img");
    MpsFileReader reader = getMpsFile();
    List<MapBlock> list = reader.getMaps();
    assertEquals("number of map blocks", 2, list.size());
    for (MapBlock map : list) {
        if (map.getMapNumber() == 63240001) {
            assertEquals("family id", 150, map.getFamilyId());
            assertEquals("product id", 24, map.getProductId());
            assertEquals("series name", "tst series", map.getSeriesName());
            assertEquals("area name", "tst area", map.getAreaName());
            assertEquals("hex name", 63240001, map.getHexNumber());
            assertEquals("map description", "uk test 1", map.getMapDescription());
        } else if (map.getMapNumber() == 63240002) {
            assertEquals("family id", 152, map.getFamilyId());
            assertEquals("product id", 26, map.getProductId());
            assertEquals("series name", "tst series 2", map.getSeriesName());
            assertEquals("area name", "tst area 2", map.getAreaName());
            assertEquals("hex name", 63240002, map.getHexNumber());
            assertEquals("map description", "uk test 2", map.getMapDescription());
        } else {
            assertTrue("Unexpected map found", false);
        }
    }
}
Also used : MapBlock(uk.me.parabola.imgfmt.mps.MapBlock) File(java.io.File) MpsFileReader(uk.me.parabola.imgfmt.mps.MpsFileReader) Test(org.junit.Test)

Example 5 with MapBlock

use of uk.me.parabola.imgfmt.mps.MapBlock in project mkgmap by openstreetmap.

the class FileCopier method addMpsFile.

/**
 * Add a complete pre-existing mps file to the mps file we are currently
 * building for this gmapsupp.
 * @param info The details of the gmapsupp file that we need to extract the
 */
private void addMpsFile(FileInfo info) {
    String name = info.getFilename();
    try (FileSystem fs = ImgFS.openFs(name)) {
        MpsFileReader mr = new MpsFileReader(fs.open(info.getMpsName(), "r"), info.getCodePage());
        for (MapBlock block : mr.getMaps()) mpsFile.addMap(block);
        for (ProductBlock b : mr.getProducts()) mpsFile.addProduct(b);
        mr.close();
    } catch (IOException e) {
        log.error("Could not read MPS file from gmapsupp", e);
    }
}
Also used : ProductBlock(uk.me.parabola.imgfmt.mps.ProductBlock) FileSystem(uk.me.parabola.imgfmt.fs.FileSystem) MapBlock(uk.me.parabola.imgfmt.mps.MapBlock) IOException(java.io.IOException) MpsFileReader(uk.me.parabola.imgfmt.mps.MpsFileReader)

Aggregations

MapBlock (uk.me.parabola.imgfmt.mps.MapBlock)5 MpsFileReader (uk.me.parabola.imgfmt.mps.MpsFileReader)4 Test (org.junit.Test)3 File (java.io.File)1 IOException (java.io.IOException)1 FileSystem (uk.me.parabola.imgfmt.fs.FileSystem)1 ProductBlock (uk.me.parabola.imgfmt.mps.ProductBlock)1