Esempio n. 1
0
  public static void compareMapFiles(MapLoader expectedSavegame, MapLoader actualSavegame)
      throws IOException, MapLoadException, ClassNotFoundException {
    System.out.println(
        "Comparing expected '"
            + expectedSavegame
            + "' with actual '"
            + actualSavegame
            + "' (uncompressed!)");

    try (InputStream expectedStream =
            RemakeMapLoader.getMapInputStream(expectedSavegame.getListedMap());
        CountingInputStream actualStream =
            new CountingInputStream(
                RemakeMapLoader.getMapInputStream(actualSavegame.getListedMap()))) {
      MapFileHeader expectedHeader = MapFileHeader.readFromStream(expectedStream);
      MatchConstants.init(new NetworkTimer(true), 0L);
      MatchConstants.deserialize(new ObjectInputStream(expectedStream));
      int expectedTime = MatchConstants.clock().getTime();
      ExtendedRandom expectedRandom = MatchConstants.random();
      MatchConstants.clearState();

      MapFileHeader actualHeader = MapFileHeader.readFromStream(actualStream);
      MatchConstants.init(new NetworkTimer(true), 1L);
      MatchConstants.deserialize(new ObjectInputStream(actualStream));
      int actualTime = MatchConstants.clock().getTime();
      ExtendedRandom actualRandom = MatchConstants.random();
      MatchConstants.clearState();

      assertEquals(expectedHeader.getBaseMapId(), actualHeader.getBaseMapId());
      assertEquals(expectedTime, actualTime);
      // Test the random behavior a bit to have a high probability of equality. An equals method
      // does not exist for Random.
      assertEquals(expectedRandom.nextInt(), actualRandom.nextInt());
      assertEquals(expectedRandom.nextInt(), actualRandom.nextInt());
      assertEquals(expectedRandom.nextInt(), actualRandom.nextInt());

      int e, a;
      while (((e = expectedStream.read()) != -1) & ((a = actualStream.read()) != -1)) {
        assertEquals("difference at (uncompressed) byte " + actualStream.getByteCounter(), e, a);
      }
      assertEquals("files have different lengths (uncompressed)", e, a);
    }
  }