Skip to content

Commit 98fd802

Browse files
committed
增加更多的测试;修改文档以提供示例参考;修改遗漏未修改的换行符
1 parent 195eecc commit 98fd802

File tree

5 files changed

+42
-8
lines changed

5 files changed

+42
-8
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ target_sources(${PROJECT_NAME}
1515
${RMDEV_TEST_FRAMEWORK_PUBLIC_SOURCES}
1616
)
1717

18+
# 将宏 RMDEV_TEST_FRAMEWORK_ENABLE_TEST 设置为 ON 即启用测试
1819
if (RMDEV_TEST_FRAMEWORK_ENABLE_TEST)
1920
add_subdirectory(test)
2021
endif ()

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ CMake 3.5 或更高版本。
2727
### 使用步骤
2828

2929
1.`rmdev_test_framework.h` 头文件包含到主函数所在的文件中。
30-
2. 在测试代码的主函数中调用 `rmdev_test_framework_main()` 函数。相关参数可参考阅读函数的注释。
30+
2. 在测试代码的主函数中调用 `rmdev_test_framework_main()` 函数。相关参数可参考阅读函数的注释,或者参考本项目的测试代码示例

src/rmdev_test_framework.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,10 @@ void rmdev_test_assert(const char* file, const int line, const rmdev_test_bool_t
154154
static void rmdev_test_finish(void)
155155
{
156156
if (success_count + fail_count == test_item_total_count) {
157-
printfCallback_("\r\nTest Finished.\r\n\r\n %d Test(s) Succeeded, %d Test(s) Failed.\r\n",
157+
printfCallback_("%sTest Finished.%s%s %d Test(s) Succeeded, %d Test(s) Failed.\r\n",
158+
break_character,
159+
break_character,
160+
break_character,
158161
success_count,
159162
fail_count);
160163
}

test/main.c

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
* @brief 测试框架的测试主函数
66
*/
77

8-
#include "rmdev_test_framework.h"
9-
108
#include <stdbool.h>
9+
#include <stdio.h>
1110

11+
#include "rmdev_test_framework.h"
1212
#include "test_function_impl.h"
1313

14-
void testUsage(void)
14+
void testApiUsage(void)
1515
{
1616
RMDEV_TEST_ITEM("Constant Test");
1717
RMDEV_TEST_CHECK(true);
@@ -44,6 +44,8 @@ void testUsage(void)
4444
RMDEV_TEST_CHECK((114514 + 1919810) == 2034324);
4545
RMDEV_TEST_ASSERT(-1 - 2 == -3);
4646

47+
RMDEV_TEST_ITEM("None Test");
48+
4749
RMDEV_TEST_ITEM("Assert Test");
4850
RMDEV_TEST_ASSERT(true);
4951
RMDEV_TEST_ASSERT(false);
@@ -53,8 +55,36 @@ void testUsage(void)
5355

5456
int main(void)
5557
{
56-
// todo 待增加其他的测试(比如传入空指针)
57-
rmdev_test_framework_main("\n", my_printf, my_delay, testUsage);
58+
printf("1 -- Api Usage Test\n");
59+
printf("2 -- NULL Break Character Test\n");
60+
printf("3 -- NULL Printf Callback Test\n");
61+
printf("4 -- NULL Delay Callback Test\n");
62+
printf("5 -- NULL Test Item Callback Test\n");
63+
printf("Choose which to test: ");
64+
65+
int choice;
66+
scanf("%d", &choice);
67+
68+
switch (choice) {
69+
case 1:
70+
rmdev_test_framework_main("\n", my_printf, my_delay, testApiUsage);
71+
break;
72+
case 2:
73+
rmdev_test_framework_main(NULL, my_printf, my_delay, testApiUsage);
74+
break;
75+
case 3:
76+
rmdev_test_framework_main("\n", NULL, my_delay, testApiUsage);
77+
break;
78+
case 4:
79+
rmdev_test_framework_main("\n", my_printf, NULL, testApiUsage);
80+
break;
81+
case 5:
82+
rmdev_test_framework_main("\n", my_printf, my_delay, NULL);
83+
break;
84+
default:
85+
printf("Invalid choice!\n");
86+
return 1;
87+
}
5888

5989
return 0;
6090
}

test/test_function_impl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include <stdio.h>
99
#include <stdarg.h>
10-
#include <unistd.h> // For sleep function
10+
#include <unistd.h> // For sleep function
1111

1212
void my_delay(const unsigned int ms)
1313
{

0 commit comments

Comments
 (0)