Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Unity
提交
61c0b0b7
T
Third Party Unity
项目概览
OpenHarmony
/
Third Party Unity
1 年多 前同步成功
通知
36
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看板
提交
61c0b0b7
编写于
4月 23, 2015
作者:
E
Eivind Tagseth
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added support for TEST_ASSERT_EQUAL_STRING_LEN*
Compares two strings until maximum n bytes (i.e. strncmp()).
上级
271f299d
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
169 addition
and
1 deletion
+169
-1
README.md
README.md
+8
-0
docs/Unity Summary.txt
docs/Unity Summary.txt
+8
-0
src/unity.c
src/unity.c
+106
-0
src/unity.h
src/unity.h
+2
-1
src/unity_internals.h
src/unity_internals.h
+7
-0
test/tests/testunity.c
test/tests/testunity.c
+38
-0
未找到文件。
README.md
浏览文件 @
61c0b0b7
...
...
@@ -169,10 +169,18 @@ String Assertions
Compare two null-terminate strings. Fail if any character is different or if the lengths are different.
TEST_ASSERT_EQUAL_STRING_LEN(expected, actual, len)
Compare two strings. Fail if any character is different, stop comparing after len characters.
TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message)
Compare two null-terminate strings. Fail if any character is different or if the lengths are different. Output a custom message on failure.
TEST_ASSERT_EQUAL_STRING_LEN_MESSAGE(expected, actual, len, message)
Compare two strings. Fail if any character is different, stop comparing after len characters. Output a custom message on failure.
Pointer Assertions
------------------
...
...
docs/Unity Summary.txt
浏览文件 @
61c0b0b7
...
...
@@ -178,10 +178,18 @@ TEST_ASSERT_EQUAL_STRING(expected, actual)
Compare two null-terminate strings. Fail if any character is different or if the lengths are different.
TEST_ASSERT_EQUAL_STRING_LEN(expected, actual, len)
Compare two strings. Fail if any character is different, stop comparing after len characters.
TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message)
Compare two null-terminate strings. Fail if any character is different or if the lengths are different. Output a custom message on failure.
TEST_ASSERT_EQUAL_STRING_LEN_MESSAGE(expected, actual, len, message)
Compare two strings. Fail if any character is different, stop comparing after len characters. Output a custom message on failure.
------------------
Pointer Assertions
------------------
...
...
src/unity.c
浏览文件 @
61c0b0b7
...
...
@@ -110,6 +110,42 @@ void UnityPrint(const char* string)
}
}
void
UnityPrintLen
(
const
char
*
string
,
const
_UU32
length
)
{
const
char
*
pch
=
string
;
if
(
pch
!=
NULL
)
{
while
(
*
pch
&&
(
pch
-
string
)
<
length
)
{
// printable characters plus CR & LF are printed
if
((
*
pch
<=
126
)
&&
(
*
pch
>=
32
))
{
UNITY_OUTPUT_CHAR
(
*
pch
);
}
//write escaped carriage returns
else
if
(
*
pch
==
13
)
{
UNITY_OUTPUT_CHAR
(
'\\'
);
UNITY_OUTPUT_CHAR
(
'r'
);
}
//write escaped line feeds
else
if
(
*
pch
==
10
)
{
UNITY_OUTPUT_CHAR
(
'\\'
);
UNITY_OUTPUT_CHAR
(
'n'
);
}
// unprintable characters are shown as codes
else
{
UNITY_OUTPUT_CHAR
(
'\\'
);
UnityPrintNumberHex
((
_U_UINT
)
*
pch
,
2
);
}
pch
++
;
}
}
}
//-----------------------------------------------
void
UnityPrintNumberByStyle
(
const
_U_SINT
number
,
const
UNITY_DISPLAY_STYLE_T
style
)
{
...
...
@@ -348,6 +384,35 @@ static void UnityPrintExpectedAndActualStrings(const char* expected, const char*
}
}
//-----------------------------------------------
static
void
UnityPrintExpectedAndActualStringsLen
(
const
char
*
expected
,
const
char
*
actual
,
const
_UU32
length
)
{
UnityPrint
(
UnityStrExpected
);
if
(
expected
!=
NULL
)
{
UNITY_OUTPUT_CHAR
(
'\''
);
UnityPrintLen
(
expected
,
length
);
UNITY_OUTPUT_CHAR
(
'\''
);
}
else
{
UnityPrint
(
UnityStrNull
);
}
UnityPrint
(
UnityStrWas
);
if
(
actual
!=
NULL
)
{
UNITY_OUTPUT_CHAR
(
'\''
);
UnityPrintLen
(
actual
,
length
);
UNITY_OUTPUT_CHAR
(
'\''
);
}
else
{
UnityPrint
(
UnityStrNull
);
}
}
//-----------------------------------------------
// Assertion & Control Helpers
//-----------------------------------------------
...
...
@@ -944,6 +1009,47 @@ void UnityAssertEqualString(const char* expected,
}
}
//-----------------------------------------------
void
UnityAssertEqualStringLen
(
const
char
*
expected
,
const
char
*
actual
,
const
_UU32
length
,
const
char
*
msg
,
const
UNITY_LINE_TYPE
lineNumber
)
{
_UU32
i
;
UNITY_SKIP_EXECUTION
;
// if both pointers not null compare the strings
if
(
expected
&&
actual
)
{
for
(
i
=
0
;
(
expected
[
i
]
||
actual
[
i
])
&&
i
<
length
;
i
++
)
{
if
(
expected
[
i
]
!=
actual
[
i
])
{
Unity
.
CurrentTestFailed
=
1
;
break
;
}
}
}
else
{
// handle case of one pointers being null (if both null, test should pass)
if
(
expected
!=
actual
)
{
Unity
.
CurrentTestFailed
=
1
;
}
}
if
(
Unity
.
CurrentTestFailed
)
{
UnityTestResultsFailBegin
(
lineNumber
);
UnityPrintExpectedAndActualStringsLen
(
expected
,
actual
,
length
);
UnityAddMsgIfSpecified
(
msg
);
UNITY_FAIL_AND_BAIL
;
}
}
//-----------------------------------------------
void
UnityAssertEqualStringArray
(
const
char
**
expected
,
const
char
**
actual
,
...
...
src/unity.h
浏览文件 @
61c0b0b7
...
...
@@ -116,6 +116,7 @@
//Structs and Strings
#define TEST_ASSERT_EQUAL_PTR(expected, actual) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, NULL)
#define TEST_ASSERT_EQUAL_STRING(expected, actual) UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_STRING_LEN(expected, actual, len) UNITY_TEST_ASSERT_EQUAL_STRING_LEN(expected, actual, len, __LINE__, NULL)
#define TEST_ASSERT_EQUAL_MEMORY(expected, actual, len) UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, __LINE__, NULL)
//Arrays
...
...
@@ -219,7 +220,7 @@
//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)
//Arrays
...
...
src/unity_internals.h
浏览文件 @
61c0b0b7
...
...
@@ -440,6 +440,12 @@ void UnityAssertEqualString(const char* expected,
const
char
*
msg
,
const
UNITY_LINE_TYPE
lineNumber
);
void
UnityAssertEqualStringLen
(
const
char
*
expected
,
const
char
*
actual
,
const
_UU32
length
,
const
char
*
msg
,
const
UNITY_LINE_TYPE
lineNumber
);
void
UnityAssertEqualStringArray
(
const
char
**
expected
,
const
char
**
actual
,
const
_UU32
num_elements
,
...
...
@@ -597,6 +603,7 @@ extern const char UnityStrErr64[];
#define UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(_UP)(expected), (_U_SINT)(_UP)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_POINTER)
#define UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, line, message) UnityAssertEqualString((const char*)(expected), (const char*)(actual), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_STRING_LEN(expected, actual, len, line, message) UnityAssertEqualStringLen((const char*)(expected), (const char*)(actual), (_UU32)(len), (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, line, message) UnityAssertEqualMemory((UNITY_PTR_ATTRIBUTE void*)(expected), (UNITY_PTR_ATTRIBUTE void*)(actual), (_UU32)(len), 1, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_PTR_ATTRIBUTE const void*)(expected), (UNITY_PTR_ATTRIBUTE const void*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
...
...
test/tests/testunity.c
浏览文件 @
61c0b0b7
...
...
@@ -1265,6 +1265,16 @@ void testEqualStrings(void)
TEST_ASSERT_EQUAL_STRING
(
""
,
""
);
}
void
testEqualStringsLen
(
void
)
{
const
char
*
testString
=
"foobar"
;
TEST_ASSERT_EQUAL_STRING_LEN
(
testString
,
testString
,
strlen
(
testString
));
TEST_ASSERT_EQUAL_STRING_LEN
(
"foobar"
,
"foobaz"
,
5
);
TEST_ASSERT_EQUAL_STRING_LEN
(
"foo"
,
testString
,
3
);
TEST_ASSERT_EQUAL_STRING_LEN
(
testString
,
foo
,
3
);
TEST_ASSERT_EQUAL_STRING_LEN
(
""
,
""
,
3
);
}
void
testEqualStringsWithCarriageReturnsAndLineFeeds
(
void
)
{
const
char
*
testString
=
"foo
\r\n
bar"
;
...
...
@@ -1283,6 +1293,13 @@ void testNotEqualString1(void)
VERIFY_FAILS_END
}
void
testNotEqualStringLen1
(
void
)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_LEN
(
"foobar"
,
"foobaz"
,
6
);
VERIFY_FAILS_END
}
void
testNotEqualString2
(
void
)
{
EXPECT_ABORT_BEGIN
...
...
@@ -1290,6 +1307,13 @@ void testNotEqualString2(void)
VERIFY_FAILS_END
}
void
testNotEqualStringLen2
(
void
)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_LEN
(
"foo"
,
""
,
3
);
VERIFY_FAILS_END
}
void
testNotEqualString3
(
void
)
{
EXPECT_ABORT_BEGIN
...
...
@@ -1297,6 +1321,13 @@ void testNotEqualString3(void)
VERIFY_FAILS_END
}
void
testNotEqualStringLen3
(
void
)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_LEN
(
""
,
"bar"
,
3
);
VERIFY_FAILS_END
}
void
testNotEqualString4
(
void
)
{
EXPECT_ABORT_BEGIN
...
...
@@ -1304,6 +1335,13 @@ void testNotEqualString4(void)
VERIFY_FAILS_END
}
void
testNotEqualStringLen4
(
void
)
{
EXPECT_ABORT_BEGIN
TEST_ASSERT_EQUAL_STRING_LEN
(
"bar
\r
"
,
"bar
\n
"
,
4
);
VERIFY_FAILS_END
}
void
testNotEqualString5
(
void
)
{
const
char
str1
[]
=
{
0x41
,
0x42
,
0x03
,
0x00
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录