Skip to content
This repository has been archived by the owner on Dec 28, 2020. It is now read-only.

Commit

Permalink
Make the tests actually run
Browse files Browse the repository at this point in the history
  • Loading branch information
LB-- committed Sep 9, 2014
1 parent 4d0a125 commit 1caab9a
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 70 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,11 @@
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
19 changes: 0 additions & 19 deletions src/test/java/com/lb_stuff/mcmodify/test/LastMapId.java

This file was deleted.

38 changes: 0 additions & 38 deletions src/test/java/com/lb_stuff/mcmodify/test/MapGeneral.java

This file was deleted.

28 changes: 28 additions & 0 deletions src/test/java/com/lb_stuff/mcmodify/test/TestingUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.lb_stuff.mcmodify.test;

import java.io.File;
import java.net.URISyntaxException;

public final class TestingUtils
{
private TestingUtils()
{
throw new UnsupportedOperationException();
}

public static File getInputFile(String name)
{
try
{
return new File(TestingUtils.class.getResource("/"+name+".in").toURI());
}
catch(URISyntaxException e)
{
return null;
}
}
public static File getOutputFile(String name)
{
return new File(name+".out");
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package com.lb_stuff.mcmodify.test;
package com.lb_stuff.mcmodify.test.minecraft;

import com.lb_stuff.mcmodify.minecraft.CompressionScheme;
import com.lb_stuff.mcmodify.minecraft.Inventory;
import com.lb_stuff.mcmodify.minecraft.Level;
import com.lb_stuff.mcmodify.nbt.Tag;
import com.lb_stuff.mcmodify.test.TestingUtils;

import static com.lb_stuff.mcmodify.minecraft.IDs.WrittenBook;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileOutputStream;

public class LevelGeneral
public class LevelTest
{
public static void main(String[] args) throws Throwable
@Test
public void general() throws Throwable
{
final Level level;
try(FileInputStream fis = new FileInputStream("level.dat.in"))
try(FileInputStream fis = new FileInputStream(TestingUtils.getInputFile("level.dat")))
{
level = new Level((Tag.Compound)Tag.deserialize(CompressionScheme.GZip.getInputStream(fis)));
}
Expand All @@ -29,7 +33,7 @@ public static void main(String[] args) throws Throwable
item.EnchantLevel(Inventory.Item.Enchantment.FireAspect, (short)2);
i.Item(7, item);

try(FileOutputStream fos = new FileOutputStream("level.dat.out"))
try(FileOutputStream fos = new FileOutputStream(TestingUtils.getOutputFile("level.dat")))
{
level.ToNBT("").serialize(CompressionScheme.GZip.getOutputStream(fos));
}
Expand Down
51 changes: 51 additions & 0 deletions src/test/java/com/lb_stuff/mcmodify/test/minecraft/MapTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.lb_stuff.mcmodify.test.minecraft;

import com.lb_stuff.mcmodify.minecraft.CompressionScheme;
import com.lb_stuff.mcmodify.minecraft.Map;
import com.lb_stuff.mcmodify.nbt.Tag;
import com.lb_stuff.mcmodify.test.TestingUtils;

import javax.imageio.ImageIO;
import org.junit.Test;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

public class MapTest
{
@Test
public void printLastMapId() throws Throwable
{
Tag.Compound idcounts;
try(FileInputStream fis = new FileInputStream(TestingUtils.getInputFile("idcounts.dat")))
{
idcounts = (Tag.Compound)Tag.deserialize(CompressionScheme.None.getInputStream(fis));
}
System.out.println("Last created map number: "+((Tag.Short)idcounts.find(Tag.Type.SHORT, "map")).v);
}
@Test
public void editMapImage() throws Throwable
{
final Map map;
try(FileInputStream fis = new FileInputStream(TestingUtils.getInputFile("map.dat")))
{
map = new Map((Tag.Compound)Tag.deserialize(CompressionScheme.GZip.getInputStream(fis)));
}

BufferedImage mapimage = map.Image();
ImageIO.write(mapimage, "png", TestingUtils.getOutputFile("map.png"));

Graphics2D g = mapimage.createGraphics();
g.setColor(Color.red);
g.drawString("My Minecraft Map", 16, 16);

try(FileOutputStream fos = new FileOutputStream(TestingUtils.getOutputFile("map.dat")))
{
map.ToNBT("").serialize(CompressionScheme.GZip.getOutputStream(fos));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package com.lb_stuff.mcmodify.test;
package com.lb_stuff.mcmodify.test.minecraft;

import com.lb_stuff.mcmodify.minecraft.Chunk;
import com.lb_stuff.mcmodify.minecraft.FileRegion;
import com.lb_stuff.mcmodify.minecraft.Mob;
import com.lb_stuff.mcmodify.test.TestingUtils;

import org.junit.Test;

import java.io.File;

public class ModifyEveryChunkInRegion
public class RegionTest
{
public static void main(String[] args) throws Throwable
@Test
public void modifyEveryChunk() throws Throwable
{
FileRegion region = new FileRegion(new File("r.0.0.mca.in"));
FileRegion newregion = new FileRegion(new File("r.0.0.mca.out"));
FileRegion region = new FileRegion(TestingUtils.getInputFile("r.0.0.mca"));
FileRegion newregion = new FileRegion(TestingUtils.getOutputFile("r.0.0.mca"));
for(int x = 0; x < 31; ++x)
{
for(int z = 0; z < 31; ++z)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package com.lb_stuff.mcmodify.test;
package com.lb_stuff.mcmodify.test.nbt;

import com.lb_stuff.mcmodify.minecraft.CompressionScheme;
import com.lb_stuff.mcmodify.nbt.Tag;

import org.junit.Test;

import java.io.FileInputStream;
import java.io.FileOutputStream;

public class ManualTimeAdjust
public class TagTests
{
public static void main(String[] args) throws Throwable
@Test
public void manualTimeAdjust() throws Throwable
{
final Tag.Compound level;
try(FileInputStream fis = new FileInputStream("level.dat.in"))
Expand Down

0 comments on commit 1caab9a

Please sign in to comment.