Class LoaderOBJTest

java.lang.Object
com.irurueta.geometry.io.LoaderOBJTest
All Implemented Interfaces:
LoaderListener, LoaderListenerOBJ

class LoaderOBJTest extends Object implements LoaderListenerOBJ
  • Field Details

    • ERROR

      private static final double ERROR
      See Also:
    • tempDir

      @TempDir private Path tempDir
    • counter

      private int counter
    • 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
  • Constructor Details

    • LoaderOBJTest

      LoaderOBJTest()
  • Method Details

    • testConstructors

      @Test void testConstructors() throws IOException
      Throws:
      IOException
    • testHasSetFileAndIsReady

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

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

      @Test void testGetSetMaxVerticesInChunk() throws LockedException, IOException
      Throws:
      LockedException
      IOException
    • testGetSetAllowDuplicateVerticesInChunk

      @Test void testGetSetAllowDuplicateVerticesInChunk() throws LockedException, IOException
      Throws:
      LockedException
      IOException
    • testGetSetMaxStreamPositions

      @Test void testGetSetMaxStreamPositions() throws LockedException, IOException
      Throws:
      LockedException
      IOException
    • testIsSetContinueIfTriangulationError

      @Test void testIsSetContinueIfTriangulationError() throws IOException
      Throws:
      IOException
    • testIsValidFile

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

      Throws:
      LockedException
      NotReadyException
      IOException
      LoaderException
    • testLoadAndIterate

      Throws:
      IllegalArgumentException
      LockedException
      NotReadyException
      IOException
      LoaderException
      NotAvailableException
    • testLoadAndIterateMacbook

      Throws:
      IllegalArgumentException
      LockedException
      NotReadyException
      IOException
      LoaderException
      NotAvailableException
    • testLoadAndIterateMacbook2

      Throws:
      IllegalArgumentException
      LockedException
      NotReadyException
      IOException
      LoaderException
      NotAvailableException
    • testLoadAndIteratePitcher

      Throws:
      IllegalArgumentException
      LockedException
      NotReadyException
      IOException
      LoaderException
      NotAvailableException
    • testLoadAndIterateCamera

      Throws:
      IllegalArgumentException
      LockedException
      NotReadyException
      IOException
      LoaderException
      NotAvailableException
    • testLoadAndIteratePotro

      Throws:
      IllegalArgumentException
      LockedException
      NotReadyException
      IOException
      LoaderException
      NotAvailableException
    • next_whenVertexOnlyIndices_returnsVerticesAndIndicesOnly

      @Test void next_whenVertexOnlyIndices_returnsVerticesAndIndicesOnly() throws Exception
      Checks vertex only face indices (form "v").
      Throws:
      Exception
    • next_whenVertexTextureIndices_returnsTextureCoordinates

      @Test void next_whenVertexTextureIndices_returnsTextureCoordinates() throws Exception
      Checks vertex and texture face indices (form "v/vt").
      Throws:
      Exception
    • next_whenVertexNormalIndices_returnsNormals

      @Test void next_whenVertexNormalIndices_returnsNormals() throws Exception
      Checks vertex and normal face indices (form "v//vn").
      Throws:
      Exception
    • next_whenVertexTextureNormalIndices_returnsAllData

      @Test void next_whenVertexTextureNormalIndices_returnsAllData() throws Exception
      Checks full face indices (form "v/vt/vn") including homogeneous vertex and texture coordinates.
      Throws:
      Exception
    • next_whenPolygonFaces_triangulatesThem

      @Test void next_whenPolygonFaces_triangulatesThem() throws Exception
      Checks that quads and pentagons are triangulated.
      Throws:
      Exception
    • next_whenQuadWithTextureAndNormals_triangulatesPreservingIndices

      @Test void next_whenQuadWithTextureAndNormals_triangulatesPreservingIndices() throws Exception
      Checks that a quad with texture and normals indices is triangulated.
      Throws:
      Exception
    • next_whenDegeneratePolygonAndContinue_skipsPolygon

      @Test void next_whenDegeneratePolygonAndContinue_skipsPolygon() throws Exception
      Checks that degenerate polygons are skipped when continuing on triangulation errors.
      Throws:
      Exception
    • next_whenDegeneratePolygonAndNotContinue_throwsLoaderException

      @Test void next_whenDegeneratePolygonAndNotContinue_throwsLoaderException() throws Exception
      Checks that degenerate polygons fail when not continuing on triangulation errors.
      Throws:
      Exception
    • load_whenCommentsGroupsAndBlankLines_collectsCommentsAndIgnoresRest

      @Test void load_whenCommentsGroupsAndBlankLines_collectsCommentsAndIgnoresRest() throws Exception
      Checks that comments are collected and groups, objects, smoothing and blank lines are ignored.
      Throws:
      Exception
    • next_whenDuplicatesNotAllowedAndSharedVertices_reusesVertices

      @Test void next_whenDuplicatesNotAllowedAndSharedVertices_reusesVertices() throws Exception
      Checks that duplicate vertices are reused in a chunk and that index arrays grow when needed.
      Throws:
      Exception
    • next_whenMaxVerticesExceeded_splitsInChunks

      @Test void next_whenMaxVerticesExceeded_splitsInChunks() throws Exception
      Checks that data is split in several chunks when maximum vertices in chunk is exceeded.
      Throws:
      Exception
    • next_whenSmallStreamPositionCache_stillLoadsAllData

      @Test void next_whenSmallStreamPositionCache_stillLoadsAllData() throws Exception
      Checks that a small stream position cache still allows resolving all vertices, textures and normals.
      Throws:
      Exception
    • next_whenMaterialLibrary_splitsChunksByMaterial

      @Test void next_whenMaterialLibrary_splitsChunksByMaterial() throws Exception
      Checks materials loaded from an MTL library referenced with an absolute path and chunks split on material changes.
      Throws:
      Exception
    • next_whenUsemtlWithoutLibrary_returnsChunkWithoutMaterial

      @Test void next_whenUsemtlWithoutLibrary_returnsChunkWithoutMaterial() throws Exception
      Checks that usemtl without a library yields chunks without material.
      Throws:
      Exception
    • load_whenListenerProvidesMaterialLoader_loadsMaterials

      @Test void load_whenListenerProvidesMaterialLoader_loadsMaterials() throws Exception
      Checks that materials requested through the listener are loaded.
      Throws:
      Exception
    • load_whenListenerReturnsNullMaterialLoader_loadsWithoutMaterials

      @Test void load_whenListenerReturnsNullMaterialLoader_loadsWithoutMaterials() throws Exception
      Checks that a listener that cannot provide a material loader is tolerated.
      Throws:
      Exception
    • load_whenMaterialLibraryMissing_throwsIOException

      @Test void load_whenMaterialLibraryMissing_throwsIOException() throws Exception
      Checks that a missing material library raises an IOException when loading.
      Throws:
      Exception
    • load_whenMaterialLibraryCorrupt_throwsLoaderException

      @Test void load_whenMaterialLibraryCorrupt_throwsLoaderException() throws Exception
      Checks that a corrupt material library raises a LoaderException when loading.
      Throws:
      Exception
    • load_whenNoFaces_throwsLoaderException

      @Test void load_whenNoFaces_throwsLoaderException() throws Exception
      Checks that a file without faces cannot be loaded.
      Throws:
      Exception
    • load_whenEmptyFile_throwsLoaderException

      @Test void load_whenEmptyFile_throwsLoaderException() throws Exception
      Checks that an empty file cannot be loaded.
      Throws:
      Exception
    • next_whenFaceHasTwoVertices_throwsLoaderException

      @Test void next_whenFaceHasTwoVertices_throwsLoaderException() throws Exception
      Checks that faces with fewer than three vertices fail.
      Throws:
      Exception
    • next_whenMalformedContent_throwsLoaderException

      @ParameterizedTest @MethodSource("malformedObjs") void next_whenMalformedContent_throwsLoaderException(String[] lines) throws Exception
      Checks that malformed lines referenced by faces fail with a LoaderException.
      Throws:
      Exception
    • next_whenInvalidIndices_throwsLoaderException

      @ParameterizedTest @MethodSource("invalidIndexObjs") void next_whenInvalidIndices_throwsLoaderException(String[] lines) throws Exception
      Checks that out of range and negative indices are rejected.
      Throws:
      Exception
    • next_whenIteratorFinished_throwsNotAvailableAndAllowsReload

      @Test void next_whenIteratorFinished_throwsNotAvailableAndAllowsReload() throws Exception
      Checks that requesting a chunk when iteration finished raises NotAvailableException and that the loader can be reused afterwards.
      Throws:
      Exception
    • load_whenNotReadyOrLocked_throwsExpectedExceptions

      @Test void load_whenNotReadyOrLocked_throwsExpectedExceptions() throws Exception
      Checks that loading while locked or without a file fails and file validity.
      Throws:
      Exception
    • next_whenIndicesAreHostile_throwsLoaderException

      @ParameterizedTest @MethodSource("hostileIndexObjs") void next_whenIndicesAreHostile_throwsLoaderException(String[] lines) throws Exception
      Checks that hostile face indices are rejected with a LoaderException, also when the first line of the file is a vertex.
      Parameters:
      lines - OBJ contents.
      Throws:
      Exception - if any unexpected error occurs.
    • load_whenFileIsBinaryGarbage_onlyCheckedExceptionsAreThrown

      @Test void load_whenFileIsBinaryGarbage_onlyCheckedExceptionsAreThrown() throws Exception
      Checks that binary garbage only produces checked exceptions.
      Throws:
      Exception - if any unexpected error occurs.
    • load_whenFileIsMalformedGarbage_onlyCheckedExceptionsAreThrown

      @ParameterizedTest @MethodSource("garbageObjs") void load_whenFileIsMalformedGarbage_onlyCheckedExceptionsAreThrown(String[] lines) throws Exception
      Checks that garbage resembling OBJ syntax only produces checked exceptions.
      Parameters:
      lines - OBJ contents.
      Throws:
      Exception - if any unexpected error occurs.
    • load_whenFileHasVeryLongLines_isHandled

      @Test void load_whenFileHasVeryLongLines_isHandled() throws Exception
      Checks that very long lines (a few MB) are handled. Lines are read completely into memory, so memory usage is proportional to the longest line (documented limit).
      Throws:
      Exception - if any unexpected error occurs.
    • next_whenFaceNeverFitsInChunk_throwsLoaderException

      @Test void next_whenFaceNeverFitsInChunk_throwsLoaderException() throws Exception
      Checks that faces that can never fit in a chunk are rejected instead of producing empty chunks forever.
      Throws:
      Exception - if any unexpected error occurs.
    • consume

      private static void consume(LoaderOBJ loader) throws Exception
      Loads a file and iterates over all its chunks.
      Parameters:
      loader - loader.
      Throws:
      Exception - if any error occurs.
    • hostileIndexObjs

      private static Stream<org.junit.jupiter.params.provider.Arguments> hostileIndexObjs()
      Provides OBJ contents whose face indices are hostile.
      Returns:
      stream of OBJ lines.
    • garbageObjs

      private static Stream<org.junit.jupiter.params.provider.Arguments> garbageObjs()
      Provides garbage OBJ contents.
      Returns:
      stream of OBJ lines.
    • malformedObjs

      private static Stream<org.junit.jupiter.params.provider.Arguments> malformedObjs()
      Provides OBJ contents with malformed vertex, texture, normal or face lines.
      Returns:
      stream of OBJ lines.
    • invalidIndexObjs

      private static Stream<org.junit.jupiter.params.provider.Arguments> invalidIndexObjs()
      Provides OBJ contents whose face indices are out of range, zero or negative.
      Returns:
      stream of OBJ lines.
    • loadChunks

      private static List<DataChunk> loadChunks(File file, int maxVertices, boolean allowDuplicates) throws Exception
      Loads all chunks of provided OBJ file.
      Parameters:
      file - file to be loaded.
      maxVertices - maximum number of vertices in a chunk.
      allowDuplicates - true to allow duplicate vertices in a chunk.
      Returns:
      list of loaded chunks.
      Throws:
      Exception - if loading fails.
    • writeObj

      private File writeObj(String... lines) throws IOException
      Writes an OBJ file with provided lines into the temporary directory.
      Parameters:
      lines - lines of the file.
      Returns:
      created file.
      Throws:
      IOException - if the file cannot be written.
    • 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
    • onMaterialLoaderRequested

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

      private void checkLocked(LoaderOBJ loader)
    • resetListener

      private void resetListener()
    • isStartValid

      private boolean isStartValid()
    • isEndValid

      private boolean isEndValid()
    • isProgressValid

      private boolean isProgressValid()
    • isLockedValid

      private boolean isLockedValid()
    • next_whenIndexIsOnePastLast_throwsLoaderExceptionAndUnlocks

      @Test void next_whenIndexIsOnePastLast_throwsLoaderExceptionAndUnlocks() throws Exception
      Checks that face indices one past the last vertex, texture coordinate or normal are rejected, and that the loader is unlocked afterwards so that it can be reused.
      Throws:
      Exception - if any unexpected error occurs.