Class LoaderBinaryTest

java.lang.Object
com.irurueta.geometry.io.LoaderBinaryTest
All Implemented Interfaces:
LoaderListener, LoaderListenerBinary, LoaderListenerOBJ, MaterialLoaderListener, MeshWriterListener

  • Field Details

    • BUFFER_SIZE

      private static final int BUFFER_SIZE
      See Also:
    • INPUT_FOLDER

      private static final String INPUT_FOLDER
      See Also:
    • TMP_FOLDER

      private static final String 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

      @TempDir private Path 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

      private final List<DataChunk> chunks
    • objTextures

      private final Map<Integer,File> objTextures
    • binTextures

      private final Map<Integer,File> 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
      Throws:
      LockedException
      IOException
      LoaderException
      NotReadyException
    • testHasSetFileAndIsReady

      @Test void testHasSetFileAndIsReady() throws LockedException, IOException, LoaderException, NotReadyException
      Throws:
      LockedException
      IOException
      LoaderException
      NotReadyException
    • testGetSetListener

      @Test void testGetSetListener() throws LockedException, IOException
      Throws:
      LockedException
      IOException
    • testIsValidFile

      @Test void testIsValidFile() throws IOException, LockedException, LoaderException, NotReadyException
      Throws:
      IOException
      LockedException
      LoaderException
      NotReadyException
    • testLoad

      Throws:
      IOException
      LockedException
      NotReadyException
      LoaderException
    • 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
      Throws:
      IOException
      LockedException
      NotReadyException
      LoaderException
      NotAvailableException
    • testLoadAndIterateRealFileWithNormals2

      @Test void testLoadAndIterateRealFileWithNormals2() throws IOException, LockedException, NotReadyException, LoaderException, NotAvailableException
      Throws:
      IOException
      LockedException
      NotReadyException
      LoaderException
      NotAvailableException
    • testLoadAndIterateRealFileWithTextures

      @Test void testLoadAndIterateRealFileWithTextures() throws IOException, LockedException, NotReadyException, LoaderException, NotAvailableException
      Throws:
      IOException
      LockedException
      NotReadyException
      LoaderException
      NotAvailableException
    • checkChunkEqualness

      private void checkChunkEqualness(DataChunk chunk, DataChunk otherChunk)
    • onMaterialLoaderRequested

      public MaterialLoaderOBJ onMaterialLoaderRequested(LoaderOBJ loader, String path)
      Specified by:
      onMaterialLoaderRequested in interface LoaderListenerOBJ
    • onLoadStart

      public void onLoadStart(MaterialLoader loader)
      Specified by:
      onLoadStart in interface MaterialLoaderListener
    • onLoadEnd

      public void onLoadEnd(MaterialLoader loader)
      Specified by:
      onLoadEnd in interface MaterialLoaderListener
    • onValidateTexture

      public boolean onValidateTexture(MaterialLoader loader, Texture texture)
      Specified by:
      onValidateTexture in interface MaterialLoaderListener
    • next_whenChunkContainsAllData_returnsAllData

      @Test void next_whenChunkContainsAllData_returnsAllData() throws Exception
      Checks that a chunk containing every kind of data is loaded correctly.
      Throws:
      Exception - if any unexpected error occurs.
    • next_whenChunkContainsFullMaterial_returnsMaterial

      @Test void next_whenChunkContainsFullMaterial_returnsMaterial() throws Exception
      Checks that a chunk containing a material with every property is loaded correctly.
      Throws:
      Exception - if any unexpected error occurs.
    • next_whenMaterialHasNoOptionalData_returnsMaterialWithOnlyId

      @Test void next_whenMaterialHasNoOptionalData_returnsMaterialWithOnlyId() throws Exception
      Checks that a material with no optional properties is loaded.
      Throws:
      Exception - if any unexpected error occurs.
    • next_whenSeveralChunks_returnsEachChunk

      @Test void next_whenSeveralChunks_returnsEachChunk() throws Exception
      Checks that several chunks are returned sequentially.
      Throws:
      Exception - if any unexpected error occurs.
    • load_whenVersionIsNotSupported_throwsLoaderException

      @Test void load_whenVersionIsNotSupported_throwsLoaderException() throws Exception
      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

      @Test void hasNext_whenNoChunks_returnsFalse() throws Exception
      Checks that a file without chunks has nothing to iterate.
      Throws:
      Exception - if any unexpected error occurs.
    • load_whenTextureAndNoListener_skipsTexture

      @Test void load_whenTextureAndNoListener_skipsTexture() throws Exception
      Checks that textures are skipped when the listener is not a binary listener.
      Throws:
      Exception - if any unexpected error occurs.
    • load_whenTextureAndListenerProvidesFile_storesTextureData

      @Test void load_whenTextureAndListenerProvidesFile_storesTextureData() throws Exception
      Checks that textures are stored in the file provided by the listener.
      Throws:
      Exception - if any unexpected error occurs.
    • load_whenTextureAndListenerProvidesNoFile_skipsTexture

      @Test void load_whenTextureAndListenerProvidesNoFile_skipsTexture() throws Exception
      Checks that texture data is skipped when the listener does not provide a file.
      Throws:
      Exception - if any unexpected error occurs.
    • load_whenTextureIsRejectedByListener_throwsLoaderException

      @Test void load_whenTextureIsRejectedByListener_throwsLoaderException() throws Exception
      Checks that an invalid texture reported by the listener makes loading fail.
      Throws:
      Exception - if any unexpected error occurs.
    • load_whenTextureLengthExceedsFile_throwsLoaderException

      @Test void load_whenTextureLengthExceedsFile_throwsLoaderException() throws Exception
      Checks that a texture longer than the file makes loading fail.
      Throws:
      Exception - if any unexpected error occurs.
    • next_whenChunkSizeIsNegative_throwsLoaderException

      @Test void next_whenChunkSizeIsNegative_throwsLoaderException() throws Exception
      Checks that a negative chunk size is detected.
      Throws:
      Exception - if any unexpected error occurs.
    • next_whenChunkSizeExceedsFile_throwsLoaderException

      @Test void next_whenChunkSizeExceedsFile_throwsLoaderException() throws Exception
      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

      private static Stream<byte[]> hostileSizePayloads()
      Gets payloads declaring huge data sizes.
      Returns:
      stream of payloads.
    • next_whenChunkDeclaresDataButFileEnds_throwsLoaderException

      @Test void next_whenChunkDeclaresDataButFileEnds_throwsLoaderException() throws Exception
      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

      @Test void load_whenFileEndsInsideTextureHeader_throwsLoaderException() throws Exception
      Checks that files truncated while reading textures are reported as loader exceptions.
      Throws:
      Exception - if any unexpected error occurs.
    • corruptedPayloads

      private static Stream<byte[]> 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

      private File writeFile(byte[]... payloads) throws IOException
      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

      private File writeFileWithTexture(byte[] texture, byte[] payload) throws IOException
      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

      private static byte[] bytes(Object... items)
      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:
      onTextureReceived in interface LoaderListenerBinary
    • onTextureDataAvailable

      public boolean onTextureDataAvailable(LoaderBinary loader, File textureFile, int textureId, int textureImageWidth, int textureImageHeight)
      Specified by:
      onTextureDataAvailable in interface LoaderListenerBinary
    • onLoadStart

      public void onLoadStart(Loader loader)
      Specified by:
      onLoadStart in interface LoaderListener
    • onLoadEnd

      public void onLoadEnd(Loader loader)
      Specified by:
      onLoadEnd in interface LoaderListener
    • onLoadProgressChange

      public void onLoadProgressChange(Loader loader, float progress)
      Specified by:
      onLoadProgressChange in interface LoaderListener
    • onWriteStart

      public void onWriteStart(MeshWriter writer)
      Specified by:
      onWriteStart in interface MeshWriterListener
    • onWriteEnd

      public void onWriteEnd(MeshWriter writer)
      Specified by:
      onWriteEnd in interface MeshWriterListener
    • onWriteProgressChange

      public void onWriteProgressChange(MeshWriter writer, float progress)
      Specified by:
      onWriteProgressChange in interface MeshWriterListener
    • onChunkAvailable

      public void onChunkAvailable(MeshWriter writer, DataChunk chunk)
      Specified by:
      onChunkAvailable in interface MeshWriterListener
    • onMaterialFileRequested

      public File onMaterialFileRequested(MeshWriter writer, String path)
      Specified by:
      onMaterialFileRequested in interface MeshWriterListener
    • onValidateTexture

      public File onValidateTexture(MeshWriter writer, Texture texture)
      Specified by:
      onValidateTexture in interface MeshWriterListener
    • onDidValidateTexture

      public void onDidValidateTexture(MeshWriter writer, File f)
      Specified by:
      onDidValidateTexture in interface MeshWriterListener
    • onTextureReceived

      public File onTextureReceived(MeshWriter writer, int textureWidth, int textureHeight)
      Specified by:
      onTextureReceived in interface MeshWriterListener
    • onTextureDataAvailable

      public File onTextureDataAvailable(MeshWriter writer, File textureFile, int textureWidth, int textureHeight)
      Specified by:
      onTextureDataAvailable in interface MeshWriterListener
    • onTextureDataProcessed

      public void onTextureDataProcessed(MeshWriter writer, File textureFile, int textureWidth, int textureHeight)
      Specified by:
      onTextureDataProcessed in interface MeshWriterListener
    • testLocked

      private void testLocked(LoaderBinary loader)
    • resetListener

      private void resetListener()
    • isStartValid

      private boolean isStartValid()
    • isEndValid

      private boolean isEndValid()
    • isProgressValid

      private boolean isProgressValid()
    • isLockedValid

      private boolean isLockedValid()
    • areEqual

      private boolean areEqual(File f1, File f2) throws IOException
      Throws:
      IOException
    • convertToBin

      private void convertToBin(File inputFile, File outputFile, MeshFormat inputFormat) throws IOException, LockedException, LoaderException, NotReadyException
      Throws:
      IOException
      LockedException
      LoaderException
      NotReadyException
    • load_whenTextureLengthExceedsFile_throwsLoaderExceptionAndUnlocks

      @Test void load_whenTextureLengthExceedsFile_throwsLoaderExceptionAndUnlocks() throws Exception
      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

      @Test void next_whenChunkIsCorrupted_throwsLoaderExceptionAndUnlocks() throws Exception
      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.