-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added unit tests to test serialization and cached model3d content
- Loading branch information
1 parent
7e6b509
commit d9ac61b
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
vitrivr-engine-module-m3d/src/test/kotlin/org/vitrivr/engine/model3d/SerializationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.vitrivr.engine.model3d | ||
|
||
import kotlinx.serialization.encodeToString | ||
import kotlinx.serialization.json.Json | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.Test | ||
import org.vitrivr.engine.core.model.content.impl.cache.CachedModel3dContent | ||
import org.vitrivr.engine.core.model.mesh.texturemodel.Material | ||
import org.vitrivr.engine.core.model.mesh.texturemodel.Model3d | ||
import java.io.File | ||
import kotlin.io.path.Path | ||
|
||
/** | ||
* Unit tests to check the serialization of 3D models. | ||
* | ||
* @author Rahel Arnold | ||
* @version 1.0.0 | ||
*/ | ||
class SerializationTest { | ||
/* | ||
* Tests if a 3D model is identical to after serialization and deserialization. | ||
*/ | ||
@Test | ||
fun serialization() { | ||
val loader = ModelLoader() | ||
val model = this::class.java.getResourceAsStream("/bunny.obj").use { inp -> | ||
loader.loadModel("bunny", inp!!) | ||
} ?: Assertions.fail("Failed to load model.") | ||
|
||
/* Serialize and deserialize model. */ | ||
val serialized = Json.encodeToString(model) | ||
val deserialized = Json.decodeFromString<Model3d>(serialized) | ||
|
||
/* Check if original and deserialized models are the same. */ | ||
Assertions.assertEquals(model, deserialized) | ||
} | ||
|
||
/** | ||
* Tests if a 3D model is identical to reloaded one from cache. | ||
*/ | ||
@Test | ||
fun cachedModel() { | ||
val tmpPath = Path("./model.json")/* Load model. */ | ||
val loader = ModelLoader() | ||
val model = this::class.java.getResourceAsStream("/bunny.obj").use { inp -> | ||
loader.loadModel("bunny", inp!!) | ||
} ?: Assertions.fail("Failed to load model.") | ||
|
||
/* Serialize and deserialize model. */ | ||
val cachedModel3dContent = CachedModel3dContent(tmpPath, model) | ||
val file = File(tmpPath.toString()) | ||
file.delete() | ||
|
||
/* Check if original and deserialized models are the same. */ | ||
Assertions.assertEquals(model, cachedModel3dContent.content) | ||
} | ||
} |