Skip to content

Commit

Permalink
Texture write tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JoopAue committed Mar 24, 2016
1 parent cae204a commit e180bfe
Show file tree
Hide file tree
Showing 4 changed files with 307 additions and 2 deletions.
Empty file modified jme3-core/src/main/java/com/jme3/texture/Texture.java
100644 → 100755
Empty file.
29 changes: 29 additions & 0 deletions jme3-core/src/test/java/com/jme3/texture/TestExporter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.jme3.texture;

import com.jme3.export.JmeExporter;
import com.jme3.export.OutputCapsule;
import com.jme3.export.Savable;

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

import static org.mockito.Mockito.spy;

public class TestExporter implements JmeExporter {

@Override
public void save(Savable object, OutputStream f) throws IOException {

}

@Override
public void save(Savable object, File f) throws IOException {

}

@Override
public OutputCapsule getCapsule(Savable object) {
return spy(new TestOutputCapsule());
}
}
222 changes: 222 additions & 0 deletions jme3-core/src/test/java/com/jme3/texture/TestOutputCapsule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
package com.jme3.texture;

import com.jme3.export.OutputCapsule;
import com.jme3.export.Savable;
import com.jme3.util.IntMap;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Map;

public class TestOutputCapsule implements OutputCapsule {

@Override
public void write(byte value, String name, byte defVal) throws IOException {

}

@Override
public void write(byte[] value, String name, byte[] defVal) throws IOException {

}

@Override
public void write(byte[][] value, String name, byte[][] defVal) throws IOException {

}

@Override
public void write(int value, String name, int defVal) throws IOException {

}

@Override
public void write(int[] value, String name, int[] defVal) throws IOException {

}

@Override
public void write(int[][] value, String name, int[][] defVal) throws IOException {

}

@Override
public void write(float value, String name, float defVal) throws IOException {

}

@Override
public void write(float[] value, String name, float[] defVal) throws IOException {

}

@Override
public void write(float[][] value, String name, float[][] defVal) throws IOException {

}

@Override
public void write(double value, String name, double defVal) throws IOException {

}

@Override
public void write(double[] value, String name, double[] defVal) throws IOException {

}

@Override
public void write(double[][] value, String name, double[][] defVal) throws IOException {

}

@Override
public void write(long value, String name, long defVal) throws IOException {

}

@Override
public void write(long[] value, String name, long[] defVal) throws IOException {

}

@Override
public void write(long[][] value, String name, long[][] defVal) throws IOException {

}

@Override
public void write(short value, String name, short defVal) throws IOException {

}

@Override
public void write(short[] value, String name, short[] defVal) throws IOException {

}

@Override
public void write(short[][] value, String name, short[][] defVal) throws IOException {

}

@Override
public void write(boolean value, String name, boolean defVal) throws IOException {

}

@Override
public void write(boolean[] value, String name, boolean[] defVal) throws IOException {

}

@Override
public void write(boolean[][] value, String name, boolean[][] defVal) throws IOException {

}

@Override
public void write(String value, String name, String defVal) throws IOException {

}

@Override
public void write(String[] value, String name, String[] defVal) throws IOException {

}

@Override
public void write(String[][] value, String name, String[][] defVal) throws IOException {

}

@Override
public void write(BitSet value, String name, BitSet defVal) throws IOException {

}

@Override
public void write(Savable object, String name, Savable defVal) throws IOException {

}

@Override
public void write(Savable[] objects, String name, Savable[] defVal) throws IOException {

}

@Override
public void write(Savable[][] objects, String name, Savable[][] defVal) throws IOException {

}

@Override
public void writeSavableArrayList(ArrayList array, String name, ArrayList defVal) throws IOException {

}

@Override
public void writeSavableArrayListArray(ArrayList[] array, String name, ArrayList[] defVal) throws IOException {

}

@Override
public void writeSavableArrayListArray2D(ArrayList[][] array, String name, ArrayList[][] defVal) throws IOException {

}

@Override
public void writeFloatBufferArrayList(ArrayList<FloatBuffer> array, String name, ArrayList<FloatBuffer> defVal) throws IOException {

}

@Override
public void writeByteBufferArrayList(ArrayList<ByteBuffer> array, String name, ArrayList<ByteBuffer> defVal) throws IOException {

}

@Override
public void writeSavableMap(Map<? extends Savable, ? extends Savable> map, String name, Map<? extends Savable, ? extends Savable> defVal) throws IOException {

}

@Override
public void writeStringSavableMap(Map<String, ? extends Savable> map, String name, Map<String, ? extends Savable> defVal) throws IOException {

}

@Override
public void writeIntSavableMap(IntMap<? extends Savable> map, String name, IntMap<? extends Savable> defVal) throws IOException {

}

@Override
public void write(FloatBuffer value, String name, FloatBuffer defVal) throws IOException {

}

@Override
public void write(IntBuffer value, String name, IntBuffer defVal) throws IOException {

}

@Override
public void write(ByteBuffer value, String name, ByteBuffer defVal) throws IOException {

}

@Override
public void write(ShortBuffer value, String name, ShortBuffer defVal) throws IOException {

}

@Override
public void write(Enum value, String name, Enum defVal) throws IOException {

}
}
58 changes: 56 additions & 2 deletions jme3-core/src/test/java/com/jme3/texture/TextureTest.java
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
package com.jme3.texture;

