Class LoaderSTLTest

java.lang.Object
com.irurueta.geometry.io.LoaderSTLTest
All Implemented Interfaces:
LoaderListener

class LoaderSTLTest extends Object implements LoaderListener
  • Field Details

    • ERROR

      private static final double ERROR
      See Also:
    • BINARY_HEADER_SIZE

      private static final int BINARY_HEADER_SIZE
      See Also:
    • tempDir

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

    • LoaderSTLTest

      LoaderSTLTest()
  • 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
    • testIsValidFile

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

      Throws:
      LockedException
      NotReadyException
      IOException
      LoaderException
    • testLoadAndIterate

      Throws:
      IllegalArgumentException
      LockedException
      NotReadyException
      IOException
      LoaderException
      NotAvailableException
    • load_whenAsciiSingleSolid_returnsSingleChunkWithAllVertices

      @Test void load_whenAsciiSingleSolid_returnsSingleChunkWithAllVertices() throws Exception
      Checks that an ASCII STL file containing a single solid with two facets is loaded into a single chunk.
      Throws:
      Exception - if any unexpected error occurs.
    • load_whenAsciiAndSmallChunkSize_returnsSeveralChunks

      @Test void load_whenAsciiAndSmallChunkSize_returnsSeveralChunks() throws Exception
      Checks that a small chunk size splits an ASCII solid into several chunks.
      Throws:
      Exception - if any unexpected error occurs.
    • load_whenAsciiEmptySolid_returnsEmptyChunk

      @Test void load_whenAsciiEmptySolid_returnsEmptyChunk() throws Exception
      Checks that an ASCII solid without facets yields an empty chunk.
      Throws:
      Exception - if any unexpected error occurs.
    • load_whenAsciiMultipleSolids_loadsOnlyFirstSolid

      @Test void load_whenAsciiMultipleSolids_loadsOnlyFirstSolid() throws Exception
      Checks that after the first solid ends, a second solid in the same file is not loaded.
      Throws:
      Exception - if any unexpected error occurs.
    • next_whenAsciiMalformed_throwsLoaderException

      @ParameterizedTest @ValueSource(strings={"solid a\nfoo\n","solid a\nfacet foo 0 0 1\n","solid a\nfacet\n","solid a\nouter foo\n","solid a\nouter\n","solid a\nfacet normal 0 0\n","solid a\nfacet normal 0 0 1\nouter loop\nvertex 0 0 0\nvertex 1 0 0\n","solid a\nfacet normal 0 0 1\nouter loop\n"}) void next_whenAsciiMalformed_throwsLoaderException(String content) throws Exception
      Checks that malformed ASCII files raise a loader exception when read.
      Parameters:
      content - malformed file content.
      Throws:
      Exception - if any unexpected error occurs.
    • next_whenAsciiVertexNotANumber_throwsLoaderException

      @Test void next_whenAsciiVertexNotANumber_throwsLoaderException() throws Exception
      Checks that malformed numbers in ASCII files do not escape as unchecked exceptions.
      Throws:
      Exception - if any unexpected error occurs.
    • load_whenAsciiOnlyMagic_throwsLoaderException

      @Test void load_whenAsciiOnlyMagic_throwsLoaderException() throws Exception
      Checks that a file containing only the "solid" keyword is rejected.
      Throws:
      Exception - if any unexpected error occurs.
    • load_whenFileTooShort_throwsLoaderException

      @Test void load_whenFileTooShort_throwsLoaderException() throws Exception
      Checks that a file shorter than the "solid" keyword is rejected.
      Throws:
      Exception - if any unexpected error occurs.
    • load_whenBinary_returnsAllTriangles

      @Test void load_whenBinary_returnsAllTriangles() throws Exception
      Checks that a binary STL with several triangles is loaded in one chunk.
      Throws:
      Exception - if any unexpected error occurs.
    • next_whenBinaryAndSmallChunkSize_returnsSeveralChunks

      @Test void next_whenBinaryAndSmallChunkSize_returnsSeveralChunks() throws Exception
      Checks that a binary STL is split in several chunks when chunk size is small.
      Throws:
      Exception - if any unexpected error occurs.
    • hasNext_whenBinaryWithoutTriangles_returnsFalse

      @Test void hasNext_whenBinaryWithoutTriangles_returnsFalse() throws Exception
      Checks that a binary STL with zero triangles has no chunks.
      Throws:
      Exception - if any unexpected error occurs.
    • next_whenBinaryTruncatedTriangles_throwsException

      @Test void next_whenBinaryTruncatedTriangles_throwsException() throws Exception
      Checks that a binary STL declaring more triangles than stored fails.
      Throws:
      Exception - if any unexpected error occurs.
    • next_whenBinaryTruncatedMidTriangle_throwsException

      @Test void next_whenBinaryTruncatedMidTriangle_throwsException() throws Exception
      Checks that a binary STL truncated in the middle of a triangle fails.
      Throws:
      Exception - if any unexpected error occurs.
    • next_whenBinaryHugeTriangleCount_throwsException

      @Test void next_whenBinaryHugeTriangleCount_throwsException() throws Exception
      Checks that a binary STL with a huge triangle count and no data fails with an exception.
      Throws:
      Exception - if any unexpected error occurs.
    • load_whenBinaryDeclaresMoreTrianglesThanFits_throwsLoaderException

      @ParameterizedTest @ValueSource(longs={1L,2L,2147483647L,2147483648L,4294967294L,4294967295L}) void load_whenBinaryDeclaresMoreTrianglesThanFits_throwsLoaderException(long declared) throws Exception
      Checks that crafted binary STL files with a tiny body are rejected at load time.
      Parameters:
      declared - number of declared triangles (unsigned 32 bit).
      Throws:
      Exception - if any unexpected error occurs.
    • load_whenBinaryDeclaresZeroTrianglesWithTinyBody_hasNoData

      @Test void load_whenBinaryDeclaresZeroTrianglesWithTinyBody_hasNoData() throws Exception
      Checks that a binary STL declaring zero triangles with a tiny body loads without triangles.
      Throws:
      Exception - if any unexpected error occurs.
    • load_whenBinaryShorterThanHeader_throwsLoaderException

      @ParameterizedTest @ValueSource(ints={81,82,83}) void load_whenBinaryShorterThanHeader_throwsLoaderException(int length) throws Exception
      Checks that binary files shorter than the header plus triangle count are rejected with a checked exception.
      Parameters:
      length - file length in bytes.
      Throws:
      Exception - if any unexpected error occurs.
    • facet

      private static String facet(float... values)
      Gets a single ASCII facet.
      Parameters:
      values - 3 normal values followed by 9 vertex coordinates.
      Returns:
      facet text.
    • writeAscii

      private File writeAscii(String name, String content) throws IOException
      Writes an ASCII STL file.
      Parameters:
      name - file name.
      content - file content.
      Returns:
      written file.
      Throws:
      IOException - if an I/O error occurs.
    • writeBinary

      private File writeBinary(String name, int declared, int available) throws IOException
      Writes a binary STL file.
      Parameters:
      name - file name.
      declared - number of triangles declared in the header.
      available - number of triangles actually written.
      Returns:
      written file.
      Throws:
      IOException - if an I/O error occurs.
    • 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
    • checkLocked

      private void checkLocked(LoaderSTL loader)
    • resetListener

      private void resetListener()
    • isStartValid

      private boolean isStartValid()
    • isEndValid

      private boolean isEndValid()
    • isProgressValid

      private boolean isProgressValid()
    • isLockedValid

      private boolean isLockedValid()
    • loadAndIterate_whenFileIsCorrupted_unlocksLoader

      @Test void loadAndIterate_whenFileIsCorrupted_unlocksLoader() throws Exception
      Checks that the loader is unlocked after a corrupted file fails while loading or iterating, so that it can be reused.
      Throws:
      Exception - if any unexpected error occurs.