Fixed up the tests.

Added tests for the Debug log routines.
master
Michael Hope 10 years ago
parent b0368f7af0
commit 117306c873
  1. 2
      Makefile.am
  2. 3
      lib/debug.cc
  3. 55
      tests/test_debug.h

@ -15,7 +15,7 @@ roverif_elf_LDADD = libnppilot.a
check_PROGRAMS = \
tests/runner
tests_runner_LDADD = libnppilot.a
tests_runner_LDADD = libnppilot.a -lstdc++
lib_LIBRARIES = \
libnppilot.a \

@ -54,6 +54,9 @@ void Debug::vprint(const char* pmsg, va_list args)
case 'x':
printn(va_arg(args, int), 16, false);
break;
case 's':
print(va_arg(args, char *));
break;
default:
assert(false);
break;

@ -0,0 +1,55 @@
#include <debug.h>
#include <cxxtest/TestSuite.h>
class TestDebug : public CxxTest::TestSuite
{
public:
void setUp()
{
_at = 0;
}
void test_basic()
{
Debug::info("rock on!");
TS_ASSERT_EQUALS(0, strcmp("info: rock on!\r\n", _msg));
}
void test_signed()
{
Debug::info("decimal %d.", -1234);
TS_ASSERT_EQUALS(0, strcmp("info: decimal -1234.\r\n", _msg));
}
void test_unsigned()
{
Debug::info("unsigned %u.", -1234);
TS_ASSERT_EQUALS(0, strcmp("info: unsigned 4294966062.\r\n", _msg));
}
void test_hex()
{
Debug::info("hex %x.", 0xabcd5678);
TS_ASSERT_EQUALS(0, strcmp("info: hex abcd5678.\r\n", _msg));
}
void test_string()
{
Debug::info("str %s.", "rock on!");
TS_ASSERT_EQUALS(0, strcmp("info: str rock on!.\r\n", _msg));
}
static int _at;
static char _msg[128];
};
void Debug::putch(char ch)
{
TestDebug::_msg[TestDebug::_at++] = ch;
TestDebug::_msg[TestDebug::_at] = '\0';
}
#ifdef CXXTEST_RUNNING
int TestDebug::_at;
char TestDebug::_msg[128];
#endif
Loading…
Cancel
Save