decompiler  1.0.0
Classes | Macros | Typedefs
test.hh File Reference

Simple test framework. More...

#include <vector>
#include <set>
#include <string>
#include <sstream>
#include <iostream>

Classes

struct  ghidra::UnitTest
 Simple unit test class. More...
 

Macros

#define TEST(testname)
 Main unit test macro. More...
 
#define ASSERT(test)
 Assert that a boolean is true for a unit test. More...
 
#define ASSERT_EQUALS(a, b)
 Assert that two values are equal for a unit test. More...
 
#define ASSERT_NOT_EQUALS(a, b)
 Assert that two values are not equal for a unit test. More...
 

Typedefs

typedef void(* ghidra::testfunc_t) ()
 A unit-test function.
 

Detailed Description

Simple test framework.

Include this file and any additional headers. Use TEST(testname) as prototype in test function definitions. E.g. test.cc: #include "float.hh" #include "test.hh"

TEST(zero_is_less_than_one) { ASSERT(0.0 < 1.0); }

Macro Definition Documentation

◆ ASSERT

#define ASSERT (   test)
Value:
if (!(test)) { \
cerr << " failed at " << __FILE__ << ":" << __LINE__ << " asserting \"" << #test << "\"." << endl; \
throw 0; \
}

Assert that a boolean is true for a unit test.

◆ ASSERT_EQUALS

#define ASSERT_EQUALS (   a,
 
)
Value:
if ((a) != (b)) { \
ostringstream ssa, ssb; \
ssa << (a); \
ssb << (b); \
cerr << " failed at " << __FILE__ << ":" << __LINE__ << " asserting \"" << ssa.str() \
<< " == " << ssb.str() << "\"." << endl; \
throw 0; \
}

Assert that two values are equal for a unit test.

◆ ASSERT_NOT_EQUALS

#define ASSERT_NOT_EQUALS (   a,
 
)
Value:
if ((a) == (b)) { \
ostringstream ssa, ssb; \
ssa << (a); \
ssb << (b); \
cerr << " failed at " << __FILE__ << ":" << __LINE__ << " asserting \"" << ssa.str() \
<< " != " << ssb.str() << "\"." << endl; \
throw 0; \
}

Assert that two values are not equal for a unit test.

◆ TEST

#define TEST (   testname)
Value:
void testname(); \
UnitTest testname##_obj{ #testname, testname }; \
void testname()

Main unit test macro.