소스 검색

Fixed up the tests.

Michael Hope 4 년 전
부모
커밋
117306c873
3개의 변경된 파일59개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      Makefile.am
  2. 3 0
      lib/debug.cc
  3. 55 0
      tests/test_debug.h

+ 1 - 1
Makefile.am 파일 보기

@@ -15,7 +15,7 @@ roverif_elf_LDADD = libnppilot.a
15 15
 check_PROGRAMS = \
16 16
 	tests/runner
17 17
 
18
-tests_runner_LDADD = libnppilot.a
18
+tests_runner_LDADD = libnppilot.a -lstdc++
19 19
 
20 20
 lib_LIBRARIES = \
21 21
 	libnppilot.a \

+ 3 - 0
lib/debug.cc 파일 보기

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

+ 55 - 0
tests/test_debug.h 파일 보기

@@ -0,0 +1,55 @@
1
+#include <debug.h>
2
+#include <cxxtest/TestSuite.h>
3
+
4
+class TestDebug : public CxxTest::TestSuite
5
+{
6
+public:
7
+    void setUp()
8
+    {
9
+        _at = 0;
10
+    }
11
+
12
+    void test_basic()
13
+    {
14
+        Debug::info("rock on!");
15
+        TS_ASSERT_EQUALS(0, strcmp("info: rock on!\r\n", _msg));
16
+    }
17
+
18
+    void test_signed()
19
+    {
20
+        Debug::info("decimal %d.", -1234);
21
+        TS_ASSERT_EQUALS(0, strcmp("info: decimal -1234.\r\n", _msg));
22
+    }
23
+
24
+    void test_unsigned()
25
+    {
26
+        Debug::info("unsigned %u.", -1234);
27
+        TS_ASSERT_EQUALS(0, strcmp("info: unsigned 4294966062.\r\n", _msg));
28
+    }
29
+
30
+    void test_hex()
31
+    {
32
+        Debug::info("hex %x.", 0xabcd5678);
33
+        TS_ASSERT_EQUALS(0, strcmp("info: hex abcd5678.\r\n", _msg));
34
+    }
35
+
36
+    void test_string()
37
+    {
38
+        Debug::info("str %s.", "rock on!");
39
+        TS_ASSERT_EQUALS(0, strcmp("info: str rock on!.\r\n", _msg));
40
+    }
41
+
42
+    static int _at;
43
+    static char _msg[128];
44
+};
45
+
46
+void Debug::putch(char ch)
47
+{
48
+    TestDebug::_msg[TestDebug::_at++] = ch;
49
+    TestDebug::_msg[TestDebug::_at] = '\0';
50
+}
51
+
52
+#ifdef CXXTEST_RUNNING
53
+int TestDebug::_at;
54
+char TestDebug::_msg[128];
55
+#endif