import com.jme3.asset.AssetKey;
import com.jme3.asset.TextureKey;
import com.jme3.export.JmeExporter;
import com.jme3.export.OutputCapsule;
import com.jme3.export.Savable;
import com.jme3.export.binary.BinaryExporter;
import com.jme3.util.IntMap;
import org.junit.Before;
import org.junit.Test;

import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Mockito.*;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Map;

import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.*;

public class TextureTest {
private Texture tex;
Expand Down Expand Up @@ -84,6 +109,35 @@ public void testGetWrapSetOneAxisT() {
tex.setWrap(wrapAxis, wrapMode);
assert tex.getWrap(wrapAxis) == wrapMode;
}
@Test
public void testWriteNoKey() throws IOException {
JmeExporter e = spy(new TestExporter());
OutputCapsule o = spy(new TestOutputCapsule());
when(e.getCapsule(any(Texture.class))).thenReturn(o);

tex.write(e);

verify(o, times(1)).write(isNull(String.class), eq("name"), isNull(String.class));
verify(o, times(1)).write(any(Savable.class), eq("image"), isNull(Savable.class));
verify(o, times(1)).write(anyInt(), eq("anisotropicFilter"), eq(1));
verify(o, times(1)).write(any(Enum.class), eq("minificationFilter"), eq(Texture.MinFilter.BilinearNoMipMaps));
verify(o, times(1)).write(any(Enum.class), eq("magnificationFilter"), eq(Texture.MagFilter.Bilinear));
}
@Test
public void testWriteWithKey() throws IOException {
JmeExporter e = spy(new TestExporter());
OutputCapsule o = spy(new TestOutputCapsule());
when(e.getCapsule(any(Texture.class))).thenReturn(o);

tex.setKey(new TextureKey());
tex.write(e);

verify(o, times(1)).write(isNull(String.class), eq("name"), isNull(String.class));
verify(o, times(1)).write(any(Savable.class), eq("key"), isNull(Savable.class));
verify(o, times(1)).write(anyInt(), eq("anisotropicFilter"), eq(1));
verify(o, times(1)).write(any(Enum.class), eq("minificationFilter"), eq(Texture.MinFilter.BilinearNoMipMaps));
verify(o, times(1)).write(any(Enum.class), eq("magnificationFilter"), eq(Texture.MagFilter.Bilinear));
}
}


}

0 comments on commit e180bfe

Please sign in to comment.