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 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);

View File

@@ -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;
}

View File

@@ -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);