Package com.irurueta.geometry.io
Class LoaderOBJTest
java.lang.Object
com.irurueta.geometry.io.LoaderOBJTest
- All Implemented Interfaces:
LoaderListener,LoaderListenerOBJ
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intprivate intprivate booleanprivate static final doubleprivate booleanprivate floatprivate booleanprivate intprivate booleanprivate Path -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidcheckLocked(LoaderOBJ loader) private static voidLoads a file and iterates over all its chunks.private static Stream<org.junit.jupiter.params.provider.Arguments> Provides garbage OBJ contents.private static Stream<org.junit.jupiter.params.provider.Arguments> Provides OBJ contents whose face indices are hostile.private static Stream<org.junit.jupiter.params.provider.Arguments> Provides OBJ contents whose face indices are out of range, zero or negative.private booleanprivate booleanprivate booleanprivate boolean(package private) voidChecks that comments are collected and groups, objects, smoothing and blank lines are ignored.(package private) voidChecks that an empty file cannot be loaded.(package private) voidChecks that very long lines (a few MB) are handled.(package private) voidChecks that binary garbage only produces checked exceptions.(package private) voidChecks that garbage resembling OBJ syntax only produces checked exceptions.(package private) voidChecks that materials requested through the listener are loaded.(package private) voidChecks that a listener that cannot provide a material loader is tolerated.(package private) voidChecks that a corrupt material library raises a LoaderException when loading.(package private) voidChecks that a missing material library raises an IOException when loading.(package private) voidChecks that a file without faces cannot be loaded.(package private) voidChecks that loading while locked or without a file fails and file validity.loadChunks(File file, int maxVertices, boolean allowDuplicates) Loads all chunks of provided OBJ file.private static Stream<org.junit.jupiter.params.provider.Arguments> Provides OBJ contents with malformed vertex, texture, normal or face lines.(package private) voidChecks that degenerate polygons are skipped when continuing on triangulation errors.(package private) voidChecks that degenerate polygons fail when not continuing on triangulation errors.(package private) voidChecks that duplicate vertices are reused in a chunk and that index arrays grow when needed.(package private) voidChecks that faces with fewer than three vertices fail.(package private) voidChecks that faces that can never fit in a chunk are rejected instead of producing empty chunks forever.(package private) voidChecks 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.(package private) voidChecks that hostile face indices are rejected with a LoaderException, also when the first line of the file is a vertex.(package private) voidChecks that out of range and negative indices are rejected.(package private) voidChecks that requesting a chunk when iteration finished raises NotAvailableException and that the loader can be reused afterwards.(package private) voidChecks that malformed lines referenced by faces fail with a LoaderException.(package private) voidChecks materials loaded from an MTL library referenced with an absolute path and chunks split on material changes.(package private) voidChecks that data is split in several chunks when maximum vertices in chunk is exceeded.(package private) voidChecks that quads and pentagons are triangulated.(package private) voidChecks that a quad with texture and normals indices is triangulated.(package private) voidChecks that a small stream position cache still allows resolving all vertices, textures and normals.(package private) voidChecks that usemtl without a library yields chunks without material.(package private) voidChecks vertex and normal face indices (form "v//vn").(package private) voidChecks vertex only face indices (form "v").(package private) voidChecks vertex and texture face indices (form "v/vt").(package private) voidChecks full face indices (form "v/vt/vn") including homogeneous vertex and texture coordinates.voidvoidonLoadProgressChange(Loader loader, float progress) voidonLoadStart(Loader loader) onMaterialLoaderRequested(LoaderOBJ loader, String path) private void(package private) void(package private) void(package private) void(package private) void(package private) void(package private) void(package private) void(package private) void(package private) voidtestLoad()(package private) void(package private) void(package private) void(package private) void(package private) void(package private) voidprivate FileWrites an OBJ file with provided lines into the temporary directory.
-
Field Details
-
ERROR
private static final double ERROR- See Also:
-
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
- Throws:
IOException
-
testHasSetFileAndIsReady
- Throws:
LockedExceptionIOException
-
testGetSetListener
- Throws:
LockedExceptionIOException
-
testGetSetMaxVerticesInChunk
- Throws:
LockedExceptionIOException
-
testGetSetAllowDuplicateVerticesInChunk
- Throws:
LockedExceptionIOException
-
testGetSetMaxStreamPositions
- Throws:
LockedExceptionIOException
-
testIsSetContinueIfTriangulationError
- Throws:
IOException
-
testIsValidFile
- Throws:
LockedExceptionIOException
-
testLoad
-
testLoadAndIterate
@Test void testLoadAndIterate() throws IllegalArgumentException, LockedException, NotReadyException, IOException, LoaderException, NotAvailableException -
testLoadAndIterateMacbook
@Test void testLoadAndIterateMacbook() throws IllegalArgumentException, LockedException, NotReadyException, IOException, LoaderException, NotAvailableException -
testLoadAndIterateMacbook2
@Test void testLoadAndIterateMacbook2() throws IllegalArgumentException, LockedException, NotReadyException, IOException, LoaderException, NotAvailableException -
testLoadAndIteratePitcher
@Test void testLoadAndIteratePitcher() throws IllegalArgumentException, LockedException, NotReadyException, IOException, LoaderException, NotAvailableException -
testLoadAndIterateCamera
@Test void testLoadAndIterateCamera() throws IllegalArgumentException, LockedException, NotReadyException, IOException, LoaderException, NotAvailableException -
testLoadAndIteratePotro
@Test void testLoadAndIteratePotro() throws IllegalArgumentException, LockedException, NotReadyException, IOException, LoaderException, NotAvailableException -
next_whenVertexOnlyIndices_returnsVerticesAndIndicesOnly
Checks vertex only face indices (form "v").- Throws:
Exception
-
next_whenVertexTextureIndices_returnsTextureCoordinates
Checks vertex and texture face indices (form "v/vt").- Throws:
Exception
-
next_whenVertexNormalIndices_returnsNormals
Checks vertex and normal face indices (form "v//vn").- Throws:
Exception
-
next_whenVertexTextureNormalIndices_returnsAllData
Checks full face indices (form "v/vt/vn") including homogeneous vertex and texture coordinates.- Throws:
Exception
-
next_whenPolygonFaces_triangulatesThem
Checks that quads and pentagons are triangulated.- Throws:
Exception
-
next_whenQuadWithTextureAndNormals_triangulatesPreservingIndices
Checks that a quad with texture and normals indices is triangulated.- Throws:
Exception
-
next_whenDegeneratePolygonAndContinue_skipsPolygon
Checks that degenerate polygons are skipped when continuing on triangulation errors.- Throws:
Exception
-
next_whenDegeneratePolygonAndNotContinue_throwsLoaderException
Checks that degenerate polygons fail when not continuing on triangulation errors.- Throws:
Exception
-
load_whenCommentsGroupsAndBlankLines_collectsCommentsAndIgnoresRest
Checks that comments are collected and groups, objects, smoothing and blank lines are ignored.- Throws:
Exception
-
next_whenMaxVerticesExceeded_splitsInChunks
Checks that data is split in several chunks when maximum vertices in chunk is exceeded.- Throws:
Exception
-
next_whenSmallStreamPositionCache_stillLoadsAllData
Checks that a small stream position cache still allows resolving all vertices, textures and normals.- Throws:
Exception
-
next_whenMaterialLibrary_splitsChunksByMaterial
Checks materials loaded from an MTL library referenced with an absolute path and chunks split on material changes.- Throws:
Exception
-
next_whenUsemtlWithoutLibrary_returnsChunkWithoutMaterial
Checks that usemtl without a library yields chunks without material.- Throws:
Exception
-
load_whenListenerProvidesMaterialLoader_loadsMaterials
Checks that materials requested through the listener are loaded.- Throws:
Exception
-
load_whenListenerReturnsNullMaterialLoader_loadsWithoutMaterials
Checks that a listener that cannot provide a material loader is tolerated.- Throws:
Exception
-
load_whenMaterialLibraryMissing_throwsIOException
Checks that a missing material library raises an IOException when loading.- Throws:
Exception
-
load_whenMaterialLibraryCorrupt_throwsLoaderException
Checks that a corrupt material library raises a LoaderException when loading.- Throws:
Exception
-
load_whenNoFaces_throwsLoaderException
Checks that a file without faces cannot be loaded.- Throws:
Exception
-
load_whenEmptyFile_throwsLoaderException
Checks that an empty file cannot be loaded.- Throws:
Exception
-
next_whenFaceHasTwoVertices_throwsLoaderException
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
Checks that requesting a chunk when iteration finished raises NotAvailableException and that the loader can be reused afterwards.- Throws:
Exception
-
load_whenNotReadyOrLocked_throwsExpectedExceptions
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
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
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
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
Loads a file and iterates over all its chunks.- Parameters:
loader- loader.- Throws:
Exception- if any error occurs.
-
hostileIndexObjs
Provides OBJ contents whose face indices are hostile.- Returns:
- stream of OBJ lines.
-
garbageObjs
Provides garbage OBJ contents.- Returns:
- stream of OBJ lines.
-
malformedObjs
Provides OBJ contents with malformed vertex, texture, normal or face lines.- Returns:
- stream of OBJ lines.
-
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
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
- Specified by:
onLoadStartin interfaceLoaderListener
-
onLoadEnd
- Specified by:
onLoadEndin interfaceLoaderListener
-
onLoadProgressChange
- Specified by:
onLoadProgressChangein interfaceLoaderListener
-
onMaterialLoaderRequested
- Specified by:
onMaterialLoaderRequestedin interfaceLoaderListenerOBJ
-
checkLocked
-
resetListener
private void resetListener() -
isStartValid
private boolean isStartValid() -
isEndValid
private boolean isEndValid() -
isProgressValid
private boolean isProgressValid() -
isLockedValid
private boolean isLockedValid() -
next_whenIndexIsOnePastLast_throwsLoaderExceptionAndUnlocks
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.
-