Skip to content

Commit de8f371

Browse files
committed
更新文档;修改字符串比较的方式,避免了不必要的字符串拷贝;减小了默认数值缓冲区的大小
1 parent 778c331 commit de8f371

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ static void testEntry(void)
9090
int main(void)
9191
{
9292
const emdevif_test_Callbacks callback = {.printfCallback = myPrintf,
93-
.testEntryCallback = testEntry,
94-
.testFinishCallback = testFinishHandler};
93+
.testEntryCallback = testEntry,
94+
.testFinishCallback = testFinishHandler};
9595

9696
emdevif_test_framework_main("\n", &callback, NULL);
9797

@@ -128,3 +128,28 @@ static void testEntry(void)
128128
```
129129
130130
* 支持测试夹具。使用方式参考[集成测试](./test/integration_test/classic_test/external_test.c)中的 FixtureTest。
131+
132+
## 自定义配置
133+
134+
### 预定义宏
135+
136+
您可以通过预定义宏以配置 emdevif 的一些属性。
137+
138+
| 预定义宏 | 预定义宏的值的类型 | 预定义宏的含义 |
139+
|---------------------------------|-----------|-----------------------------------------------------|
140+
| EMDEVIF_TEST_VALUE_BUFFER_SIZE | size_t | 存储 ASSERT 与 EXPECT 宏的数值的字符串长度,默认为 64。 |
141+
| EMDEVIF_TEST_FLOAT_EQUAL_ERROR | double | 浮点数等于判定的误差值,即两个浮点类型数据之差的绝对值小于这个值即认为它们相等,默认为 0.0001。 |
142+
143+
使用 CMake 预定义宏的示例:
144+
```CMake
145+
add_subdirectory(
146+
# path to emdevif_test_framework
147+
)
148+
target_compile_definitions(emdevif_test_framework INTERFACE EMDEVIF_TEST_VALUE_BUFFER_SIZE=128) # example about how to set macro EMDEVIF_TEST_VALUE_BUFFER_SIZE to 128
149+
150+
target_link_libraries(
151+
# your project name
152+
# PUBLIC / PRIVATE / INTERFACE
153+
emdevif_test_framework
154+
)
155+
```

src/emdevif_test_framework.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static int test_suit_success_count = 0; ///< 成功计数
2727
static int test_suit_fail_count = 0; ///< 失败计数
2828

2929
#ifndef EMDEVIF_TEST_VALUE_BUFFER_SIZE
30-
#define EMDEVIF_TEST_VALUE_BUFFER_SIZE 128
30+
#define EMDEVIF_TEST_VALUE_BUFFER_SIZE 64
3131
#endif
3232

3333
static char lhs_buffer[EMDEVIF_TEST_VALUE_BUFFER_SIZE], rhs_buffer[EMDEVIF_TEST_VALUE_BUFFER_SIZE];
@@ -144,10 +144,8 @@ const emdevif_test_CompareMsg* emdevif_test_strEqual(emdevif_test_CompareMsg* co
144144
const char* const lhs,
145145
const char* const rhs)
146146
{
147-
sprintf(lhs_buffer, "%s", lhs);
148-
sprintf(rhs_buffer, "%s", rhs);
149-
msg->lhs_value = lhs_buffer;
150-
msg->rhs_value = rhs_buffer;
147+
msg->lhs_value = lhs;
148+
msg->rhs_value = rhs;
151149

152150
setCompareName(msg, EMDEVIF_TEST_COMPARE_EQUAL);
153151

0 commit comments

Comments
 (0)