提交 031b1ba4 编写于 作者: M Mark VanderVoord 提交者: GitHub

Merge pull request #300 from jsalling/bugfix/greater-than

Bugfix greater/less than asserts with unsigned int. (Thanks @jsalling! I can't express what a GREAT job you did with this.)
......@@ -18,7 +18,9 @@ install:
script:
- cd test && rake ci
- make -s
- make -s DEBUG=-m32
- make -s DEBUG=-m32 #32-bit architecture with 64-bit support
- make -s DEBUG=-m32 UNITY_SUPPORT_64= #32-bit build without 64-bit types
- make -s UNITY_INCLUDE_DOUBLE= # without double
- cd ../extras/fixture/test && rake ci
- make -s default noStdlibMalloc
- make -s C89
......
......@@ -29,6 +29,7 @@ static const char UnityStrExpected[] = " Expected ";
static const char UnityStrWas[] = " Was ";
static const char UnityStrGt[] = " to be greater than ";
static const char UnityStrLt[] = " to be less than ";
static const char UnityStrOrEqual[] = "or equal to ";
static const char UnityStrElement[] = " Element ";
static const char UnityStrByte[] = " Byte ";
static const char UnityStrMemory[] = " Memory Mismatch.";
......@@ -531,49 +532,44 @@ void UnityAssertEqualNumber(const UNITY_INT expected,
}
/*-----------------------------------------------*/
void UnityAssertGreaterNumber(const UNITY_INT threshold,
const UNITY_INT actual,
const char *msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
void UnityAssertGreaterOrLessOrEqualNumber(const UNITY_INT threshold,
const UNITY_INT actual,
const UNITY_COMPARISON_T compare,
const char *msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
{
int failed = 0;
RETURN_IF_FAIL_OR_IGNORE;
if (!(actual > threshold))
if (threshold == actual && compare & UNITY_EQUAL_TO) return;
if (threshold == actual) failed = 1;
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(actual, style);
UnityPrint(UnityStrGt);
UnityPrintNumberByStyle(threshold, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
if (actual > threshold && compare & UNITY_SMALLER_THAN) failed = 1;
if (actual < threshold && compare & UNITY_GREATER_THAN) failed = 1;
}
else /* UINT or HEX */
{
if ((UNITY_UINT)actual > (UNITY_UINT)threshold && compare & UNITY_SMALLER_THAN) failed = 1;
if ((UNITY_UINT)actual < (UNITY_UINT)threshold && compare & UNITY_GREATER_THAN) failed = 1;
}
}
/*-----------------------------------------------*/
void UnityAssertSmallerNumber(const UNITY_INT threshold,
const UNITY_INT actual,
const char *msg,
const UNITY_LINE_TYPE lineNumber,
const UNITY_DISPLAY_STYLE_T style)
{
RETURN_IF_FAIL_OR_IGNORE;
if (!(actual < threshold))
if (failed)
{
UnityTestResultsFailBegin(lineNumber);
UnityPrint(UnityStrExpected);
UnityPrintNumberByStyle(actual, style);
UnityPrint(UnityStrLt);
if (compare & UNITY_GREATER_THAN) UnityPrint(UnityStrGt);
if (compare & UNITY_SMALLER_THAN) UnityPrint(UnityStrLt);
if (compare & UNITY_EQUAL_TO) UnityPrint(UnityStrOrEqual);
UnityPrintNumberByStyle(threshold, style);
UnityAddMsgIfSpecified(msg);
UNITY_FAIL_AND_BAIL;
}
}
#define UnityPrintPointlessAndBail() \
{ \
UnityTestResultsFailBegin(lineNumber); \
......
此差异已折叠。
此差异已折叠。
......@@ -15,7 +15,9 @@ CFLAGS += -Wbad-function-cast -Wcast-qual -Wold-style-definition -Wshadow -Wstri
CFLAGS += $(DEBUG)
DEFINES = -D UNITY_OUTPUT_CHAR=putcharSpy
DEFINES += -D UNITY_OUTPUT_CHAR_HEADER_DECLARATION=putcharSpy\(int\)
DEFINES += -D UNITY_SUPPORT_64 -D UNITY_INCLUDE_DOUBLE
DEFINES += $(UNITY_SUPPORT_64) $(UNITY_INCLUDE_DOUBLE)
UNITY_SUPPORT_64 = -D UNITY_SUPPORT_64
UNITY_INCLUDE_DOUBLE = -D UNITY_INCLUDE_DOUBLE
SRC = ../src/unity.c tests/testunity.c build/testunityRunner.c
INC_DIR = -I ../src
COV_FLAGS = -fprofile-arcs -ftest-coverage -I ../../src
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册