Found a leak, moving to linux

This commit is contained in:
2022-08-28 23:47:58 +01:00
parent f705d82aee
commit 4fb2dea1b4
5 changed files with 95 additions and 4 deletions

View File

@@ -10,7 +10,6 @@ int main() {
//test a single null literal
Literal literal = TO_NULL_LITERAL;
//
if (!IS_NULL(literal)) {
fprintf(stderr, ERROR "ERROR: null literal failed\n" RESET);
return -1;
@@ -22,7 +21,6 @@ int main() {
Literal t = TO_BOOLEAN_LITERAL(true);
Literal f = TO_BOOLEAN_LITERAL(false);
//
if (!IS_TRUTHY(t) || IS_TRUTHY(f)) {
fprintf(stderr, ERROR "ERROR: boolean literal failed\n" RESET);
return -1;
@@ -30,6 +28,7 @@ int main() {
}
{
//test string literals
char* buffer = ALLOCATE(char, 128);
snprintf(buffer, 128, "Hello world");
@@ -39,6 +38,17 @@ int main() {
freeLiteral(literal);
}
{
//test identifier literals
char* buffer = ALLOCATE(char, 128);
snprintf(buffer, 128, "foobar");
Literal literal = TO_IDENTIFIER_LITERAL(buffer, 128);
freeLiteral(literal);
}
//check allocated memory
if (getAllocatedMemoryCount() != 0) {
fprintf(stderr, ERROR "ERROR: Dangling memory detected: %d byes\n" RESET, getAllocatedMemoryCount());

78
test/test_literal_array.c Normal file
View File

@@ -0,0 +1,78 @@
#include "literal_array.h"
#include "memory.h"
#include "console_colors.h"
#include <stdio.h>
int main() {
{
//test init & cleanup
LiteralArray array;
initLiteralArray(&array);
freeLiteralArray(&array);
}
{
//test pushing and pulling
LiteralArray array;
initLiteralArray(&array);
for (int i = 0; i < 100; i++) {
pushLiteralArray(&array, TO_INTEGER_LITERAL(i));
}
for (int i = 0; i < 90; i++) {
Literal lit = popLiteralArray(&array);
freeLiteral(lit);
}
if (array.count != 10) {
fprintf(stderr, ERROR "ERROR: Array didn't clear the correct number of literal integers\n" RESET);
freeLiteralArray(&array);
return -1;
}
freeLiteralArray(&array);
}
{
//check string, identifier and compound type behaviours
LiteralArray array;
initLiteralArray(&array);
//raw
char* str_raw = "hello world";
char* idn_raw = "foobar";
Literal string = TO_STRING_LITERAL(copyString(str_raw, strlen(str_raw)), strlen(str_raw));
Literal identifier = TO_IDENTIFIER_LITERAL(copyString(idn_raw, strlen(idn_raw)), strlen(idn_raw));
//[string, string]
Literal type = TO_TYPE_LITERAL(LITERAL_DICTIONARY, false);
TYPE_PUSH_SUBTYPE(&type, TO_TYPE_LITERAL(LITERAL_STRING, false));
TYPE_PUSH_SUBTYPE(&type, TO_TYPE_LITERAL(LITERAL_STRING, false));
//push
pushLiteralArray(&array, string);
pushLiteralArray(&array, identifier);
pushLiteralArray(&array, type);
//free the local literals
freeLiteral(string);
freeLiteral(identifier);
freeLiteral(type);
freeLiteralArray(&array);
}
//check allocated memory
if (getAllocatedMemoryCount() != 0) {
fprintf(stderr, ERROR "ERROR: Dangling memory detected: %d byes\n" RESET, getAllocatedMemoryCount());
return -1;
}
printf(NOTICE "All good\n" RESET);
return 0;
}