Package com.irurueta.geometry.io
Class LoaderBinaryTest
java.lang.Object
com.irurueta.geometry.io.LoaderBinaryTest
- All Implemented Interfaces:
LoaderListener,LoaderListenerBinary,LoaderListenerOBJ,MaterialLoaderListener,MeshWriterListener
class LoaderBinaryTest
extends Object
implements LoaderListenerBinary, LoaderListenerOBJ, MaterialLoaderListener, MeshWriterListener
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate intprivate booleanprivate static final Stringprivate booleanprivate floatprivate booleanprivate booleanprivate booleanprivate intprivate booleanprivate static final byteprivate Pathprivate static final intprivate booleanprivate static final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate booleanprivate static byte[]bbox()Gets bounding box bytes.private static byte[]Serializes values in big endian order.private voidcheckChunkEqualness(DataChunk chunk, DataChunk otherChunk) private voidconvertToBin(File inputFile, File outputFile, MeshFormat inputFormat) private static Stream<byte[]> Gets corrupted chunk payloads.private static byte[]fullPayload(boolean withMaterial) Builds a payload with every kind of data.(package private) voidChecks that a file without chunks has nothing to iterate.private static Stream<byte[]> Gets payloads declaring huge data sizes.private booleanprivate booleanprivate booleanprivate boolean(package private) voidChecks that files truncated while reading textures are reported as loader exceptions.(package private) voidChecks that textures are stored in the file provided by the listener.(package private) voidChecks that texture data is skipped when the listener does not provide a file.(package private) voidChecks that textures are skipped when the listener is not a binary listener.(package private) voidChecks that an invalid texture reported by the listener makes loading fail.(package private) voidChecks that a texture longer than the file makes loading fail.(package private) voidChecks that the loader is unlocked when a texture declares more bytes than the file contains, so that it can be reused.(package private) voidChecks that texture lengths that are negative or overflow when added to the position are rejected.(package private) voidChecks that a file with an unsupported version is not valid and cannot be loaded.(package private) voidChecks that a chunk containing every kind of data is loaded correctly.(package private) voidChecks that a chunk containing a material with every property is loaded correctly.(package private) voidnext_whenChunkContentIsCorrupted_throwsLoaderException(byte[] payload) Checks that corrupted chunk contents are reported as loader exceptions.(package private) voidChecks that a chunk is rejected when reading it from a file with no body after the size.(package private) voidChecks that the loader is unlocked when a chunk cannot be read while iterating, so that it can be reused.(package private) voidChecks that a chunk size beyond the end of file is detected.(package private) voidChecks that chunk sizes near the integer limit are rejected without allocating memory.(package private) voidChecks that a negative chunk size is detected.(package private) voidnext_whenDataSizeIsNearIntegerLimit_throwsLoaderException(byte[] payload) Checks that data sizes near the integer limit declared inside a chunk are rejected without allocating memory.(package private) voidChecks that a material with no optional properties is loaded.(package private) voidChecks that several chunks are returned sequentially.voidonChunkAvailable(MeshWriter writer, DataChunk chunk) voidonDidValidateTexture(MeshWriter writer, File f) voidvoidonLoadEnd(MaterialLoader loader) voidonLoadProgressChange(Loader loader, float progress) voidonLoadStart(Loader loader) voidonLoadStart(MaterialLoader loader) onMaterialFileRequested(MeshWriter writer, String path) onMaterialLoaderRequested(LoaderOBJ loader, String path) booleanonTextureDataAvailable(LoaderBinary loader, File textureFile, int textureId, int textureImageWidth, int textureImageHeight) onTextureDataAvailable(MeshWriter writer, File textureFile, int textureWidth, int textureHeight) voidonTextureDataProcessed(MeshWriter writer, File textureFile, int textureWidth, int textureHeight) onTextureReceived(LoaderBinary loader, int textureId, int textureImageWidth, int textureImageHeight) onTextureReceived(MeshWriter writer, int textureWidth, int textureHeight) booleanonValidateTexture(MaterialLoader loader, Texture texture) onValidateTexture(MeshWriter writer, Texture texture) voidonWriteEnd(MeshWriter writer) voidonWriteProgressChange(MeshWriter writer, float progress) voidonWriteStart(MeshWriter writer) private void(package private) static void(package private) static void(package private) void(package private) void(package private) void(package private) void(package private) voidtestLoad()(package private) voidtestLoadAndIterate(String inputFile, String binFile) (package private) void(package private) voidprivate voidtestLocked(LoaderBinary loader) private FilewriteFile(byte[]... payloads) Writes a file with no textures and the provided chunk payloads.private FilewriteFileWithTexture(byte[] texture, byte[] payload) Writes a file with a single texture followed by the provided chunk payload.
-
Field Details
-
BUFFER_SIZE
private static final int BUFFER_SIZE- See Also:
-
INPUT_FOLDER
- See Also:
-
TMP_FOLDER
- See Also:
-
SUPPORTED_VERSION
private static final byte SUPPORTED_VERSION- See Also:
-
TEXTURE_ID
private static final int TEXTURE_ID- See Also:
-
tempDir
-
returnNullTextureFile
private boolean returnNullTextureFile -
textureDataValid
private boolean textureDataValid -
startValid
private boolean startValid -
endValid
private boolean endValid -
progressValid
private boolean progressValid -
lockedValid
private boolean lockedValid -
startCounter
private int startCounter -
endCounter
private int endCounter -
previousProgress
private float previousProgress -
saveChunks
private boolean saveChunks -
chunks
-
objTextures
-
binTextures
-
-
Constructor Details
-
LoaderBinaryTest
LoaderBinaryTest()
-
-
Method Details
-
setUpClass
@BeforeAll static void setUpClass() -
tearDownClass
@AfterAll static void tearDownClass() -
testConstructors
@Test void testConstructors() throws LockedException, IOException, LoaderException, NotReadyException -
testHasSetFileAndIsReady
@Test void testHasSetFileAndIsReady() throws LockedException, IOException, LoaderException, NotReadyException -
testGetSetListener
- Throws:
LockedExceptionIOException
-
testIsValidFile
@Test void testIsValidFile() throws IOException, LockedException, LoaderException, NotReadyException -
testLoad
-
testLoadAndIterate
@ParameterizedTest(name="{index} => inputFile={0}, binFile={1}") @CsvSource({"randomBig.ply,randomBig.bin","pilarBigEndian.ply,pilarBigEndian.bin","booksBinary.ply,booksBinary.bin"}) void testLoadAndIterate(String inputFile, String binFile) throws IOException, LockedException, NotReadyException, LoaderException, NotAvailableException -
testLoadAndIterateRealFileWithNormals2
@Test void testLoadAndIterateRealFileWithNormals2() throws IOException, LockedException, NotReadyException, LoaderException, NotAvailableException -
testLoadAndIterateRealFileWithTextures
@Test void testLoadAndIterateRealFileWithTextures() throws IOException, LockedException, NotReadyException, LoaderException, NotAvailableException -
checkChunkEqualness
-
onMaterialLoaderRequested
- Specified by:
onMaterialLoaderRequestedin interfaceLoaderListenerOBJ
-
onLoadStart
- Specified by:
onLoadStartin interfaceMaterialLoaderListener
-
onLoadEnd
- Specified by:
onLoadEndin interfaceMaterialLoaderListener
-
onValidateTexture
- Specified by:
onValidateTexturein interfaceMaterialLoaderListener
-
next_whenChunkContainsAllData_returnsAllData
Checks that a chunk containing every kind of data is loaded correctly.- Throws:
Exception- if any unexpected error occurs.
-
next_whenChunkContainsFullMaterial_returnsMaterial
Checks that a chunk containing a material with every property is loaded correctly.- Throws:
Exception- if any unexpected error occurs.
-
next_whenMaterialHasNoOptionalData_returnsMaterialWithOnlyId
Checks that a material with no optional properties is loaded.- Throws:
Exception- if any unexpected error occurs.
-
next_whenSeveralChunks_returnsEachChunk
Checks that several chunks are returned sequentially.- Throws:
Exception- if any unexpected error occurs.
-
load_whenVersionIsNotSupported_throwsLoaderException
Checks that a file with an unsupported version is not valid and cannot be loaded.- Throws:
Exception- if any unexpected error occurs.
-
hasNext_whenNoChunks_returnsFalse
Checks that a file without chunks has nothing to iterate.- Throws:
Exception- if any unexpected error occurs.
-
load_whenTextureAndNoListener_skipsTexture
Checks that textures are skipped when the listener is not a binary listener.- Throws:
Exception- if any unexpected error occurs.
-
load_whenTextureAndListenerProvidesFile_storesTextureData
Checks that textures are stored in the file provided by the listener.- Throws:
Exception- if any unexpected error occurs.
-
load_whenTextureAndListenerProvidesNoFile_skipsTexture
Checks that texture data is skipped when the listener does not provide a file.- Throws:
Exception- if any unexpected error occurs.
-
load_whenTextureIsRejectedByListener_throwsLoaderException
Checks that an invalid texture reported by the listener makes loading fail.- Throws:
Exception- if any unexpected error occurs.
-
load_whenTextureLengthExceedsFile_throwsLoaderException
Checks that a texture longer than the file makes loading fail.- Throws:
Exception- if any unexpected error occurs.
-
next_whenChunkSizeIsNegative_throwsLoaderException
Checks that a negative chunk size is detected.- Throws:
Exception- if any unexpected error occurs.
-
next_whenChunkSizeExceedsFile_throwsLoaderException
Checks that a chunk size beyond the end of file is detected.- Throws:
Exception- if any unexpected error occurs.
-
next_whenChunkContentIsCorrupted_throwsLoaderException
@ParameterizedTest @MethodSource("corruptedPayloads") void next_whenChunkContentIsCorrupted_throwsLoaderException(byte[] payload) throws Exception Checks that corrupted chunk contents are reported as loader exceptions.- Parameters:
payload- corrupted chunk payload.- Throws:
Exception- if any unexpected error occurs.
-
load_whenTextureLengthIsHostile_throwsLoaderException
@ParameterizedTest @ValueSource(longs={9223372036854775807L,9223372036854775806L,-9223372036854775808L,-1L,2147483647L}) void load_whenTextureLengthIsHostile_throwsLoaderException(long length) throws Exception Checks that texture lengths that are negative or overflow when added to the position are rejected.- Parameters:
length- crafted texture length.- Throws:
Exception- if any unexpected error occurs.
-
next_whenChunkSizeIsNearIntegerLimit_throwsLoaderException
@ParameterizedTest @ValueSource(ints={2147483647,2147483646,2147483644,-2147483648}) void next_whenChunkSizeIsNearIntegerLimit_throwsLoaderException(int size) throws Exception Checks that chunk sizes near the integer limit are rejected without allocating memory.- Parameters:
size- crafted chunk size.- Throws:
Exception- if any unexpected error occurs.
-
next_whenDataSizeIsNearIntegerLimit_throwsLoaderException
@ParameterizedTest @MethodSource("hostileSizePayloads") void next_whenDataSizeIsNearIntegerLimit_throwsLoaderException(byte[] payload) throws Exception Checks that data sizes near the integer limit declared inside a chunk are rejected without allocating memory.- Parameters:
payload- crafted chunk payload.- Throws:
Exception- if any unexpected error occurs.
-
hostileSizePayloads
Gets payloads declaring huge data sizes.- Returns:
- stream of payloads.
-
next_whenChunkDeclaresDataButFileEnds_throwsLoaderException
Checks that a chunk is rejected when reading it from a file with no body after the size.- Throws:
Exception- if any unexpected error occurs.
-
load_whenFileEndsInsideTextureHeader_throwsLoaderException
Checks that files truncated while reading textures are reported as loader exceptions.- Throws:
Exception- if any unexpected error occurs.
-
corruptedPayloads
Gets corrupted chunk payloads.- Returns:
- stream of payloads.
-
fullPayload
private static byte[] fullPayload(boolean withMaterial) Builds a payload with every kind of data.- Parameters:
withMaterial- true to include a full material.- Returns:
- chunk payload.
-
bbox
private static byte[] bbox()Gets bounding box bytes.- Returns:
- bounding box bytes.
-
writeFile
Writes a file with no textures and the provided chunk payloads.- Parameters:
payloads- chunk payloads.- Returns:
- written file.
- Throws:
IOException- if an I/O error occurs.
-
writeFileWithTexture
Writes a file with a single texture followed by the provided chunk payload.- Parameters:
texture- texture data.payload- chunk payload.- Returns:
- written file.
- Throws:
IOException- if an I/O error occurs.
-
bytes
Serializes values in big endian order.- Parameters:
items- values (Boolean, Byte, Short, Integer, Long, Float or byte arrays).- Returns:
- serialized bytes.
-
onTextureReceived
public File onTextureReceived(LoaderBinary loader, int textureId, int textureImageWidth, int textureImageHeight) - Specified by:
onTextureReceivedin interfaceLoaderListenerBinary
-
onTextureDataAvailable
public boolean onTextureDataAvailable(LoaderBinary loader, File textureFile, int textureId, int textureImageWidth, int textureImageHeight) - Specified by:
onTextureDataAvailablein interfaceLoaderListenerBinary
-
onLoadStart
- Specified by:
onLoadStartin interfaceLoaderListener
-
onLoadEnd
- Specified by:
onLoadEndin interfaceLoaderListener
-
onLoadProgressChange
- Specified by:
onLoadProgressChangein interfaceLoaderListener
-
onWriteStart
- Specified by:
onWriteStartin interfaceMeshWriterListener
-
onWriteEnd
- Specified by:
onWriteEndin interfaceMeshWriterListener
-
onWriteProgressChange
- Specified by:
onWriteProgressChangein interfaceMeshWriterListener
-
onChunkAvailable
- Specified by:
onChunkAvailablein interfaceMeshWriterListener
-
onMaterialFileRequested
- Specified by:
onMaterialFileRequestedin interfaceMeshWriterListener
-
onValidateTexture
- Specified by:
onValidateTexturein interfaceMeshWriterListener
-
onDidValidateTexture
- Specified by:
onDidValidateTexturein interfaceMeshWriterListener
-
onTextureReceived
- Specified by:
onTextureReceivedin interfaceMeshWriterListener
-
onTextureDataAvailable
public File onTextureDataAvailable(MeshWriter writer, File textureFile, int textureWidth, int textureHeight) - Specified by:
onTextureDataAvailablein interfaceMeshWriterListener
-
onTextureDataProcessed
public void onTextureDataProcessed(MeshWriter writer, File textureFile, int textureWidth, int textureHeight) - Specified by:
onTextureDataProcessedin interfaceMeshWriterListener
-
testLocked
-
resetListener
private void resetListener() -
isStartValid
private boolean isStartValid() -
isEndValid
private boolean isEndValid() -
isProgressValid
private boolean isProgressValid() -
isLockedValid
private boolean isLockedValid() -
areEqual
- Throws:
IOException
-
convertToBin
private void convertToBin(File inputFile, File outputFile, MeshFormat inputFormat) throws IOException, LockedException, LoaderException, NotReadyException -
load_whenTextureLengthExceedsFile_throwsLoaderExceptionAndUnlocks
Checks that the loader is unlocked when a texture declares more bytes than the file contains, so that it can be reused.- Throws:
Exception- if any unexpected error occurs.
-
next_whenChunkIsCorrupted_throwsLoaderExceptionAndUnlocks
Checks that the loader is unlocked when a chunk cannot be read while iterating, so that it can be reused.- Throws:
Exception- if any unexpected error occurs.
-