From a9759384cd99ab6be59c5dd4a1054a8ddd52c36a Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 30 Sep 2024 15:35:08 +1000 Subject: [PATCH] Fixed bad tests with 64 bit platforms --- source/toy_string.h | 6 ++++-- tests/cases/test_memory.c | 2 +- tests/cases/test_string.c | 16 ++++++++-------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/source/toy_string.h b/source/toy_string.h index 349da24..0244bd8 100644 --- a/source/toy_string.h +++ b/source/toy_string.h @@ -12,6 +12,8 @@ typedef struct Toy_String { //32 | 64 BITNESS int length; //4 | 4 int refCount; //4 | 4 + int _padding; //4 | 4 + union { struct { struct Toy_String* left; //4 | 8 @@ -19,11 +21,11 @@ typedef struct Toy_String { //32 | 64 BITNESS } node; //8 | 16 struct { - int dummy; //4 | 4 + int _dummy; //4 | 4 char data[]; //- | - } leaf; //4 | 4 } as; //8 | 16 -} Toy_String; //20 | 28 +} Toy_String; //24 | 32 TOY_API Toy_String* Toy_createString(Toy_Bucket** bucket, const char* cstring); TOY_API Toy_String* Toy_createStringLength(Toy_Bucket** bucket, const char* cstring, int length); diff --git a/tests/cases/test_memory.c b/tests/cases/test_memory.c index 431d8cb..137960b 100644 --- a/tests/cases/test_memory.c +++ b/tests/cases/test_memory.c @@ -66,7 +66,7 @@ int test_buckets() { //check if (bucket == NULL || bucket->count != 4 * sizeof(int)) { - fprintf(stderr, TOY_CC_ERROR "ERROR: failed to partition 'Toy_Bucket' correctly: count is %d, expected %d\n" TOY_CC_RESET, bucket->count, (int)(4*sizeof(int))); + fprintf(stderr, TOY_CC_ERROR "ERROR: failed to partition 'Toy_Bucket' correctly: count is %d, expected %d\n" TOY_CC_RESET, (int)(bucket->count), (int)(4*sizeof(int))); return -1; } diff --git a/tests/cases/test_string.c b/tests/cases/test_string.c index 2988447..2ad279a 100644 --- a/tests/cases/test_string.c +++ b/tests/cases/test_string.c @@ -9,8 +9,8 @@ int test_sizeof_string_64bit() { //test for the correct size { - if (sizeof(Toy_String) != 28) { - fprintf(stderr, TOY_CC_ERROR "ERROR: 'Toy_String' is an unexpected size in memory\n" TOY_CC_RESET); + if (sizeof(Toy_String) != 32) { + fprintf(stderr, TOY_CC_ERROR "ERROR: 'Toy_String' is an unexpected size in memory: expected 32, found %d \n" TOY_CC_RESET, (int)sizeof(Toy_String)); return -1; } } @@ -21,8 +21,8 @@ int test_sizeof_string_64bit() { int test_sizeof_string_32bit() { //test for the correct size { - if (sizeof(Toy_String) != 20) { - fprintf(stderr, TOY_CC_ERROR "ERROR: 'Toy_String' is an unexpected size in memory\n" TOY_CC_RESET); + if (sizeof(Toy_String) != 24) { + fprintf(stderr, TOY_CC_ERROR "ERROR: 'Toy_String' is an unexpected size in memory: expected 24, found %d \n" TOY_CC_RESET, (int)sizeof(Toy_String)); return -1; } } @@ -35,7 +35,7 @@ int test_string_allocation() { { //setup Toy_Bucket* bucket = NULL; - Toy_initBucket(&bucket, 32); + Toy_initBucket(&bucket, 1024); const char* cstring = "Hello world"; Toy_String* str = Toy_createString(&bucket, cstring); @@ -55,7 +55,7 @@ int test_string_allocation() { Toy_freeString(str); //inspect the bucket - if (bucket->capacity != 32 || + if (bucket->capacity != 1024 || bucket->count != sizeof(Toy_String) + 12 || bucket->next != NULL) { @@ -78,7 +78,7 @@ int test_string_allocation() { { //setup Toy_Bucket* bucket = NULL; - Toy_initBucket(&bucket, 32); + Toy_initBucket(&bucket, 1024); const char* cstring = "Hello world"; Toy_String* str = Toy_createString(&bucket, cstring); @@ -105,7 +105,7 @@ int test_string_allocation() { { //setup Toy_Bucket* bucket = NULL; - Toy_initBucket(&bucket, 32); + Toy_initBucket(&bucket, 1024); const char* cstring = ""; Toy_String* str = Toy_createString(&bucket, cstring);