Package com.irurueta.geometry.io
Class LoaderSTLTest
java.lang.Object
com.irurueta.geometry.io.LoaderSTLTest
- All Implemented Interfaces:
LoaderListener
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate intprivate booleanprivate static final doubleprivate booleanprivate floatprivate booleanprivate intprivate booleanprivate Path -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcheckLocked(LoaderSTL loader) private static Stringfacet(float... values) Gets a single ASCII facet.(package private) voidChecks that a binary STL with zero triangles has no chunks.private booleanprivate booleanprivate booleanprivate boolean(package private) voidChecks that a small chunk size splits an ASCII solid into several chunks.(package private) voidChecks that an ASCII solid without facets yields an empty chunk.(package private) voidChecks that after the first solid ends, a second solid in the same file is not loaded.(package private) voidChecks that a file containing only the "solid" keyword is rejected.(package private) voidChecks that an ASCII STL file containing a single solid with two facets is loaded into a single chunk.(package private) voidChecks that a binary STL with several triangles is loaded in one chunk.(package private) voidChecks that crafted binary STL files with a tiny body are rejected at load time.(package private) voidChecks that a binary STL declaring zero triangles with a tiny body loads without triangles.(package private) voidChecks that binary files shorter than the header plus triangle count are rejected with a checked exception.(package private) voidChecks that a file shorter than the "solid" keyword is rejected.(package private) voidChecks that the loader is unlocked after a corrupted file fails while loading or iterating, so that it can be reused.(package private) voidChecks that malformed ASCII files raise a loader exception when read.(package private) voidChecks that malformed numbers in ASCII files do not escape as unchecked exceptions.(package private) voidChecks that a binary STL is split in several chunks when chunk size is small.(package private) voidChecks that a binary STL with a huge triangle count and no data fails with an exception.(package private) voidChecks that a binary STL truncated in the middle of a triangle fails.(package private) voidChecks that a binary STL declaring more triangles than stored fails.voidvoidonLoadProgressChange(Loader loader, float progress) voidonLoadStart(Loader loader) private void(package private) void(package private) void(package private) void(package private) void(package private) void(package private) voidtestLoad()(package private) voidprivate FilewriteAscii(String name, String content) Writes an ASCII STL file.private FilewriteBinary(String name, int declared, int available) Writes a binary STL file.
-
Field Details
-
ERROR
private static final double ERROR- See Also:
-
BINARY_HEADER_SIZE
private static final int BINARY_HEADER_SIZE- See Also:
-
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
- Throws:
IOException
-
testHasSetFileAndIsReady
- Throws:
LockedExceptionIOException
-
testGetSetListener
- Throws:
LockedExceptionIOException
-
testGetSetMaxVerticesInChunk
- Throws:
LockedExceptionIOException
-
testIsValidFile
- Throws:
LockedExceptionIOException
-
testLoad
-
testLoadAndIterate
@Test void testLoadAndIterate() throws IllegalArgumentException, LockedException, NotReadyException, IOException, LoaderException, NotAvailableException -
load_whenAsciiSingleSolid_returnsSingleChunkWithAllVertices
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
Checks that a small chunk size splits an ASCII solid into several chunks.- Throws:
Exception- if any unexpected error occurs.
-
load_whenAsciiEmptySolid_returnsEmptyChunk
Checks that an ASCII solid without facets yields an empty chunk.- Throws:
Exception- if any unexpected error occurs.
-
load_whenAsciiMultipleSolids_loadsOnlyFirstSolid
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
Checks that malformed numbers in ASCII files do not escape as unchecked exceptions.- Throws:
Exception- if any unexpected error occurs.
-
load_whenAsciiOnlyMagic_throwsLoaderException
Checks that a file containing only the "solid" keyword is rejected.- Throws:
Exception- if any unexpected error occurs.
-
load_whenFileTooShort_throwsLoaderException
Checks that a file shorter than the "solid" keyword is rejected.- Throws:
Exception- if any unexpected error occurs.
-
load_whenBinary_returnsAllTriangles
Checks that a binary STL with several triangles is loaded in one chunk.- Throws:
Exception- if any unexpected error occurs.
-
next_whenBinaryAndSmallChunkSize_returnsSeveralChunks
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
Checks that a binary STL with zero triangles has no chunks.- Throws:
Exception- if any unexpected error occurs.
-
next_whenBinaryTruncatedTriangles_throwsException
Checks that a binary STL declaring more triangles than stored fails.- Throws:
Exception- if any unexpected error occurs.
-
next_whenBinaryTruncatedMidTriangle_throwsException
Checks that a binary STL truncated in the middle of a triangle fails.- Throws:
Exception- if any unexpected error occurs.
-
next_whenBinaryHugeTriangleCount_throwsException
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
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
Gets a single ASCII facet.- Parameters:
values- 3 normal values followed by 9 vertex coordinates.- Returns:
- facet text.
-
writeAscii
Writes an ASCII STL file.- Parameters:
name- file name.content- file content.- Returns:
- written file.
- Throws:
IOException- if an I/O error occurs.
-
writeBinary
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
- Specified by:
onLoadStartin interfaceLoaderListener
-
onLoadEnd
- Specified by:
onLoadEndin interfaceLoaderListener
-
onLoadProgressChange
- Specified by:
onLoadProgressChangein interfaceLoaderListener
-
checkLocked
-
resetListener
private void resetListener() -
isStartValid
private boolean isStartValid() -
isEndValid
private boolean isEndValid() -
isProgressValid
private boolean isProgressValid() -
isLockedValid
private boolean isLockedValid() -
loadAndIterate_whenFileIsCorrupted_unlocksLoader
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.
-