Wrapper for GC finished, untested

This commit is contained in:
Victor Olin 2023-03-29 15:13:24 +02:00
parent ee53759ca5
commit 16aa1be309
4 changed files with 142 additions and 15 deletions

View file

@ -8,6 +8,7 @@
void time_string(char *buffer);
void print_log_file(const std::string TESTS_PATH);
void readlink_test();
void null_test();
int main()
{
@ -17,7 +18,9 @@ int main()
// const std::string TESTS_PATH = "/home/virre/dev/systemF/org/language/src/GC/tests/";
// print_log_file(TESTS_PATH);
readlink_test();
// readlink_test();
null_test();
return 0;
}
@ -65,4 +68,10 @@ void readlink_test()
std::string log_path = folder + "/log_file_bla.txt";
std::cout << "\n" << log_path << std::endl;
}
void null_test() {
int *p = nullptr;
std::cout << "P: " << nullptr << std::endl;
}

90
src/GC/tests/wrapper.c Normal file
View file

@ -0,0 +1,90 @@
#include <stdbool.h>
#include <stdio.h>
#include "cheap.h"
typedef struct object
{
int x, y, z;
double velocity;
} Object;
void test_init()
{
printf("----- IN TEST_INIT ----------------------------\n");
cheap_init();
printf("----- EXIT TEST_INIT --------------------------\n");
}
cheap_t *test_the()
{
printf("----- IN TEST_THE -----------------------------\n");
cheap_t *fst_heap = cheap_the();
printf("Heap 1:\t%p\n", fst_heap->obj);
cheap_t *snd_heap = cheap_the();
printf("Heap 2:\t%p\n", snd_heap->obj);
printf("----- EXIT TEST_THE ---------------------------\n");
free(snd_heap);
return fst_heap;
}
void test_profiler(cheap_t *heap)
{
printf("----- IN TEST_PROFILER ------------------------\n");
cheap_set_profiler(heap, false);
cheap_set_profiler(heap, true);
printf("----- EXIT TEST_PROFILER ----------------------\n");
}
Object *test_alloc()
{
printf("----- IN TEST_ALLOC ---------------------------\n");
Object *o;
o = (Object *)(cheap_alloc(sizeof(Object)));
o->x = 3;
o->y = 4;
o->z = 5;
o->velocity = 1.0f;
printf("----- EXIT TEST_ALLOC -------------------------\n");
return o;
}
void test_dispose()
{
printf("----- IN TEST_DISPOSE -------------------------\n");
cheap_dispose();
printf("----- EXIT TEST_DISPOSE -----------------------\n");
}
int main(int argc, char **argv)
{
test_init();
cheap_t *heap = test_the();
test_profiler(heap);
Object *o = test_alloc();
printf("Object:\n\tx: %d\n\ty: %d\n\tz: %d\n\tvel: %f\n", o->x, o->y, o->z, o->velocity);
test_dispose();
free(heap);
free(o);
return 0;
}