@@ -0,0 +1,8 @@
|
||||
tests = [
|
||||
'seed_high_bits',
|
||||
]
|
||||
|
||||
foreach t : tests
|
||||
exec = executable(t, t+'.c', include_directories: headers_include, c_args: evh_c_args)
|
||||
test(t, exec, suite: 'hash')
|
||||
endforeach
|
||||
@@ -0,0 +1,22 @@
|
||||
#define EV_HASH_IMPLEMENTATION
|
||||
#include "ev_macros.h"
|
||||
#include "ev_hash.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const char *data = "same input";
|
||||
|
||||
u64 low_seed = 1;
|
||||
u64 high_seed = (1ull << 32) | 1ull;
|
||||
|
||||
u64 low_hash = ev_hash_murmur3(data, (u32)strlen(data), low_seed);
|
||||
u64 high_hash = ev_hash_murmur3(data, (u32)strlen(data), high_seed);
|
||||
|
||||
assert(low_seed != high_seed);
|
||||
assert(low_hash != high_hash);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#define EV_STR_IMPLEMENTATION
|
||||
#include "ev_str.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
evstring text = evstr("abc");
|
||||
evstring query = evstr("");
|
||||
|
||||
evstring_view match = evstring_findFirst(text, query);
|
||||
|
||||
assert(match.len == 0);
|
||||
assert(match.offset == ~0ull);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -10,6 +10,7 @@ tests = [
|
||||
'find_first_overlapping_prefix',
|
||||
'stack_get_space',
|
||||
'overlapping_push',
|
||||
'find_first_empty_query',
|
||||
]
|
||||
|
||||
foreach t : tests
|
||||
|
||||
@@ -3,6 +3,7 @@ tests = [
|
||||
'reducecap_updatelen',
|
||||
'reducecap_free_elems',
|
||||
'reducelen_free_elems',
|
||||
'pop_out_frees_vector_owned_elem',
|
||||
]
|
||||
|
||||
foreach t : tests
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#define EV_VEC_IMPLEMENTATION
|
||||
#include "ev_vec.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static int free_calls = 0;
|
||||
|
||||
typedef struct OwningInt {
|
||||
int *ptr;
|
||||
} OwningInt;
|
||||
|
||||
DEFINE_COPY_FUNCTION(OwningInt, Default)
|
||||
{
|
||||
dst->ptr = malloc(sizeof(*dst->ptr));
|
||||
assert(dst->ptr != NULL);
|
||||
*dst->ptr = *src->ptr;
|
||||
}
|
||||
|
||||
DEFINE_FREE_FUNCTION(OwningInt, Default)
|
||||
{
|
||||
assert(self->ptr != NULL);
|
||||
free(self->ptr);
|
||||
self->ptr = NULL;
|
||||
free_calls++;
|
||||
}
|
||||
|
||||
TYPEDATA_GEN(OwningInt, COPY(Default), FREE(Default));
|
||||
|
||||
int main(void)
|
||||
{
|
||||
ev_vec(OwningInt) v = ev_vec_init(OwningInt);
|
||||
assert(v != NULL);
|
||||
|
||||
OwningInt original = { .ptr = malloc(sizeof(*original.ptr)) };
|
||||
assert(original.ptr != NULL);
|
||||
*original.ptr = 42;
|
||||
|
||||
assert(ev_vec_push_impl(&v, &original) == 0);
|
||||
free(original.ptr);
|
||||
|
||||
OwningInt out = {0};
|
||||
assert(ev_vec_pop(&v, &out) == EV_VEC_ERR_NONE);
|
||||
assert(out.ptr != NULL);
|
||||
assert(*out.ptr == 42);
|
||||
|
||||
FREE_FUNCTION(OwningInt, Default)(&out);
|
||||
|
||||
/* Popping with an output copy transfers no pointer from the vector element.
|
||||
The vector's own deep-copied element must still be destroyed. */
|
||||
assert(free_calls == 2);
|
||||
|
||||
ev_vec_fini(&v);
|
||||
return 0;
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
subdir('ev_hash')
|
||||
subdir('ev_log')
|
||||
subdir('ev_str')
|
||||
subdir('ev_types')
|
||||
|
||||
Reference in New Issue
Block a user