simap/main.cpp

52 lines
1.5 KiB
C++
Raw Normal View History

2024-09-29 20:52:18 +02:00
#include <cstdio>
2024-10-07 10:32:52 +02:00
#include <cassert>
2024-09-29 20:52:18 +02:00
#include "amap.h"
#include "simap.h"
2024-10-07 10:32:52 +02:00
void test_basics(amap mapdo, void *map) {
assert(NULL == mapdo(map, AMAP_GET, "asdf", NULL));
2024-10-07 12:46:15 +02:00
int i = 42;
int *iptr;
2024-10-09 18:52:01 +02:00
const char *chptr;
2024-10-07 18:13:18 +02:00
assert(NULL != mapdo(map, AMAP_SET, "meaning", &i));
assert(NULL != (iptr = (int *)mapdo(map, AMAP_GET, "meaning", NULL)));
2024-10-07 12:46:15 +02:00
assert(*iptr == 42);
assert(iptr == &i);
2024-10-09 18:52:01 +02:00
/* Delete / tombstone */
assert(NULL != mapdo(map, AMAP_SET, "meaning", NULL));
/* Check re-adding */
assert(NULL != mapdo(map, AMAP_SET, "meaning", &i));
assert(NULL != (iptr = (int *)mapdo(map, AMAP_GET, "meaning", NULL)));
assert(*iptr == 42);
assert(iptr == &i);
/* Test Erase */
assert(NULL != mapdo(map, AMAP_ERASE, NULL, NULL));
/* Check re-adding 3 new things */
assert(NULL != mapdo(map, AMAP_SET, "meaningless1", &i));
2024-10-09 18:52:01 +02:00
assert(NULL != mapdo(map, AMAP_SET, "meaning2", &i));
const char *helloworld = "Hello world!";
assert(NULL != mapdo(map, AMAP_SET, "hello", (char *)helloworld)); /* TODO: ugly cast... */
assert(NULL != (chptr = (const char *)mapdo(map, AMAP_GET, "hello", NULL)));
assert(strlen(chptr) == strlen(helloworld));
assert(strcmp(chptr, helloworld) == 0);
assert(NULL != (iptr = (int *)mapdo(map, AMAP_GET, "meaning2", NULL)));
assert(*iptr == 42);
assert(iptr == &i);
assert(NULL != (iptr = (int *)mapdo(map, AMAP_GET, "meaningless1", NULL)));
2024-10-09 18:52:01 +02:00
assert(*iptr == 42);
assert(iptr == &i);
2024-10-07 10:32:52 +02:00
}
2024-09-29 20:52:18 +02:00
int main() {
2024-10-07 10:32:52 +02:00
/* test simap */
simap_instance si = simap_create();
test_basics(simap, &si);
2024-09-29 20:52:18 +02:00
return 0;
}