tests/core: Update string test to the new framework

I converted the test to the new framework, and I introduced a new
"test.h" file in the source directory to help with mixing C and C++
code.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-08-21 12:26:15 -04:00
parent 55a7673983
commit 2276a44a07
3 changed files with 34 additions and 10 deletions

View File

@ -11,10 +11,10 @@ def CoreTest(name, source):
return run return run
res = [ CoreTest("version", "version.c") ] res = [ CoreTest("version", "version.c") ]
res += [ CoreTest("string", "string.cpp") ]
Return("res") Return("res")
#test( "string", )
#test( "file" ) #test( "file" )
#test( "database" ) #test( "database" )
#test( "index" ) #test( "index" )

View File

@ -3,7 +3,7 @@
* Test the string formatting functions. * Test the string formatting functions.
*/ */
#include <core/string.h> #include <core/string.h>
#include <tests/test.h> #include "test.h"
void test_utos() void test_utos()
{ {
@ -70,10 +70,9 @@ void test_lowercase()
} }
int main(int argc, char **argv) DECLARE_UNIT_TESTS(
{ UNIT_TEST("Unsigned to String", test_utos),
test :: run("Unsigned to String Test", test_utos); UNIT_TEST("Seconds to String", test_sec2str),
test :: run("Seconds to String Test", test_sec2str); UNIT_TEST("Seconds to String (Detailed)", test_sec2str_detailed),
test :: run("Seconds to String (Detailed) Test", test_sec2str_detailed); UNIT_TEST("String Lowercase", test_lowercase),
test :: run("String Lowercase Test", test_lowercase); );
}

25
tests/core/test.h Normal file
View File

@ -0,0 +1,25 @@
/*
* Copyright 2015 (c) Anna Schumaker.
*/
#ifndef TESTS_CORE_TESTS_H
#define TESTS_CORE_TESTS_H
extern "C" {
#include <tests/test.h>
}
#include <sstream>
#undef tostring
template <class T>
static inline char *tostring(T s)
{
std::stringstream ss;
ss << s;
return strdup(ss.str().c_str());
}
#endif /* TESTS_CORE_TESTS_H */