Skip to content

Commit 98b1087

Browse files
committed
[components/utilities/utest] 修复 gcc 编译警告
[components/utilities/utest] 移除组件的版本号 [components/utilities/utest] 优化 basename 函数的处理 Signed-off-by: MurphyZhao <[email protected]>
1 parent 51b17a1 commit 98b1087

File tree

3 files changed

+12
-32
lines changed

3 files changed

+12
-32
lines changed

components/utilities/utest/utest.c

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -74,42 +74,24 @@ static void utest_tc_list(void)
7474
LOG_I("[testcase name]:%s; [run timeout]:%d", tc_table[i].name, tc_table[i].run_timeout);
7575
}
7676
}
77-
MSH_CMD_EXPORT_ALIAS(utest_tc_list, utest_tc_list, output all utest testcase);
77+
MSH_CMD_EXPORT_ALIAS(utest_tc_list, utest_list, output all utest testcase);
7878

79-
static char *file_basename(const char *file)
79+
static const char *file_basename(const char *file)
8080
{
81-
char *ptr = RT_NULL;
81+
char *end_ptr = RT_NULL;
8282
char *rst = RT_NULL;
83-
char *file_bak = rt_strdup(file);
84-
uint8_t len = 0;
85-
if ((ptr = strrchr(file_bak, '\\')) != RT_NULL || (ptr = strrchr(file_bak, '/')) != RT_NULL)
83+
84+
if (!((end_ptr = strrchr(file, '\\')) != RT_NULL || \
85+
(end_ptr = strrchr(file, '/')) != RT_NULL) || \
86+
(rt_strlen(file) < 2))
8687
{
87-
rst = ptr;
88+
rst = (char *)file;
8889
}
8990
else
9091
{
91-
rst = file_bak;
92+
rst = (char *)(end_ptr + 1);
9293
}
93-
94-
len = rst - file_bak;
95-
if (rst != file)
96-
{
97-
file_bak[len] = '\0';
98-
99-
if ((ptr = strrchr(file_bak, '\\')) != RT_NULL || (ptr = strrchr(file_bak, '/')) != RT_NULL)
100-
{
101-
rst = ptr;
102-
}
103-
else
104-
{
105-
rst = file_bak;
106-
}
107-
len = rst - file_bak;
108-
}
109-
110-
rt_free(file_bak);
111-
len = len != 0? len + 1 : len;
112-
return (char *)(file + len);
94+
return (const char *)rst;
11395
}
11496

11597
static void utest_run(const char *utest_name)

components/utilities/utest/utest.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
#include <rtthread.h>
1515
#include "utest_log.h"
1616

17-
#define UTEST_SW_VERSION "0.0.1"
18-
1917
/**
2018
* utest_error
2119
*

components/utilities/utest/utest_assert.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ void utest_assert_string(const char *a, const char *b, rt_bool_t equal, const ch
4343
*/
4444
#define uassert_true(value) __utest_assert(value, "(" #value ") is false")
4545
#define uassert_false(value) __utest_assert(!(value), "(" #value ") is true")
46-
#define uassert_null(value) __utest_assert((value) == NULL, "(" #value ") is not null")
47-
#define uassert_not_null(value) __utest_assert((value) != NULL, "(" #value ") is null")
46+
#define uassert_null(value) __utest_assert((const char *)(value) == NULL, "(" #value ") is not null")
47+
#define uassert_not_null(value) __utest_assert((const char *)(value) != NULL, "(" #value ") is null")
4848

4949
#define uassert_int_equal(a, b) __utest_assert((a) == (b), "(" #a ") not equal to (" #b ")")
5050
#define uassert_int_not_equal(a, b) __utest_assert((a) != (b), "(" #a ") equal to (" #b ")")

0 commit comments

Comments
 (0)