parent
672502449b
commit
701601f5cd
@ -0,0 +1,22 @@
|
||||
#ifndef _TESTH_H
|
||||
#define _TESTS_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include "macros.h"
|
||||
|
||||
/// Run a test before `main()`
|
||||
#define RUNTEST(name) __attribute__((constructor)) void _runtest__ ## name () { \
|
||||
fprintf(stderr, "[!] <--- running test " #name " --- \n"); \
|
||||
CALLTEST(name); \
|
||||
fprintf(stderr, "[!] --- " #name " ok --->\n"); \
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
#define RUNTEST_DEBUG(name) RUNTEST(name)
|
||||
#else
|
||||
#define RUNTEST_DEBUG(name)
|
||||
#endif
|
||||
|
||||
DEFTEST(version_str);
|
||||
|
||||
#endif /* _TESTS_H */
|
@ -0,0 +1,36 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <ints.h>
|
||||
#include <macros.h>
|
||||
#include <version.h>
|
||||
|
||||
#include <tests.h>
|
||||
|
||||
DEFTEST(version_str)
|
||||
{
|
||||
const u32 vraw = VERSION(100,200,101,255);
|
||||
version_t vers = v_rawtoc(vraw);
|
||||
|
||||
usize sz = v_ctosn_sz(vers);
|
||||
TEST_ASSERT(sz > 0);
|
||||
char verstr[sz+1];
|
||||
TEST_ASSERT_EQ(v_ctosn(vers, sz+1, verstr), sz);
|
||||
|
||||
|
||||
|
||||
char* verstr_h;
|
||||
INFO("Version: 0x%x, raw: 0x%x", vers.raw, vraw);
|
||||
INFO("Output is: (%lu chars)\t%s", sz, verstr);
|
||||
INFO("Output is (static):\t%s", v_ctoss(vers));
|
||||
INFO("Output is (leak):\t\t%s", (verstr_h = v_ctos(vers)));
|
||||
|
||||
TEST_ASSERT(verstr_h);
|
||||
|
||||
free(verstr_h);
|
||||
|
||||
return TEST_OK;
|
||||
}
|
||||
RUNTEST_DEBUG(version_str)
|
Loading…
Reference in new issue