#include #include "gltexture/GLTextureAtlas.h" #include "serialization/TestDeserializationContext.h" #include "serialization/TestSerializationContext.h" #include "unittest/TestSuite.h" #include "utilities/printfFormats.h" static void testInit() { GLTextureAtlas atlas, * atlasPtr; bool success; memset(&atlas, 0x00, sizeof(GLTextureAtlas)); success = GLTextureAtlas_init(&atlas); TestCase_assert(success, "Expected true but got false"); TestCase_assert(atlas.vtable == &GLTextureAtlas_class, "Expected %p but got %p", &GLTextureAtlas_class, atlas.vtable); TestCase_assert(atlas.vtable->dispose == GLTextureAtlas_dispose, "Expected %p but got %p", GLTextureAtlas_dispose, atlas.vtable->dispose); TestCase_assert(atlas.textureName == NULL, "Expected NULL but got %p", atlas.textureName); TestCase_assert(atlas.texture == NULL, "Expected NULL but got %p", atlas.texture); GLTextureAtlas_dispose(&atlas); memset(&atlas, 0xFF, sizeof(GLTextureAtlas)); success = GLTextureAtlas_init(&atlas); TestCase_assert(success, "Expected true but got false"); TestCase_assert(atlas.vtable == &GLTextureAtlas_class, "Expected %p but got %p", &GLTextureAtlas_class, atlas.vtable); TestCase_assert(atlas.vtable->dispose == GLTextureAtlas_dispose, "Expected %p but got %p", GLTextureAtlas_dispose, atlas.vtable->dispose); TestCase_assert(atlas.textureName == NULL, "Expected NULL but got %p", atlas.textureName); TestCase_assert(atlas.texture == NULL, "Expected NULL but got %p", atlas.texture); GLTextureAtlas_dispose(&atlas); atlasPtr = GLTextureAtlas_create(); TestCase_assert(atlasPtr != NULL, "Expected non-NULL but got NULL"); TestCase_assert(atlasPtr->vtable == &GLTextureAtlas_class, "Expected %p but got %p", &GLTextureAtlas_class, atlasPtr->vtable); TestCase_assert(atlasPtr->vtable->dispose == GLTextureAtlas_dispose, "Expected %p but got %p", GLTextureAtlas_dispose, atlasPtr->vtable->dispose); TestCase_assert(atlasPtr->textureName == NULL, "Expected NULL but got %p", atlasPtr->textureName); TestCase_assert(atlasPtr->texture == NULL, "Expected NULL but got %p", atlasPtr->texture); GLTextureAtlas_dispose(atlasPtr); } static void testSetRemoveEntry() { GLTextureAtlas atlas; const char ** keys; size_t keyCount; struct GLTextureAtlas_entry entry; GLTextureAtlas_init(&atlas); keyCount = -1; keys = GLTextureAtlas_getKeys(&atlas, &keyCount); TestCase_assert(keyCount == 0, "Expected 0 but got " SIZE_T_FORMAT, keyCount); free(keys); TestCase_assert(!GLTextureAtlas_hasKey(&atlas, "a"), "Expected false but got true"); entry = GLTextureAtlas_lookup(&atlas, "a"); TestCase_assert(entry.left == 0.0f, "Expected 0.0 but got %f", entry.left); TestCase_assert(entry.right == 0.0f, "Expected 0.0 but got %f", entry.right); TestCase_assert(entry.bottom == 0.0f, "Expected 0.0 but got %f", entry.bottom); TestCase_assert(entry.top == 0.0f, "Expected 0.0 but got %f", entry.top); GLTextureAtlas_setEntry(&atlas, "a", (struct GLTextureAtlas_entry) {0.125f, 0.25f, 0.375f, 0.5f}); keyCount = -1; keys = GLTextureAtlas_getKeys(&atlas, &keyCount); TestCase_assert(keyCount == 1, "Expected 1 but got " SIZE_T_FORMAT, keyCount); TestCase_assert(keys != NULL, "Expected non-NULL but got NULL"); TestCase_assert(!strcmp(keys[0], "a"), "Expected \"a\" but got \"%s\"", keys[0]); free(keys); TestCase_assert(GLTextureAtlas_hasKey(&atlas, "a"), "Expected true but got false"); entry = GLTextureAtlas_lookup(&atlas, "a"); TestCase_assert(entry.left == 0.125f, "Expected 0.125 but got %f", entry.left); TestCase_assert(entry.right == 0.25f, "Expected 0.25 but got %f", entry.right); TestCase_assert(entry.bottom == 0.375f, "Expected 0.375 but got %f", entry.bottom); TestCase_assert(entry.top == 0.5f, "Expected 0.5 but got %f", entry.top); entry = GLTextureAtlas_lookup(&atlas, "b"); TestCase_assert(entry.left == 0.0f, "Expected 0.0 but got %f", entry.left); TestCase_assert(entry.right == 0.0f, "Expected 0.0 but got %f", entry.right); TestCase_assert(entry.bottom == 0.0f, "Expected 0.0 but got %f", entry.bottom); TestCase_assert(entry.top == 0.0f, "Expected 0.0 but got %f", entry.top); GLTextureAtlas_setEntry(&atlas, "b", (struct GLTextureAtlas_entry) {0.5f, 0.625f, 0.75f, 0.875f}); keyCount = -1; keys = GLTextureAtlas_getKeys(&atlas, &keyCount); TestCase_assert(keyCount == 2, "Expected 2 but got " SIZE_T_FORMAT, keyCount); TestCase_assert(keys != NULL, "Expected non-NULL but got NULL"); TestCase_assert(!strcmp(keys[0], "a") || !strcmp(keys[0], "b"), "Expected \"a\" or \"b\" but got \"%s\"", keys[0]); TestCase_assert(!strcmp(keys[1], "a") || !strcmp(keys[1], "b"), "Expected \"a\" or \"b\" but got \"%s\"", keys[1]); free(keys); TestCase_assert(GLTextureAtlas_hasKey(&atlas, "b"), "Expected true but got false"); entry = GLTextureAtlas_lookup(&atlas, "b"); TestCase_assert(entry.left == 0.5f, "Expected 0.5 but got %f", entry.left); TestCase_assert(entry.right == 0.625f, "Expected 0.625 but got %f", entry.right); TestCase_assert(entry.bottom == 0.75f, "Expected 0.75 but got %f", entry.bottom); TestCase_assert(entry.top == 0.875f, "Expected 0.875 but got %f", entry.top); GLTextureAtlas_removeEntry(&atlas, "a"); keyCount = -1; keys = GLTextureAtlas_getKeys(&atlas, &keyCount); TestCase_assert(keyCount == 1, "Expected 1 but got " SIZE_T_FORMAT, keyCount); TestCase_assert(keys != NULL, "Expected non-NULL but got NULL"); TestCase_assert(!strcmp(keys[0], "b"), "Expected \"b\" but got \"%s\"", keys[0]); free(keys); TestCase_assert(!GLTextureAtlas_hasKey(&atlas, "a"), "Expected false but got true"); entry = GLTextureAtlas_lookup(&atlas, "a"); TestCase_assert(entry.left == 0.0f, "Expected 0.0 but got %f", entry.left); TestCase_assert(entry.right == 0.0f, "Expected 0.0 but got %f", entry.right); TestCase_assert(entry.bottom == 0.0f, "Expected 0.0 but got %f", entry.bottom); TestCase_assert(entry.top == 0.0f, "Expected 0.0 but got %f", entry.top); } static void testDeserialization() { GLTextureAtlas * atlasPtr, atlas; TestDeserializationContext * context; jmp_buf jmpEnv; bool success; unsigned int failIndex; const char ** keys; size_t keyCount; struct GLTextureAtlas_entry entry; context = TestDeserializationContext_create(&jmpEnv); if (setjmp(jmpEnv) != 0) { TestCase_assert(false, "%s", context->error); } context->vtable->expectCall(context, __LINE__, context->vtable->beginStructure, "gltextureatlas"); context->vtable->expectCall(context, __LINE__, context->vtable->readUInt16, "format_version", GLTEXTUREATLAS_SERIALIZATION_FORMAT_VERSION); context->vtable->expectCall(context, __LINE__, context->vtable->readString, "texture_name", "foo"); context->vtable->expectCall(context, __LINE__, context->vtable->beginDictionary, "entries", 0); context->vtable->expectCall(context, __LINE__, context->vtable->endDictionary); context->vtable->expectCall(context, __LINE__, context->vtable->endStructure); atlasPtr = GLTextureAtlas_deserialize((DeserializationContext *) context); context->vtable->finish(context); TestCase_assert(atlasPtr != NULL, "GLTextureAtlas_deserialize unexpectedly returned NULL"); if (atlasPtr == NULL) { return; } // Silence clang warning TestCase_assert(atlasPtr->textureName != NULL, "Expected non-NULL but got NULL"); TestCase_assert(!strcmp(atlasPtr->textureName, "foo"), "Expected \"foo\" but got \"%s\"", atlasPtr->textureName); TestCase_assert(atlasPtr->texture == NULL, "Expected NULL but got %p", atlasPtr->texture); keyCount = -1; keys = GLTextureAtlas_getKeys(atlasPtr, &keyCount); TestCase_assert(keyCount == 0, "Expected 0 but got " SIZE_T_FORMAT, keyCount); free(keys); GLTextureAtlas_dispose(atlasPtr); context->vtable->rewind(context); success = GLTextureAtlas_loadSerializedData(&atlas, (DeserializationContext *) context); context->vtable->finish(context); context->vtable->dispose(context); TestCase_assert(success, "Expected true but got false"); TestCase_assert(atlas.textureName != NULL, "Expected non-NULL but got NULL"); TestCase_assert(!strcmp(atlas.textureName, "foo"), "Expected \"foo\" but got \"%s\"", atlas.textureName); TestCase_assert(atlas.texture == NULL, "Expected NULL but got %p", atlas.texture); keyCount = -1; keys = GLTextureAtlas_getKeys(&atlas, &keyCount); TestCase_assert(keyCount == 0, "Expected 0 but got " SIZE_T_FORMAT, keyCount); free(keys); GLTextureAtlas_dispose(&atlas); context = TestDeserializationContext_create(&jmpEnv); if (setjmp(jmpEnv) != 0) { TestCase_assert(false, "%s", context->error); } context->vtable->expectCall(context, __LINE__, context->vtable->beginStructure, "gltextureatlas"); context->vtable->expectCall(context, __LINE__, context->vtable->readUInt16, "format_version", GLTEXTUREATLAS_SERIALIZATION_FORMAT_VERSION); context->vtable->expectCall(context, __LINE__, context->vtable->readString, "texture_name", "bar"); context->vtable->expectCall(context, __LINE__, context->vtable->beginDictionary, "entries", 2); context->vtable->expectCall(context, __LINE__, context->vtable->readNextDictionaryKey, "a"); context->vtable->expectCall(context, __LINE__, context->vtable->beginStructure, "a"); context->vtable->expectCall(context, __LINE__, context->vtable->readFloat, "left", 0.0f); context->vtable->expectCall(context, __LINE__, context->vtable->readFloat, "right", 0.25f); context->vtable->expectCall(context, __LINE__, context->vtable->readFloat, "bottom", 0.5f); context->vtable->expectCall(context, __LINE__, context->vtable->readFloat, "top", 0.75f); context->vtable->expectCall(context, __LINE__, context->vtable->endStructure); context->vtable->expectCall(context, __LINE__, context->vtable->readNextDictionaryKey, "b"); context->vtable->expectCall(context, __LINE__, context->vtable->beginStructure, "b"); context->vtable->expectCall(context, __LINE__, context->vtable->readFloat, "left", 0.125f); context->vtable->expectCall(context, __LINE__, context->vtable->readFloat, "right", 0.375f); context->vtable->expectCall(context, __LINE__, context->vtable->readFloat, "bottom", 0.625f); context->vtable->expectCall(context, __LINE__, context->vtable->readFloat, "top", 0.875f); context->vtable->expectCall(context, __LINE__, context->vtable->endStructure); context->vtable->expectCall(context, __LINE__, context->vtable->endDictionary); context->vtable->expectCall(context, __LINE__, context->vtable->endStructure); atlasPtr = GLTextureAtlas_deserialize((DeserializationContext *) context); context->vtable->finish(context); TestCase_assert(atlasPtr != NULL, "GLTextureAtlas_deserialize unexpectedly returned NULL"); if (atlasPtr == NULL) { return; } // Silence clang warning TestCase_assert(atlasPtr->textureName != NULL, "Expected non-NULL but got NULL"); TestCase_assert(!strcmp(atlasPtr->textureName, "bar"), "Expected \"bar\" but got \"%s\"", atlasPtr->textureName); TestCase_assert(atlasPtr->texture == NULL, "Expected NULL but got %p", atlasPtr->texture); keyCount = -1; keys = GLTextureAtlas_getKeys(atlasPtr, &keyCount); TestCase_assert(keyCount == 2, "Expected 2 but got " SIZE_T_FORMAT, keyCount); TestCase_assert(keys != NULL, "Expected non-NULL but got NULL"); TestCase_assert(!strcmp(keys[0], "a") || !strcmp(keys[0], "b"), "Expected \"a\" or \"b\" but got \"%s\"", keys[0]); TestCase_assert(!strcmp(keys[1], "a") || !strcmp(keys[1], "b"), "Expected \"a\" or \"b\" but got \"%s\"", keys[1]); free(keys); TestCase_assert(GLTextureAtlas_hasKey(atlasPtr, "a"), "Expected true but got false"); TestCase_assert(GLTextureAtlas_hasKey(atlasPtr, "b"), "Expected true but got false"); entry = GLTextureAtlas_lookup(atlasPtr, "a"); TestCase_assert(entry.left == 0.0f, "Expected 0.0 but got %f", entry.left); TestCase_assert(entry.right == 0.25f, "Expected 0.25 but got %f", entry.right); TestCase_assert(entry.bottom == 0.5f, "Expected 0.5 but got %f", entry.bottom); TestCase_assert(entry.top == 0.75f, "Expected 0.75 but got %f", entry.top); entry = GLTextureAtlas_lookup(atlasPtr, "b"); TestCase_assert(entry.left == 0.125f, "Expected 0.125 but got %f", entry.left); TestCase_assert(entry.right == 0.375f, "Expected 0.375 but got %f", entry.right); TestCase_assert(entry.bottom == 0.625f, "Expected 0.625 but got %f", entry.bottom); TestCase_assert(entry.top == 0.875f, "Expected 0.875 but got %f", entry.top); GLTextureAtlas_dispose(atlasPtr); context->vtable->rewind(context); success = GLTextureAtlas_loadSerializedData(&atlas, (DeserializationContext *) context); context->vtable->finish(context); TestCase_assert(success, "Expected true but got false"); TestCase_assert(atlas.textureName != NULL, "Expected non-NULL but got NULL"); TestCase_assert(!strcmp(atlas.textureName, "bar"), "Expected \"bar\" but got \"%s\"", atlas.textureName); TestCase_assert(atlas.texture == NULL, "Expected NULL but got %p", atlas.texture); keyCount = -1; keys = GLTextureAtlas_getKeys(&atlas, &keyCount); TestCase_assert(keyCount == 2, "Expected 2 but got " SIZE_T_FORMAT, keyCount); TestCase_assert(keys != NULL, "Expected non-NULL but got NULL"); TestCase_assert(!strcmp(keys[0], "a") || !strcmp(keys[0], "b"), "Expected \"a\" or \"b\" but got \"%s\"", keys[0]); TestCase_assert(!strcmp(keys[1], "a") || !strcmp(keys[1], "b"), "Expected \"a\" or \"b\" but got \"%s\"", keys[1]); free(keys); TestCase_assert(GLTextureAtlas_hasKey(&atlas, "a"), "Expected true but got false"); TestCase_assert(GLTextureAtlas_hasKey(&atlas, "b"), "Expected true but got false"); entry = GLTextureAtlas_lookup(&atlas, "a"); TestCase_assert(entry.left == 0.0f, "Expected 0.0 but got %f", entry.left); TestCase_assert(entry.right == 0.25f, "Expected 0.25 but got %f", entry.right); TestCase_assert(entry.bottom == 0.5f, "Expected 0.5 but got %f", entry.bottom); TestCase_assert(entry.top == 0.75f, "Expected 0.75 but got %f", entry.top); entry = GLTextureAtlas_lookup(&atlas, "b"); TestCase_assert(entry.left == 0.125f, "Expected 0.125 but got %f", entry.left); TestCase_assert(entry.right == 0.375f, "Expected 0.375 but got %f", entry.right); TestCase_assert(entry.bottom == 0.625f, "Expected 0.625 but got %f", entry.bottom); TestCase_assert(entry.top == 0.875f, "Expected 0.875 but got %f", entry.top); GLTextureAtlas_dispose(&atlas); for (failIndex = 0; failIndex < 20; failIndex++) { context->vtable->rewind(context); context->vtable->failNthCall(context, failIndex, 1); atlasPtr = GLTextureAtlas_deserialize((DeserializationContext *) context); TestCase_assert(atlasPtr == NULL, "GLTextureAtlas_deserialize didn't return NULL when deserialization call %d failed", failIndex); context->vtable->rewind(context); context->vtable->failNthCall(context, failIndex, 1); success = GLTextureAtlas_loadSerializedData(&atlas, (DeserializationContext *) context); TestCase_assert(!success, "GLTextureAtlas_loadSerializedData didn't return false when deserialization call %d failed", failIndex); } context->vtable->dispose(context); } static void testSerialization() { GLTextureAtlas atlas; TestSerializationContext * context; jmp_buf jmpEnv; context = TestSerializationContext_create(&jmpEnv); if (setjmp(jmpEnv) != 0) { TestCase_assert(false, "%s", context->error); } GLTextureAtlas_init(&atlas); atlas.textureName = "foo"; context->vtable->expectCall(context, __LINE__, context->vtable->beginStructure, "gltextureatlas"); context->vtable->expectCall(context, __LINE__, context->vtable->writeUInt16, "format_version", GLTEXTUREATLAS_SERIALIZATION_FORMAT_VERSION); context->vtable->expectCall(context, __LINE__, context->vtable->writeString, "texture_name", "foo"); context->vtable->expectCall(context, __LINE__, context->vtable->beginDictionary, "entries"); context->vtable->expectCall(context, __LINE__, context->vtable->endDictionary); context->vtable->expectCall(context, __LINE__, context->vtable->endStructure); GLTextureAtlas_serialize(&atlas, (SerializationContext *) context); context->vtable->finish(context); context->vtable->dispose(context); GLTextureAtlas_dispose(&atlas); context = TestSerializationContext_create(&jmpEnv); if (setjmp(jmpEnv) != 0) { TestCase_assert(false, "%s", context->error); } GLTextureAtlas_init(&atlas); atlas.textureName = "bar"; GLTextureAtlas_setEntry(&atlas, "a", (struct GLTextureAtlas_entry) {0.0f, 0.25f, 0.5f, 0.75f}); GLTextureAtlas_setEntry(&atlas, "b", (struct GLTextureAtlas_entry) {0.125f, 0.375f, 0.625f, 0.875f}); context->vtable->expectCall(context, __LINE__, context->vtable->beginStructure, "gltextureatlas"); context->vtable->expectCall(context, __LINE__, context->vtable->writeUInt16, "format_version", GLTEXTUREATLAS_SERIALIZATION_FORMAT_VERSION); context->vtable->expectCall(context, __LINE__, context->vtable->writeString, "texture_name", "bar"); context->vtable->expectCall(context, __LINE__, context->vtable->beginDictionary, "entries"); context->vtable->expectCall(context, __LINE__, context->vtable->beginStructure, "a"); context->vtable->expectCall(context, __LINE__, context->vtable->writeFloat, "left", 0.0f); context->vtable->expectCall(context, __LINE__, context->vtable->writeFloat, "right", 0.25f); context->vtable->expectCall(context, __LINE__, context->vtable->writeFloat, "bottom", 0.5f); context->vtable->expectCall(context, __LINE__, context->vtable->writeFloat, "top", 0.75f); context->vtable->expectCall(context, __LINE__, context->vtable->endStructure); context->vtable->expectCall(context, __LINE__, context->vtable->beginStructure, "b"); context->vtable->expectCall(context, __LINE__, context->vtable->writeFloat, "left", 0.125f); context->vtable->expectCall(context, __LINE__, context->vtable->writeFloat, "right", 0.375f); context->vtable->expectCall(context, __LINE__, context->vtable->writeFloat, "bottom", 0.625f); context->vtable->expectCall(context, __LINE__, context->vtable->writeFloat, "top", 0.875f); context->vtable->expectCall(context, __LINE__, context->vtable->endStructure); context->vtable->expectCall(context, __LINE__, context->vtable->endDictionary); context->vtable->expectCall(context, __LINE__, context->vtable->endStructure); GLTextureAtlas_serialize(&atlas, (SerializationContext *) context); context->vtable->finish(context); context->vtable->dispose(context); GLTextureAtlas_dispose(&atlas); } static void testFormatVersionVerification() { GLTextureAtlas * atlas; TestDeserializationContext * context; jmp_buf jmpEnv; context = TestDeserializationContext_create(&jmpEnv); if (setjmp(jmpEnv) != 0) { TestCase_assert(false, "%s", context->error); } context->vtable->expectCall(context, __LINE__, context->vtable->beginStructure, "gltextureatlas"); context->vtable->expectCall(context, __LINE__, context->vtable->readUInt16, "format_version", GLTEXTUREATLAS_SERIALIZATION_FORMAT_VERSION + 1); atlas = GLTextureAtlas_deserialize((DeserializationContext *) context); context->vtable->finish(context); context->vtable->dispose(context); TestCase_assert(atlas == NULL, "GLTextureAtlas_deserialize didn't return NULL when format_version was too high"); } static void testGetEntryDimensions() { GLTextureAtlas atlas; GLTexture texture; Vector2f result; GLTexture_init(&texture, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, GL_NEAREST, GL_REPEAT, GL_REPEAT, AUTO_BLEND_MODE_NONE, false, false); texture.pixelWidth = 64; texture.pixelHeight = 128; GLTextureAtlas_init(&atlas); GLTextureAtlas_setTexture(&atlas, &texture, true); GLTextureAtlas_setEntry(&atlas, "a", (struct GLTextureAtlas_entry) {0.0f, 0.5f, 0.25f, 0.75f}); GLTextureAtlas_setEntry(&atlas, "b", (struct GLTextureAtlas_entry) {0.125f, 0.375f, 0.25f, 0.375f}); result = GLTextureAtlas_getEntryDimensions(&atlas, "a", 1.0f, 2.0f); TestCase_assert(result.x == 1.0f, "Expected 1.0f but got %f\n", result.x); TestCase_assert(result.y == 2.0f, "Expected 2.0f but got %f\n", result.y); result = GLTextureAtlas_getEntryDimensions(&atlas, "a", 3.0f, 1.0f); TestCase_assert(result.x == 3.0f, "Expected 3.0f but got %f\n", result.x); TestCase_assert(result.y == 1.0f, "Expected 1.0f but got %f\n", result.y); result = GLTextureAtlas_getEntryDimensions(&atlas, "a", GLTEXTUREATLAS_SIZE_AUTO, GLTEXTUREATLAS_SIZE_AUTO); TestCase_assert(result.x == 32.0f, "Expected 32.0f but got %f\n", result.x); TestCase_assert(result.y == 64.0f, "Expected 64.0f but got %f\n", result.y); result = GLTextureAtlas_getEntryDimensions(&atlas, "b", GLTEXTUREATLAS_SIZE_AUTO, GLTEXTUREATLAS_SIZE_AUTO); TestCase_assert(result.x == 16.0f, "Expected 16.0f but got %f\n", result.x); TestCase_assert(result.y == 16.0f, "Expected 16.0f but got %f\n", result.y); result = GLTextureAtlas_getEntryDimensions(&atlas, "a", 1.0f, GLTEXTUREATLAS_SIZE_AUTO); TestCase_assert(result.x == 1.0f, "Expected 1.0f but got %f\n", result.x); TestCase_assert(result.y == 2.0f, "Expected 2.0f but got %f\n", result.y); result = GLTextureAtlas_getEntryDimensions(&atlas, "a", 2.0f, GLTEXTUREATLAS_SIZE_AUTO); TestCase_assert(result.x == 2.0f, "Expected 2.0f but got %f\n", result.x); TestCase_assert(result.y == 4.0f, "Expected 4.0f but got %f\n", result.y); result = GLTextureAtlas_getEntryDimensions(&atlas, "b", 1.0f, GLTEXTUREATLAS_SIZE_AUTO); TestCase_assert(result.x == 1.0f, "Expected 1.0f but got %f\n", result.x); TestCase_assert(result.y == 1.0f, "Expected 1.0f but got %f\n", result.y); result = GLTextureAtlas_getEntryDimensions(&atlas, "b", 0.5f, GLTEXTUREATLAS_SIZE_AUTO); TestCase_assert(result.x == 0.5f, "Expected 0.5f but got %f\n", result.x); TestCase_assert(result.y == 0.5f, "Expected 0.5f but got %f\n", result.y); result = GLTextureAtlas_getEntryDimensions(&atlas, "a", GLTEXTUREATLAS_SIZE_AUTO, 1.0f); TestCase_assert(result.x == 0.5f, "Expected 0.5f but got %f\n", result.x); TestCase_assert(result.y == 1.0f, "Expected 1.0f but got %f\n", result.y); result = GLTextureAtlas_getEntryDimensions(&atlas, "a", GLTEXTUREATLAS_SIZE_AUTO, 2.0f); TestCase_assert(result.x == 1.0f, "Expected 1.0f but got %f\n", result.x); TestCase_assert(result.y == 2.0f, "Expected 2.0f but got %f\n", result.y); result = GLTextureAtlas_getEntryDimensions(&atlas, "b", GLTEXTUREATLAS_SIZE_AUTO, 1.0f); TestCase_assert(result.x == 1.0f, "Expected 1.0f but got %f\n", result.x); TestCase_assert(result.y == 1.0f, "Expected 1.0f but got %f\n", result.y); result = GLTextureAtlas_getEntryDimensions(&atlas, "b", GLTEXTUREATLAS_SIZE_AUTO, 0.5f); TestCase_assert(result.x == 0.5f, "Expected 0.5f but got %f\n", result.x); TestCase_assert(result.y == 0.5f, "Expected 0.5f but got %f\n", result.y); texture.pixelWidth = 32; texture.pixelHeight = 16; result = GLTextureAtlas_getEntryDimensions(&atlas, "a", GLTEXTUREATLAS_SIZE_AUTO, GLTEXTUREATLAS_SIZE_AUTO); TestCase_assert(result.x == 16.0f, "Expected 16.0f but got %f\n", result.x); TestCase_assert(result.y == 8.0f, "Expected 8.0f but got %f\n", result.y); result = GLTextureAtlas_getEntryDimensions(&atlas, "b", GLTEXTUREATLAS_SIZE_AUTO, GLTEXTUREATLAS_SIZE_AUTO); TestCase_assert(result.x == 8.0f, "Expected 8.0f but got %f\n", result.x); TestCase_assert(result.y == 2.0f, "Expected 2.0f but got %f\n", result.y); result = GLTextureAtlas_getEntryDimensions(&atlas, "a", 1.0f, GLTEXTUREATLAS_SIZE_AUTO); TestCase_assert(result.x == 1.0f, "Expected 1.0f but got %f\n", result.x); TestCase_assert(result.y == 0.5f, "Expected 0.5f but got %f\n", result.y); result = GLTextureAtlas_getEntryDimensions(&atlas, "a", 2.0f, GLTEXTUREATLAS_SIZE_AUTO); TestCase_assert(result.x == 2.0f, "Expected 2.0f but got %f\n", result.x); TestCase_assert(result.y == 1.0f, "Expected 1.0f but got %f\n", result.y); result = GLTextureAtlas_getEntryDimensions(&atlas, "b", 1.0f, GLTEXTUREATLAS_SIZE_AUTO); TestCase_assert(result.x == 1.0f, "Expected 1.0f but got %f\n", result.x); TestCase_assert(result.y == 0.25f, "Expected 0.25f but got %f\n", result.y); result = GLTextureAtlas_getEntryDimensions(&atlas, "b", 0.5f, GLTEXTUREATLAS_SIZE_AUTO); TestCase_assert(result.x == 0.5f, "Expected 0.5f but got %f\n", result.x); TestCase_assert(result.y == 0.125f, "Expected 0.125f but got %f\n", result.y); result = GLTextureAtlas_getEntryDimensions(&atlas, "a", GLTEXTUREATLAS_SIZE_AUTO, 1.0f); TestCase_assert(result.x == 2.0f, "Expected 2.0f but got %f\n", result.x); TestCase_assert(result.y == 1.0f, "Expected 1.0f but got %f\n", result.y); result = GLTextureAtlas_getEntryDimensions(&atlas, "a", GLTEXTUREATLAS_SIZE_AUTO, 2.0f); TestCase_assert(result.x == 4.0f, "Expected 4.0f but got %f\n", result.x); TestCase_assert(result.y == 2.0f, "Expected 2.0f but got %f\n", result.y); result = GLTextureAtlas_getEntryDimensions(&atlas, "b", GLTEXTUREATLAS_SIZE_AUTO, 1.0f); TestCase_assert(result.x == 4.0f, "Expected 4.0f but got %f\n", result.x); TestCase_assert(result.y == 1.0f, "Expected 1.0f but got %f\n", result.y); result = GLTextureAtlas_getEntryDimensions(&atlas, "b", GLTEXTUREATLAS_SIZE_AUTO, 0.5f); TestCase_assert(result.x == 2.0f, "Expected 2.0f but got %f\n", result.x); TestCase_assert(result.y == 0.5f, "Expected 0.5f but got %f\n", result.y); GLTextureAtlas_dispose(&atlas); } static void testGetVertices() { GLTextureAtlas atlas; unsigned int vertexCount, indexCount; struct vertex_p2f_t2f vertices[6]; GLubyte indexesByte[8]; GLushort indexesShort[6]; GLuint indexesInt[6]; GLTextureAtlas_init(&atlas); GLTextureAtlas_setEntry(&atlas, "a", (struct GLTextureAtlas_entry) {0.0f, 0.25f, 0.5f, 0.75f}); GLTextureAtlas_setEntry(&atlas, "b", (struct GLTextureAtlas_entry) {0.125f, 0.375f, 0.625f, 0.875f}); vertexCount = indexCount = 0; GLTextureAtlas_getVertices(&atlas, "a", VECTOR2f(0.0f, 0.0f), VECTOR2f(0.0f, 0.0f), VECTOR2f(0.0f, 0.0f), GL_UNSIGNED_INT, NULL, NULL, &vertexCount, &indexCount); TestCase_assert(vertexCount == 4, "Expected 4 but got %u", vertexCount); TestCase_assert(indexCount == 6, "Expected 6 but got %u", indexCount); memset(vertices, 0xFF, sizeof(vertices)); memset(indexesByte, 0xFF, sizeof(indexesByte)); vertexCount = 1; indexCount = 2; GLTextureAtlas_getVertices(&atlas, "a", VECTOR2f(0.0f, 0.0f), VECTOR2f(0.0f, 0.0f), VECTOR2f(1.0f, 1.0f), GL_UNSIGNED_BYTE, vertices, indexesByte, &vertexCount, &indexCount); TestCase_assert(vertexCount == 5, "Expected 5 but got %u", vertexCount); TestCase_assert(vertices[1].position[0] == 0.0f, "Expected 0.0 but got %f\n", vertices[1].position[0]); TestCase_assert(vertices[1].position[1] == 0.0f, "Expected 0.0 but got %f\n", vertices[1].position[1]); TestCase_assert(vertices[1].texCoords[0] == 0.0f, "Expected 0.0 but got %f\n", vertices[1].texCoords[0]); TestCase_assert(vertices[1].texCoords[1] == 0.5f, "Expected 0.5 but got %f\n", vertices[1].texCoords[1]); TestCase_assert(vertices[2].position[0] == 1.0f, "Expected 1.0 but got %f\n", vertices[2].position[0]); TestCase_assert(vertices[2].position[1] == 0.0f, "Expected 0.0 but got %f\n", vertices[2].position[1]); TestCase_assert(vertices[2].texCoords[0] == 0.25f, "Expected 0.25 but got %f\n", vertices[2].texCoords[0]); TestCase_assert(vertices[2].texCoords[1] == 0.5f, "Expected 0.5 but got %f\n", vertices[2].texCoords[1]); TestCase_assert(vertices[3].position[0] == 1.0f, "Expected 1.0 but got %f\n", vertices[3].position[0]); TestCase_assert(vertices[3].position[1] == 1.0f, "Expected 1.0 but got %f\n", vertices[3].position[1]); TestCase_assert(vertices[3].texCoords[0] == 0.25f, "Expected 0.25 but got %f\n", vertices[3].texCoords[0]); TestCase_assert(vertices[3].texCoords[1] == 0.75f, "Expected 0.75 but got %f\n", vertices[3].texCoords[1]); TestCase_assert(vertices[4].position[0] == 0.0f, "Expected 0.0 but got %f\n", vertices[4].position[0]); TestCase_assert(vertices[4].position[1] == 1.0f, "Expected 1.0 but got %f\n", vertices[4].position[1]); TestCase_assert(vertices[4].texCoords[0] == 0.0f, "Expected 0.0 but got %f\n", vertices[4].texCoords[0]); TestCase_assert(vertices[4].texCoords[1] == 0.75f, "Expected 0.75 but got %f\n", vertices[4].texCoords[1]); TestCase_assert(indexCount == 8, "Expected 8 but got %u", indexCount); TestCase_assert(indexesByte[2] == 1, "Expected 1 but got %u", indexesByte[2]); TestCase_assert(indexesByte[3] == 2, "Expected 2 but got %u", indexesByte[3]); TestCase_assert(indexesByte[4] == 3, "Expected 3 but got %u", indexesByte[4]); TestCase_assert(indexesByte[5] == 3, "Expected 3 but got %u", indexesByte[5]); TestCase_assert(indexesByte[6] == 4, "Expected 4 but got %u", indexesByte[6]); TestCase_assert(indexesByte[7] == 1, "Expected 1 but got %u", indexesByte[7]); memset(vertices, 0xFF, sizeof(vertices)); memset(indexesShort, 0xFF, sizeof(indexesShort)); vertexCount = 1; indexCount = 0; GLTextureAtlas_getVertices(&atlas, "b", VECTOR2f(0.0f, 0.0f), VECTOR2f(0.0f, 0.0f), VECTOR2f(1.0f, 1.0f), GL_UNSIGNED_SHORT, vertices, indexesShort, &vertexCount, &indexCount); TestCase_assert(vertexCount == 5, "Expected 5 but got %u", vertexCount); TestCase_assert(vertices[1].position[0] == 0.0f, "Expected 0.0 but got %f\n", vertices[1].position[0]); TestCase_assert(vertices[1].position[1] == 0.0f, "Expected 0.0 but got %f\n", vertices[1].position[1]); TestCase_assert(vertices[1].texCoords[0] == 0.125f, "Expected 0.125 but got %f\n", vertices[1].texCoords[0]); TestCase_assert(vertices[1].texCoords[1] == 0.625f, "Expected 0.625 but got %f\n", vertices[1].texCoords[1]); TestCase_assert(vertices[2].position[0] == 1.0f, "Expected 1.0 but got %f\n", vertices[2].position[0]); TestCase_assert(vertices[2].position[1] == 0.0f, "Expected 0.0 but got %f\n", vertices[2].position[1]); TestCase_assert(vertices[2].texCoords[0] == 0.375f, "Expected 0.375 but got %f\n", vertices[2].texCoords[0]); TestCase_assert(vertices[2].texCoords[1] == 0.625f, "Expected 0.625 but got %f\n", vertices[2].texCoords[1]); TestCase_assert(vertices[3].position[0] == 1.0f, "Expected 1.0 but got %f\n", vertices[3].position[0]); TestCase_assert(vertices[3].position[1] == 1.0f, "Expected 1.0 but got %f\n", vertices[3].position[1]); TestCase_assert(vertices[3].texCoords[0] == 0.375f, "Expected 0.375 but got %f\n", vertices[3].texCoords[0]); TestCase_assert(vertices[3].texCoords[1] == 0.875f, "Expected 0.875 but got %f\n", vertices[3].texCoords[1]); TestCase_assert(vertices[4].position[0] == 0.0f, "Expected 0.0 but got %f\n", vertices[4].position[0]); TestCase_assert(vertices[4].position[1] == 1.0f, "Expected 1.0 but got %f\n", vertices[4].position[1]); TestCase_assert(vertices[4].texCoords[0] == 0.125f, "Expected 0.125 but got %f\n", vertices[4].texCoords[0]); TestCase_assert(vertices[4].texCoords[1] == 0.875f, "Expected 0.875 but got %f\n", vertices[4].texCoords[1]); TestCase_assert(indexCount == 6, "Expected 6 but got %u", indexCount); TestCase_assert(indexesShort[0] == 1, "Expected 1 but got %u", indexesShort[0]); TestCase_assert(indexesShort[1] == 2, "Expected 2 but got %u", indexesShort[1]); TestCase_assert(indexesShort[2] == 3, "Expected 3 but got %u", indexesShort[2]); TestCase_assert(indexesShort[3] == 3, "Expected 3 but got %u", indexesShort[3]); TestCase_assert(indexesShort[4] == 4, "Expected 4 but got %u", indexesShort[4]); TestCase_assert(indexesShort[5] == 1, "Expected 1 but got %u", indexesShort[5]); memset(vertices, 0xFF, sizeof(vertices)); memset(indexesInt, 0xFF, sizeof(indexesInt)); vertexCount = 2; indexCount = 0; GLTextureAtlas_getVertices(&atlas, "a", VECTOR2f(6.0f, -3.0f), VECTOR2f(0.5f, 1.0f), VECTOR2f(2.0f, 1.5f), GL_UNSIGNED_INT, vertices, indexesInt, &vertexCount, &indexCount); TestCase_assert(vertexCount == 6, "Expected 6 but got %u", vertexCount); TestCase_assert(vertices[2].position[0] == 5.0f, "Expected 5.0 but got %f\n", vertices[2].position[0]); TestCase_assert(vertices[2].position[1] == -4.5f, "Expected -4.5 but got %f\n", vertices[2].position[1]); TestCase_assert(vertices[2].texCoords[0] == 0.0f, "Expected 0.0 but got %f\n", vertices[2].texCoords[0]); TestCase_assert(vertices[2].texCoords[1] == 0.5f, "Expected 0.5 but got %f\n", vertices[2].texCoords[1]); TestCase_assert(vertices[3].position[0] == 7.0f, "Expected 7.0 but got %f\n", vertices[3].position[0]); TestCase_assert(vertices[3].position[1] == -4.5f, "Expected -4.5 but got %f\n", vertices[3].position[1]); TestCase_assert(vertices[3].texCoords[0] == 0.25f, "Expected 0.25 but got %f\n", vertices[3].texCoords[0]); TestCase_assert(vertices[3].texCoords[1] == 0.5f, "Expected 0.5 but got %f\n", vertices[3].texCoords[1]); TestCase_assert(vertices[4].position[0] == 7.0f, "Expected 7.0 but got %f\n", vertices[4].position[0]); TestCase_assert(vertices[4].position[1] == -3.0f, "Expected -3.0 but got %f\n", vertices[4].position[1]); TestCase_assert(vertices[4].texCoords[0] == 0.25f, "Expected 0.25 but got %f\n", vertices[4].texCoords[0]); TestCase_assert(vertices[4].texCoords[1] == 0.75f, "Expected 0.75 but got %f\n", vertices[4].texCoords[1]); TestCase_assert(vertices[5].position[0] == 5.0f, "Expected 5.0 but got %f\n", vertices[5].position[0]); TestCase_assert(vertices[5].position[1] == -3.0f, "Expected -3.0 but got %f\n", vertices[5].position[1]); TestCase_assert(vertices[5].texCoords[0] == 0.0f, "Expected 0.0 but got %f\n", vertices[5].texCoords[0]); TestCase_assert(vertices[5].texCoords[1] == 0.75f, "Expected 0.75 but got %f\n", vertices[5].texCoords[1]); TestCase_assert(indexCount == 6, "Expected 6 but got %u", indexCount); TestCase_assert(indexesInt[0] == 2, "Expected 2 but got %u", indexesInt[0]); TestCase_assert(indexesInt[1] == 3, "Expected 3 but got %u", indexesInt[1]); TestCase_assert(indexesInt[2] == 4, "Expected 4 but got %u", indexesInt[2]); TestCase_assert(indexesInt[3] == 4, "Expected 4 but got %u", indexesInt[3]); TestCase_assert(indexesInt[4] == 5, "Expected 5 but got %u", indexesInt[4]); TestCase_assert(indexesInt[5] == 2, "Expected 2 but got %u", indexesInt[5]); } static void testGetVerticesWithColor() { GLTextureAtlas atlas; unsigned int vertexCount, indexCount; struct vertex_p2f_t2f_c4f vertices[6]; GLubyte indexesByte[8]; GLushort indexesShort[6]; GLuint indexesInt[6]; GLTextureAtlas_init(&atlas); GLTextureAtlas_setEntry(&atlas, "a", (struct GLTextureAtlas_entry) {0.0f, 0.25f, 0.5f, 0.75f}); GLTextureAtlas_setEntry(&atlas, "b", (struct GLTextureAtlas_entry) {0.125f, 0.375f, 0.625f, 0.875f}); vertexCount = indexCount = 0; GLTextureAtlas_getVerticesWithColor(&atlas, "a", VECTOR2f(0.0f, 0.0f), VECTOR2f(0.0f, 0.0f), VECTOR2f(0.0f, 0.0f), COLOR4f(0.0f, 0.0f, 0.0f, 0.0f), GL_UNSIGNED_INT, NULL, NULL, &vertexCount, &indexCount); TestCase_assert(vertexCount == 4, "Expected 4 but got %u", vertexCount); TestCase_assert(indexCount == 6, "Expected 6 but got %u", indexCount); memset(vertices, 0xFF, sizeof(vertices)); memset(indexesByte, 0xFF, sizeof(indexesByte)); vertexCount = 1; indexCount = 2; GLTextureAtlas_getVerticesWithColor(&atlas, "a", VECTOR2f(0.0f, 0.0f), VECTOR2f(0.0f, 0.0f), VECTOR2f(1.0f, 1.0f), COLOR4f(0.0f, 0.0f, 0.0f, 0.0f), GL_UNSIGNED_BYTE, vertices, indexesByte, &vertexCount, &indexCount); TestCase_assert(vertexCount == 5, "Expected 5 but got %u", vertexCount); TestCase_assert(vertices[1].position[0] == 0.0f, "Expected 0.0 but got %f\n", vertices[1].position[0]); TestCase_assert(vertices[1].position[1] == 0.0f, "Expected 0.0 but got %f\n", vertices[1].position[1]); TestCase_assert(vertices[1].texCoords[0] == 0.0f, "Expected 0.0 but got %f\n", vertices[1].texCoords[0]); TestCase_assert(vertices[1].texCoords[1] == 0.5f, "Expected 0.5 but got %f\n", vertices[1].texCoords[1]); TestCase_assert(vertices[1].color[0] == 0.0f, "Expected 0.0 but got %f\n", vertices[1].color[0]); TestCase_assert(vertices[1].color[1] == 0.0f, "Expected 0.0 but got %f\n", vertices[1].color[1]); TestCase_assert(vertices[1].color[2] == 0.0f, "Expected 0.0 but got %f\n", vertices[1].color[2]); TestCase_assert(vertices[1].color[3] == 0.0f, "Expected 0.0 but got %f\n", vertices[1].color[3]); TestCase_assert(vertices[2].position[0] == 1.0f, "Expected 1.0 but got %f\n", vertices[2].position[0]); TestCase_assert(vertices[2].position[1] == 0.0f, "Expected 0.0 but got %f\n", vertices[2].position[1]); TestCase_assert(vertices[2].texCoords[0] == 0.25f, "Expected 0.25 but got %f\n", vertices[2].texCoords[0]); TestCase_assert(vertices[2].texCoords[1] == 0.5f, "Expected 0.5 but got %f\n", vertices[2].texCoords[1]); TestCase_assert(vertices[2].color[0] == 0.0f, "Expected 0.0 but got %f\n", vertices[2].color[0]); TestCase_assert(vertices[2].color[1] == 0.0f, "Expected 0.0 but got %f\n", vertices[2].color[1]); TestCase_assert(vertices[2].color[2] == 0.0f, "Expected 0.0 but got %f\n", vertices[2].color[2]); TestCase_assert(vertices[2].color[3] == 0.0f, "Expected 0.0 but got %f\n", vertices[2].color[3]); TestCase_assert(vertices[3].position[0] == 1.0f, "Expected 1.0 but got %f\n", vertices[3].position[0]); TestCase_assert(vertices[3].position[1] == 1.0f, "Expected 1.0 but got %f\n", vertices[3].position[1]); TestCase_assert(vertices[3].texCoords[0] == 0.25f, "Expected 0.25 but got %f\n", vertices[3].texCoords[0]); TestCase_assert(vertices[3].texCoords[1] == 0.75f, "Expected 0.75 but got %f\n", vertices[3].texCoords[1]); TestCase_assert(vertices[3].color[0] == 0.0f, "Expected 0.0 but got %f\n", vertices[3].color[0]); TestCase_assert(vertices[3].color[1] == 0.0f, "Expected 0.0 but got %f\n", vertices[3].color[1]); TestCase_assert(vertices[3].color[2] == 0.0f, "Expected 0.0 but got %f\n", vertices[3].color[2]); TestCase_assert(vertices[3].color[3] == 0.0f, "Expected 0.0 but got %f\n", vertices[3].color[3]); TestCase_assert(vertices[4].position[0] == 0.0f, "Expected 0.0 but got %f\n", vertices[4].position[0]); TestCase_assert(vertices[4].position[1] == 1.0f, "Expected 1.0 but got %f\n", vertices[4].position[1]); TestCase_assert(vertices[4].texCoords[0] == 0.0f, "Expected 0.0 but got %f\n", vertices[4].texCoords[0]); TestCase_assert(vertices[4].texCoords[1] == 0.75f, "Expected 0.75 but got %f\n", vertices[4].texCoords[1]); TestCase_assert(vertices[4].color[0] == 0.0f, "Expected 0.0 but got %f\n", vertices[4].color[0]); TestCase_assert(vertices[4].color[1] == 0.0f, "Expected 0.0 but got %f\n", vertices[4].color[1]); TestCase_assert(vertices[4].color[2] == 0.0f, "Expected 0.0 but got %f\n", vertices[4].color[2]); TestCase_assert(vertices[4].color[3] == 0.0f, "Expected 0.0 but got %f\n", vertices[4].color[3]); TestCase_assert(indexCount == 8, "Expected 8 but got %u", indexCount); TestCase_assert(indexesByte[2] == 1, "Expected 1 but got %u", indexesByte[2]); TestCase_assert(indexesByte[3] == 2, "Expected 2 but got %u", indexesByte[3]); TestCase_assert(indexesByte[4] == 3, "Expected 3 but got %u", indexesByte[4]); TestCase_assert(indexesByte[5] == 3, "Expected 3 but got %u", indexesByte[5]); TestCase_assert(indexesByte[6] == 4, "Expected 4 but got %u", indexesByte[6]); TestCase_assert(indexesByte[7] == 1, "Expected 1 but got %u", indexesByte[7]); memset(vertices, 0xFF, sizeof(vertices)); memset(indexesShort, 0xFF, sizeof(indexesShort)); vertexCount = indexCount = 0; GLTextureAtlas_getVerticesWithColor(&atlas, "b", VECTOR2f(0.0f, 0.0f), VECTOR2f(0.0f, 0.0f), VECTOR2f(1.0f, 1.0f), COLOR4f(0.25f, 0.5f, 0.75f, 1.0f), GL_UNSIGNED_SHORT, vertices, indexesShort, &vertexCount, &indexCount); TestCase_assert(vertexCount == 4, "Expected 4 but got %u", vertexCount); TestCase_assert(vertices[0].position[0] == 0.0f, "Expected 0.0 but got %f\n", vertices[0].position[0]); TestCase_assert(vertices[0].position[1] == 0.0f, "Expected 0.0 but got %f\n", vertices[0].position[1]); TestCase_assert(vertices[0].texCoords[0] == 0.125f, "Expected 0.125 but got %f\n", vertices[0].texCoords[0]); TestCase_assert(vertices[0].texCoords[1] == 0.625f, "Expected 0.625 but got %f\n", vertices[0].texCoords[1]); TestCase_assert(vertices[0].color[0] == 0.25f, "Expected 0.25 but got %f\n", vertices[0].color[0]); TestCase_assert(vertices[0].color[1] == 0.5f, "Expected 0.5 but got %f\n", vertices[0].color[1]); TestCase_assert(vertices[0].color[2] == 0.75f, "Expected 0.75 but got %f\n", vertices[0].color[2]); TestCase_assert(vertices[0].color[3] == 1.0f, "Expected 1.0 but got %f\n", vertices[0].color[3]); TestCase_assert(vertices[1].position[0] == 1.0f, "Expected 1.0 but got %f\n", vertices[1].position[0]); TestCase_assert(vertices[1].position[1] == 0.0f, "Expected 0.0 but got %f\n", vertices[1].position[1]); TestCase_assert(vertices[1].texCoords[0] == 0.375f, "Expected 0.375 but got %f\n", vertices[1].texCoords[0]); TestCase_assert(vertices[1].texCoords[1] == 0.625f, "Expected 0.625 but got %f\n", vertices[1].texCoords[1]); TestCase_assert(vertices[1].color[0] == 0.25f, "Expected 0.25 but got %f\n", vertices[1].color[0]); TestCase_assert(vertices[1].color[1] == 0.5f, "Expected 0.5 but got %f\n", vertices[1].color[1]); TestCase_assert(vertices[1].color[2] == 0.75f, "Expected 0.75 but got %f\n", vertices[1].color[2]); TestCase_assert(vertices[1].color[3] == 1.0f, "Expected 1.0 but got %f\n", vertices[1].color[3]); TestCase_assert(vertices[2].position[0] == 1.0f, "Expected 1.0 but got %f\n", vertices[2].position[0]); TestCase_assert(vertices[2].position[1] == 1.0f, "Expected 1.0 but got %f\n", vertices[2].position[1]); TestCase_assert(vertices[2].texCoords[0] == 0.375f, "Expected 0.375 but got %f\n", vertices[2].texCoords[0]); TestCase_assert(vertices[2].texCoords[1] == 0.875f, "Expected 0.875 but got %f\n", vertices[2].texCoords[1]); TestCase_assert(vertices[2].color[0] == 0.25f, "Expected 0.25 but got %f\n", vertices[2].color[0]); TestCase_assert(vertices[2].color[1] == 0.5f, "Expected 0.5 but got %f\n", vertices[2].color[1]); TestCase_assert(vertices[2].color[2] == 0.75f, "Expected 0.75 but got %f\n", vertices[2].color[2]); TestCase_assert(vertices[2].color[3] == 1.0f, "Expected 1.0 but got %f\n", vertices[2].color[3]); TestCase_assert(vertices[3].position[0] == 0.0f, "Expected 0.0 but got %f\n", vertices[3].position[0]); TestCase_assert(vertices[3].position[1] == 1.0f, "Expected 1.0 but got %f\n", vertices[3].position[1]); TestCase_assert(vertices[3].texCoords[0] == 0.125f, "Expected 0.125 but got %f\n", vertices[3].texCoords[0]); TestCase_assert(vertices[3].texCoords[1] == 0.875f, "Expected 0.875 but got %f\n", vertices[3].texCoords[1]); TestCase_assert(vertices[3].color[0] == 0.25f, "Expected 0.25 but got %f\n", vertices[3].color[0]); TestCase_assert(vertices[3].color[1] == 0.5f, "Expected 0.5 but got %f\n", vertices[3].color[1]); TestCase_assert(vertices[3].color[2] == 0.75f, "Expected 0.75 but got %f\n", vertices[3].color[2]); TestCase_assert(vertices[3].color[3] == 1.0f, "Expected 1.0 but got %f\n", vertices[3].color[3]); TestCase_assert(indexCount == 6, "Expected 6 but got %u", indexCount); TestCase_assert(indexesShort[0] == 0, "Expected 0 but got %u", indexesShort[0]); TestCase_assert(indexesShort[1] == 1, "Expected 1 but got %u", indexesShort[1]); TestCase_assert(indexesShort[2] == 2, "Expected 2 but got %u", indexesShort[2]); TestCase_assert(indexesShort[3] == 2, "Expected 2 but got %u", indexesShort[3]); TestCase_assert(indexesShort[4] == 3, "Expected 3 but got %u", indexesShort[4]); TestCase_assert(indexesShort[5] == 0, "Expected 0 but got %u", indexesShort[5]); memset(vertices, 0xFF, sizeof(vertices)); memset(indexesInt, 0xFF, sizeof(indexesInt)); vertexCount = indexCount = 0; GLTextureAtlas_getVerticesWithColor(&atlas, "a", VECTOR2f(6.0f, -3.0f), VECTOR2f(0.5f, 1.0f), VECTOR2f(2.0f, 1.5f), COLOR4f(0.25f, 0.5f, 0.75f, 1.0f), GL_UNSIGNED_INT, vertices, indexesInt, &vertexCount, &indexCount); TestCase_assert(vertexCount == 4, "Expected 4 but got %u", vertexCount); TestCase_assert(vertices[0].position[0] == 5.0f, "Expected 5.0 but got %f\n", vertices[0].position[0]); TestCase_assert(vertices[0].position[1] == -4.5f, "Expected -4.5 but got %f\n", vertices[0].position[1]); TestCase_assert(vertices[0].texCoords[0] == 0.0f, "Expected 0.0 but got %f\n", vertices[0].texCoords[0]); TestCase_assert(vertices[0].texCoords[1] == 0.5f, "Expected 0.5 but got %f\n", vertices[0].texCoords[1]); TestCase_assert(vertices[0].color[0] == 0.25f, "Expected 0.25 but got %f\n", vertices[0].color[0]); TestCase_assert(vertices[0].color[1] == 0.5f, "Expected 0.5 but got %f\n", vertices[0].color[1]); TestCase_assert(vertices[0].color[2] == 0.75f, "Expected 0.75 but got %f\n", vertices[0].color[2]); TestCase_assert(vertices[0].color[3] == 1.0f, "Expected 1.0 but got %f\n", vertices[0].color[3]); TestCase_assert(vertices[1].position[0] == 7.0f, "Expected 7.0 but got %f\n", vertices[1].position[0]); TestCase_assert(vertices[1].position[1] == -4.5f, "Expected -4.5 but got %f\n", vertices[1].position[1]); TestCase_assert(vertices[1].texCoords[0] == 0.25f, "Expected 0.25 but got %f\n", vertices[1].texCoords[0]); TestCase_assert(vertices[1].texCoords[1] == 0.5f, "Expected 0.5 but got %f\n", vertices[1].texCoords[1]); TestCase_assert(vertices[1].color[0] == 0.25f, "Expected 0.25 but got %f\n", vertices[1].color[0]); TestCase_assert(vertices[1].color[1] == 0.5f, "Expected 0.5 but got %f\n", vertices[1].color[1]); TestCase_assert(vertices[1].color[2] == 0.75f, "Expected 0.75 but got %f\n", vertices[1].color[2]); TestCase_assert(vertices[1].color[3] == 1.0f, "Expected 1.0 but got %f\n", vertices[1].color[3]); TestCase_assert(vertices[2].position[0] == 7.0f, "Expected 7.0 but got %f\n", vertices[2].position[0]); TestCase_assert(vertices[2].position[1] == -3.0f, "Expected -3.0 but got %f\n", vertices[2].position[1]); TestCase_assert(vertices[2].texCoords[0] == 0.25f, "Expected 0.25 but got %f\n", vertices[2].texCoords[0]); TestCase_assert(vertices[2].texCoords[1] == 0.75f, "Expected 0.75 but got %f\n", vertices[2].texCoords[1]); TestCase_assert(vertices[2].color[0] == 0.25f, "Expected 0.25 but got %f\n", vertices[2].color[0]); TestCase_assert(vertices[2].color[1] == 0.5f, "Expected 0.5 but got %f\n", vertices[2].color[1]); TestCase_assert(vertices[2].color[2] == 0.75f, "Expected 0.75 but got %f\n", vertices[2].color[2]); TestCase_assert(vertices[2].color[3] == 1.0f, "Expected 1.0 but got %f\n", vertices[2].color[3]); TestCase_assert(vertices[3].position[0] == 5.0f, "Expected 5.0 but got %f\n", vertices[3].position[0]); TestCase_assert(vertices[3].position[1] == -3.0f, "Expected -3.0 but got %f\n", vertices[3].position[1]); TestCase_assert(vertices[3].texCoords[0] == 0.0f, "Expected 0.0 but got %f\n", vertices[3].texCoords[0]); TestCase_assert(vertices[3].texCoords[1] == 0.75f, "Expected 0.75 but got %f\n", vertices[3].texCoords[1]); TestCase_assert(vertices[3].color[0] == 0.25f, "Expected 0.25 but got %f\n", vertices[3].color[0]); TestCase_assert(vertices[3].color[1] == 0.5f, "Expected 0.5 but got %f\n", vertices[3].color[1]); TestCase_assert(vertices[3].color[2] == 0.75f, "Expected 0.75 but got %f\n", vertices[3].color[2]); TestCase_assert(vertices[3].color[3] == 1.0f, "Expected 1.0 but got %f\n", vertices[3].color[3]); TestCase_assert(indexCount == 6, "Expected 6 but got %u", indexCount); TestCase_assert(indexesInt[0] == 0, "Expected 0 but got %u", indexesInt[0]); TestCase_assert(indexesInt[1] == 1, "Expected 1 but got %u", indexesInt[1]); TestCase_assert(indexesInt[2] == 2, "Expected 2 but got %u", indexesInt[2]); TestCase_assert(indexesInt[3] == 2, "Expected 2 but got %u", indexesInt[3]); TestCase_assert(indexesInt[4] == 3, "Expected 3 but got %u", indexesInt[4]); TestCase_assert(indexesInt[5] == 0, "Expected 0 but got %u", indexesInt[5]); } TEST_SUITE(GLTextureAtlasTest, testInit, testSetRemoveEntry, testDeserialization, testSerialization, testGetEntryDimensions, testGetVertices, testGetVerticesWithColor, testFormatVersionVerification)