1111#include <rtthread.h>
1212#include <string.h>
1313#include <stdlib.h>
14-
1514#include "utest.h"
16- #include <utest_log.h>
17-
18- #undef DBG_TAG
19- #undef DBG_LVL
15+ #include "utest_log.h"
2016
2117#define DBG_TAG "utest"
2218#ifdef UTEST_DEBUG
@@ -217,7 +213,7 @@ static void utest_do_run(const char *utest_name)
217213 {
218214 if (utest_name )
219215 {
220- int len = strlen (utest_name );
216+ int len = rt_strlen (utest_name );
221217 if (utest_name [len - 1 ] == '*' )
222218 {
223219 len -= 1 ;
@@ -397,13 +393,27 @@ void utest_unit_run(test_unit_func func, const char *unit_func_name)
397393 }
398394}
399395
400- void utest_assert (int value , const char * file , int line , const char * func , const char * msg )
396+ /*
397+ * utest_assert - assert function
398+ *
399+ * @param value - assert value
400+ * @param file - file name
401+ * @param line - line number
402+ * @param func - function name
403+ * @param msg - assert message
404+ *
405+ * @return - RT_TRUE: assert success; RT_FALSE: assert failed
406+ */
407+ rt_bool_t utest_assert (int value , const char * file , int line , const char * func , const char * msg )
401408{
409+ rt_bool_t rst = RT_FALSE ;
410+
402411 if (!(value ))
403412 {
404413 local_utest .error = UTEST_FAILED ;
405414 local_utest .failed_num ++ ;
406415 LOG_E ("[ ASSERT ] [ unit ] at (%s); func: (%s:%d); msg: (%s)" , file_basename (file ), func , line , msg );
416+ rst = RT_FALSE ;
407417 }
408418 else
409419 {
@@ -413,37 +423,49 @@ void utest_assert(int value, const char *file, int line, const char *func, const
413423 }
414424 local_utest .error = UTEST_PASSED ;
415425 local_utest .passed_num ++ ;
426+ rst = RT_TRUE ;
416427 }
428+
429+ return rst ;
417430}
418431
419432void utest_assert_string (const char * a , const char * b , rt_bool_t equal , const char * file , int line , const char * func , const char * msg )
420433{
434+ rt_bool_t rst = RT_FALSE ;
435+
421436 if (a == RT_NULL || b == RT_NULL )
422437 {
423- utest_assert (0 , file , line , func , msg );
438+ rst = utest_assert (0 , file , line , func , msg );
424439 }
425-
426- if (equal )
440+ else
427441 {
428- if (rt_strcmp ( a , b ) == 0 )
442+ if (equal )
429443 {
430- utest_assert (1 , file , line , func , msg );
444+ if (rt_strcmp (a , b ) == 0 )
445+ {
446+ rst = utest_assert (1 , file , line , func , msg );
447+ }
448+ else
449+ {
450+ rst = utest_assert (0 , file , line , func , msg );
451+ }
431452 }
432453 else
433454 {
434- utest_assert (0 , file , line , func , msg );
455+ if (rt_strcmp (a , b ) == 0 )
456+ {
457+ rst = utest_assert (0 , file , line , func , msg );
458+ }
459+ else
460+ {
461+ rst = utest_assert (1 , file , line , func , msg );
462+ }
435463 }
436464 }
437- else
465+
466+ if (!rst )
438467 {
439- if (rt_strcmp (a , b ) == 0 )
440- {
441- utest_assert (0 , file , line , func , msg );
442- }
443- else
444- {
445- utest_assert (1 , file , line , func , msg );
446- }
468+ LOG_E ("[ ASSERT ] [ unit ] str-a: (%s); str-b: (%s)" , a , b );
447469 }
448470}
449471
0 commit comments