Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Unity
提交
7053ef75
T
Third Party Unity
项目概览
OpenHarmony
/
Third Party Unity
大约 1 年 前同步成功
通知
34
Star
144
Fork
2
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Unity
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7053ef75
编写于
5月 04, 2016
作者:
M
Mark VanderVoord
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #192 from jsalling/feature/unity-coverage
100% code coverage for Unity project (Thanks jsalling!)
上级
0247e34b
c5238ada
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
120 addition
and
59 deletion
+120
-59
src/unity.c
src/unity.c
+15
-53
src/unity.h
src/unity.h
+2
-2
test/Makefile
test/Makefile
+2
-3
test/tests/testunity.c
test/tests/testunity.c
+101
-1
未找到文件。
src/unity.c
浏览文件 @
7053ef75
...
...
@@ -164,12 +164,9 @@ void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T s
}
//-----------------------------------------------
/// basically do an itoa using as little ram as possible
void
UnityPrintNumber
(
const
_U_SINT
number_to_print
)
{
_U_UINT
divisor
=
1
;
_U_UINT
next_divisor
;
_U_UINT
number
;
_U_UINT
number
=
(
_U_UINT
)
number_to_print
;
if
(
number_to_print
<
0
)
{
...
...
@@ -177,29 +174,7 @@ void UnityPrintNumber(const _U_SINT number_to_print)
UNITY_OUTPUT_CHAR
(
'-'
);
number
=
(
_U_UINT
)(
-
number_to_print
);
}
else
{
//Non-negative number
number
=
(
_U_UINT
)
number_to_print
;
}
// figure out initial divisor
while
(
number
/
divisor
>
9
)
{
next_divisor
=
divisor
*
10
;
if
(
next_divisor
>
divisor
)
divisor
=
next_divisor
;
else
break
;
}
// now mod and print, then divide divisor
do
{
UNITY_OUTPUT_CHAR
((
char
)(
'0'
+
(
number
/
divisor
%
10
)));
divisor
/=
10
;
}
while
(
divisor
>
0
);
UnityPrintNumberUnsigned
(
number
);
}
//-----------------------------------------------
...
...
@@ -207,16 +182,11 @@ void UnityPrintNumber(const _U_SINT number_to_print)
void
UnityPrintNumberUnsigned
(
const
_U_UINT
number
)
{
_U_UINT
divisor
=
1
;
_U_UINT
next_divisor
;
// figure out initial divisor
while
(
number
/
divisor
>
9
)
{
next_divisor
=
divisor
*
10
;
if
(
next_divisor
>
divisor
)
divisor
=
next_divisor
;
else
break
;
divisor
*=
10
;
}
// now mod and print, then divide divisor
...
...
@@ -521,6 +491,13 @@ void UnityAssertEqualNumber(const _U_SINT expected,
}
}
#define UnityPrintPointlessAndBail() \
{ \
UnityTestResultsFailBegin(lineNumber); \
UnityPrint(UnityStrPointless); \
UnityAddMsgIfSpecified(msg); \
UNITY_FAIL_AND_BAIL; }
//-----------------------------------------------
void
UnityAssertEqualIntArray
(
UNITY_INTERNAL_PTR
expected
,
UNITY_INTERNAL_PTR
actual
,
...
...
@@ -537,10 +514,7 @@ void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected,
if
(
elements
==
0
)
{
UnityTestResultsFailBegin
(
lineNumber
);
UnityPrint
(
UnityStrPointless
);
UnityAddMsgIfSpecified
(
msg
);
UNITY_FAIL_AND_BAIL
;
UnityPrintPointlessAndBail
();
}
if
(
UnityCheckArraysForNull
((
UNITY_INTERNAL_PTR
)
expected
,
(
UNITY_INTERNAL_PTR
)
actual
,
lineNumber
,
msg
)
==
1
)
...
...
@@ -655,10 +629,7 @@ void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const _UF* expected,
if
(
elements
==
0
)
{
UnityTestResultsFailBegin
(
lineNumber
);
UnityPrint
(
UnityStrPointless
);
UnityAddMsgIfSpecified
(
msg
);
UNITY_FAIL_AND_BAIL
;
UnityPrintPointlessAndBail
();
}
if
(
UnityCheckArraysForNull
((
UNITY_INTERNAL_PTR
)
expected
,
(
UNITY_INTERNAL_PTR
)
actual
,
lineNumber
,
msg
)
==
1
)
...
...
@@ -819,10 +790,7 @@ void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const _UD* expected,
if
(
elements
==
0
)
{
UnityTestResultsFailBegin
(
lineNumber
);
UnityPrint
(
UnityStrPointless
);
UnityAddMsgIfSpecified
(
msg
);
UNITY_FAIL_AND_BAIL
;
UnityPrintPointlessAndBail
();
}
if
(
UnityCheckArraysForNull
((
UNITY_INTERNAL_PTR
)
expected
,
(
UNITY_INTERNAL_PTR
)
actual
,
lineNumber
,
msg
)
==
1
)
...
...
@@ -1101,10 +1069,7 @@ void UnityAssertEqualStringArray( const char** expected,
// if no elements, it's an error
if
(
num_elements
==
0
)
{
UnityTestResultsFailBegin
(
lineNumber
);
UnityPrint
(
UnityStrPointless
);
UnityAddMsgIfSpecified
(
msg
);
UNITY_FAIL_AND_BAIL
;
UnityPrintPointlessAndBail
();
}
if
(
UnityCheckArraysForNull
((
UNITY_INTERNAL_PTR
)
expected
,
(
UNITY_INTERNAL_PTR
)
actual
,
lineNumber
,
msg
)
==
1
)
...
...
@@ -1164,10 +1129,7 @@ void UnityAssertEqualMemory( UNITY_INTERNAL_PTR expected,
if
((
elements
==
0
)
||
(
length
==
0
))
{
UnityTestResultsFailBegin
(
lineNumber
);
UnityPrint
(
UnityStrPointless
);
UnityAddMsgIfSpecified
(
msg
);
UNITY_FAIL_AND_BAIL
;
UnityPrintPointlessAndBail
();
}
if
(
UnityCheckArraysForNull
((
UNITY_INTERNAL_PTR
)
expected
,
(
UNITY_INTERNAL_PTR
)
actual
,
lineNumber
,
msg
)
==
1
)
...
...
src/unity.h
浏览文件 @
7053ef75
...
...
@@ -235,8 +235,8 @@ void tearDown(void);
//Structs and Strings
#define TEST_ASSERT_EQUAL_PTR_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_STRING((expected), (actual), __LINE__, (message))
#define TEST_ASSERT_EQUAL_STRING_LEN_MESSAGE(expected, actual, len, message) UNITY_TEST_ASSERT_EQUAL_STRING_LEN((expected), (actual), (len), __LINE__, (message))
#define TEST_ASSERT_EQUAL_MEMORY_MESSAGE(expected, actual, len, message) UNITY_TEST_ASSERT_EQUAL_MEMORY((expected), (actual), (len), __LINE__, (message))
#define TEST_ASSERT_EQUAL_STRING_LEN_MESSAGE(expected, actual, len, message)
UNITY_TEST_ASSERT_EQUAL_STRING_LEN((expected), (actual), (len), __LINE__, (message))
#define TEST_ASSERT_EQUAL_MEMORY_MESSAGE(expected, actual, len, message)
UNITY_TEST_ASSERT_EQUAL_MEMORY((expected), (actual), (len), __LINE__, (message))
//Arrays
#define TEST_ASSERT_EQUAL_INT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY((expected), (actual), (num_elements), __LINE__, (message))
...
...
test/Makefile
浏览文件 @
7053ef75
...
...
@@ -5,7 +5,8 @@ endif
#DEBUG = -O0 -g
CFLAGS
+=
-std
=
c99
-pedantic
-Wall
-Wextra
-Werror
-Wredundant-decls
CFLAGS
+=
$(DEBUG)
DEFINES
=
-D
UNITY_OUTPUT_CHAR
=
putcharSpy
-D
UNITY_INCLUDE_DOUBLE
DEFINES
=
-D
UNITY_OUTPUT_CHAR
=
putcharSpy
DEFINES
+=
-D
UNITY_SUPPORT_64
-D
UNITY_INCLUDE_DOUBLE
-D
UNITY_NO_WEAK
SRC
=
../src/unity.c tests/testunity.c build/testunityRunner.c
INC_DIR
=
-I
../src
COV_FLAGS
=
-fprofile-arcs
-ftest-coverage
-I
../../src
...
...
@@ -24,8 +25,6 @@ coverage: $(BUILD_DIR)/testunityRunner.c
./
$(TARGET)
|
grep
Tests
-A1
cd
$(BUILD_DIR)
&&
\
gcov unity.c |
head
-3
uncovered
:
grep
'###'
$(BUILD_DIR)
/unity.c.gcov
-C2
||
true
test
:
CFLAGS += -Wbad-function-cast -Wcast-qual -Wconversion -Wformat=2 -Wold-style-definition
\
...
...
test/tests/testunity.c
浏览文件 @
7053ef75
...
...
@@ -1370,7 +1370,7 @@ void testNotEqualString4(void)
void
testNotEqualStringLen4
(
void
)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_LEN
(
"
bar
\r
"
,
"bar
\n
"
,
4
);
TEST_ASSERT_EQUAL_STRING_LEN
(
"
\r\x16
"
,
"bar
\n
"
,
4
);
VERIFY_FAILS_END
}
...
...
@@ -1390,6 +1390,13 @@ void testNotEqualString_ExpectedStringIsNull(void)
VERIFY_FAILS_END
}
void
testNotEqualStringLen_ExpectedStringIsNull
(
void
)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_LEN
(
NULL
,
"bar"
,
1
);
VERIFY_FAILS_END
}
void
testNotEqualString_ActualStringIsNull
(
void
)
{
EXPECT_ABORT_BEGIN
...
...
@@ -1397,6 +1404,13 @@ void testNotEqualString_ActualStringIsNull(void)
VERIFY_FAILS_END
}
void
testNotEqualStringLen_ActualStringIsNull
(
void
)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_LEN
(
"foo"
,
NULL
,
1
);
VERIFY_FAILS_END
}
void
testEqualStringArrays
(
void
)
{
const
char
*
testStrings
[]
=
{
"foo"
,
"boo"
,
"woo"
,
"moo"
};
...
...
@@ -1476,6 +1490,16 @@ void testEqualStringArrayIfBothNulls(void)
TEST_ASSERT_EQUAL_STRING_ARRAY
(
expStrings
,
testStrings
,
4
);
}
void
testNotEqualStringArrayLengthZero
(
void
)
{
const
char
*
testStrings
[]
=
{
NULL
};
const
char
**
expStrings
=
NULL
;
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_ARRAY
(
expStrings
,
testStrings
,
0
);
VERIFY_FAILS_END
}
void
testEqualMemory
(
void
)
{
const
char
*
testString
=
"whatever"
;
...
...
@@ -1516,6 +1540,13 @@ void testNotEqualMemory4(void)
VERIFY_FAILS_END
}
void
testNotEqualMemoryLengthZero
(
void
)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_MEMORY
(
NULL
,
NULL
,
0
);
VERIFY_FAILS_END
}
void
testEqualIntArrays
(
void
)
{
int
p0
[]
=
{
1
,
8
,
987
,
-
2
};
...
...
@@ -1528,6 +1559,7 @@ void testEqualIntArrays(void)
TEST_ASSERT_EQUAL_INT_ARRAY
(
p0
,
p1
,
4
);
TEST_ASSERT_EQUAL_INT_ARRAY
(
p0
,
p2
,
3
);
TEST_ASSERT_EQUAL_INT_ARRAY
(
p0
,
p3
,
1
);
TEST_ASSERT_EQUAL_INT_ARRAY
(
NULL
,
NULL
,
1
);
}
void
testNotEqualIntArraysNullExpected
(
void
)
...
...
@@ -1580,6 +1612,16 @@ void testNotEqualIntArrays3(void)
VERIFY_FAILS_END
}
void
testNotEqualIntArraysLengthZero
(
void
)
{
_UU32
p0
[
1
]
=
{
1
};
_UU32
p1
[
1
]
=
{
1
};
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_INT_ARRAY
(
p0
,
p1
,
0
);
VERIFY_FAILS_END
}
void
testEqualPtrArrays
(
void
)
{
char
A
=
1
;
...
...
@@ -2218,6 +2260,19 @@ int putcharSpy(int c)
return
c
;
}
void
testFailureCountIncrementsAndIsReturnedAtEnd
(
void
)
{
Unity
.
CurrentTestFailed
=
1
;
startPutcharSpy
();
// Suppress output
UnityConcludeTest
();
TEST_ASSERT_EQUAL
(
1
,
Unity
.
TestFailures
);
int
failures
=
UnityEnd
();
Unity
.
TestFailures
--
;
endPutcharSpy
();
TEST_ASSERT_EQUAL
(
1
,
failures
);
}
#define TEST_ASSERT_EQUAL_PRINT_NUMBERS(expected, actual) { \
startPutcharSpy(); UnityPrintNumber((actual)); endPutcharSpy(); \
TEST_ASSERT_EQUAL_STRING((expected), getBufferPutcharSpy()); \
...
...
@@ -3005,6 +3060,7 @@ void testEqualFloatArrays(void)
TEST_ASSERT_EQUAL_FLOAT_ARRAY
(
p0
,
p1
,
4
);
TEST_ASSERT_EQUAL_FLOAT_ARRAY
(
p0
,
p2
,
3
);
TEST_ASSERT_EQUAL_FLOAT_ARRAY
(
p0
,
p3
,
1
);
TEST_ASSERT_EQUAL_FLOAT_ARRAY
(
NULL
,
NULL
,
1
);
#endif
}
...
...
@@ -3148,6 +3204,20 @@ void testNotEqualFloatArraysInf(void)
#endif
}
void
testNotEqualFloatArraysLengthZero
(
void
)
{
#ifdef UNITY_EXCLUDE_FLOAT
TEST_IGNORE
();
#else
float
p0
[
1
]
=
{
0
.
0
f
};
float
p1
[
1
]
=
{
0
.
0
f
};
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_FLOAT_ARRAY
(
p0
,
p1
,
0
);
VERIFY_FAILS_END
#endif
}
// ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES DOUBLE SUPPORT ==================
void
testDoublesWithinDelta
(
void
)
...
...
@@ -3521,6 +3591,7 @@ void testEqualDoubleArrays(void)
TEST_ASSERT_EQUAL_DOUBLE_ARRAY
(
p0
,
p1
,
4
);
TEST_ASSERT_EQUAL_DOUBLE_ARRAY
(
p0
,
p2
,
3
);
TEST_ASSERT_EQUAL_DOUBLE_ARRAY
(
p0
,
p3
,
1
);
TEST_ASSERT_EQUAL_DOUBLE_ARRAY
(
NULL
,
NULL
,
1
);
#endif
}
...
...
@@ -3664,6 +3735,22 @@ void testNotEqualDoubleArraysInf(void)
#endif
}
void
testNotEqualDoubleArraysLengthZero
(
void
)
{
#ifdef UNITY_EXCLUDE_DOUBLE
TEST_IGNORE
();
#else
double
p0
[
1
]
=
{
0
.
0
};
double
p1
[
1
]
=
{
0
.
0
};
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_DOUBLE_ARRAY
(
p0
,
p1
,
0
);
VERIFY_FAILS_END
#endif
}
// ===================== THESE TEST WILL RUN IF YOUR CONFIG INCLUDES DETAIL SUPPORT ==================
void
testThatDetailsCanBeHandleOneDetail
(
void
)
{
#ifdef UNITY_EXCLUDE_DETAILS
...
...
@@ -3677,6 +3764,19 @@ void testThatDetailsCanBeHandleOneDetail(void)
#endif
}
void
testThatDetailsCanHandleTestFail
(
void
)
{
#ifdef UNITY_EXCLUDE_DETAILS
TEST_IGNORE
();
#else
UNITY_SET_DETAILS
(
"Detail1"
,
"Detail2"
);
EXPECT_ABORT_BEGIN
TEST_FAIL_MESSAGE
(
"Should Fail And Say Detail1 and Detail2"
);
VERIFY_FAILS_END
#endif
}
void
testThatDetailsCanBeHandleTwoDetails
(
void
)
{
#ifdef UNITY_EXCLUDE_DETAILS
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录