Fixed bad tests with 64 bit platforms

This commit is contained in:
2024-09-30 15:35:08 +10:00
parent 7b8ff8f873
commit a9759384cd
3 changed files with 13 additions and 11 deletions

View File

@@ -12,6 +12,8 @@ typedef struct Toy_String { //32 | 64 BITNESS
int length; //4 | 4 int length; //4 | 4
int refCount; //4 | 4 int refCount; //4 | 4
int _padding; //4 | 4
union { union {
struct { struct {
struct Toy_String* left; //4 | 8 struct Toy_String* left; //4 | 8
@@ -19,11 +21,11 @@ typedef struct Toy_String { //32 | 64 BITNESS
} node; //8 | 16 } node; //8 | 16
struct { struct {
int dummy; //4 | 4 int _dummy; //4 | 4
char data[]; //- | - char data[]; //- | -
} leaf; //4 | 4 } leaf; //4 | 4
} as; //8 | 16 } 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_createString(Toy_Bucket** bucket, const char* cstring);
TOY_API Toy_String* Toy_createStringLength(Toy_Bucket** bucket, const char* cstring, int length); TOY_API Toy_String* Toy_createStringLength(Toy_Bucket** bucket, const char* cstring, int length);

View File

@@ -66,7 +66,7 @@ int test_buckets() {
//check //check
if (bucket == NULL || bucket->count != 4 * sizeof(int)) { 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; return -1;
} }

View File

@@ -9,8 +9,8 @@
int test_sizeof_string_64bit() { int test_sizeof_string_64bit() {
//test for the correct size //test for the correct size
{ {
if (sizeof(Toy_String) != 28) { if (sizeof(Toy_String) != 32) {
fprintf(stderr, TOY_CC_ERROR "ERROR: 'Toy_String' is an unexpected size in memory\n" TOY_CC_RESET); 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; return -1;
} }
} }
@@ -21,8 +21,8 @@ int test_sizeof_string_64bit() {
int test_sizeof_string_32bit() { int test_sizeof_string_32bit() {
//test for the correct size //test for the correct size
{ {
if (sizeof(Toy_String) != 20) { if (sizeof(Toy_String) != 24) {
fprintf(stderr, TOY_CC_ERROR "ERROR: 'Toy_String' is an unexpected size in memory\n" TOY_CC_RESET); 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; return -1;
} }
} }
@@ -35,7 +35,7 @@ int test_string_allocation() {
{ {
//setup //setup
Toy_Bucket* bucket = NULL; Toy_Bucket* bucket = NULL;
Toy_initBucket(&bucket, 32); Toy_initBucket(&bucket, 1024);
const char* cstring = "Hello world"; const char* cstring = "Hello world";
Toy_String* str = Toy_createString(&bucket, cstring); Toy_String* str = Toy_createString(&bucket, cstring);
@@ -55,7 +55,7 @@ int test_string_allocation() {
Toy_freeString(str); Toy_freeString(str);
//inspect the bucket //inspect the bucket
if (bucket->capacity != 32 || if (bucket->capacity != 1024 ||
bucket->count != sizeof(Toy_String) + 12 || bucket->count != sizeof(Toy_String) + 12 ||
bucket->next != NULL) bucket->next != NULL)
{ {
@@ -78,7 +78,7 @@ int test_string_allocation() {
{ {
//setup //setup
Toy_Bucket* bucket = NULL; Toy_Bucket* bucket = NULL;
Toy_initBucket(&bucket, 32); Toy_initBucket(&bucket, 1024);
const char* cstring = "Hello world"; const char* cstring = "Hello world";
Toy_String* str = Toy_createString(&bucket, cstring); Toy_String* str = Toy_createString(&bucket, cstring);
@@ -105,7 +105,7 @@ int test_string_allocation() {
{ {
//setup //setup
Toy_Bucket* bucket = NULL; Toy_Bucket* bucket = NULL;
Toy_initBucket(&bucket, 32); Toy_initBucket(&bucket, 1024);
const char* cstring = ""; const char* cstring = "";
Toy_String* str = Toy_createString(&bucket, cstring); Toy_String* str = Toy_createString(&bucket, cstring);