mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2025-05-21 01:16:39 +08:00
git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@29 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
This commit is contained in:
45
examples/helper/UnityHelper.c
Normal file
45
examples/helper/UnityHelper.c
Normal file
@ -0,0 +1,45 @@
|
||||
#include "unity.h"
|
||||
#include "UnityHelper.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static char message[1024];
|
||||
|
||||
void AssertEqualUintArray(const unsigned int* expected, const unsigned int* actual, const unsigned int length)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
sprintf(message, "Array comparison failed at index %u.", i);
|
||||
TEST_ASSERT_EQUAL_UINT_MESSAGE(expected[i], actual[i], message);
|
||||
}
|
||||
}
|
||||
|
||||
void AssertEqualIntArray(const int* expected, const int* actual, const unsigned int length)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
sprintf(message, "Array comparison failed at index %u.", i);
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(expected[i], actual[i], message);
|
||||
}
|
||||
}
|
||||
|
||||
void AssertFloatArrayWithin(const float tolerance, const float* expected, const float* actual, const unsigned int length)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < length; i++)
|
||||
{
|
||||
sprintf(message, "Array mismatch at index %u, Expected %f, Actual %f, Tolerance %f, Delta %f", i, expected[i], actual[i], tolerance, (expected[i]-actual[i]));
|
||||
TEST_ASSERT_FLOAT_WITHIN_MESSAGE(tolerance, expected[i], actual[i], message);
|
||||
}
|
||||
}
|
||||
|
||||
void AssertEqualExampleStruct(EXAMPLE_STRUCT_T expected, EXAMPLE_STRUCT_T actual)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.x, actual.x, "Example Struct Failed For Field x");
|
||||
TEST_ASSERT_EQUAL_INT_MESSAGE(expected.y, actual.y, "Example Struct Failed For Field y");
|
||||
}
|
17
examples/helper/UnityHelper.h
Normal file
17
examples/helper/UnityHelper.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef _TESTHELPER_H
|
||||
#define _TESTHELPER_H
|
||||
|
||||
#include "Types.h"
|
||||
|
||||
void AssertEqualUintArray(const unsigned int* expected, const unsigned int* actual, const unsigned int length);
|
||||
void AssertEqualIntArray(const int* expected, const int* actual, const unsigned int length);
|
||||
void AssertEqualCharArray(const char expected[], const char actual[], const int length);
|
||||
void AssertFloatArrayWithin(const float tolerance, const float* expected, const float* actual, const unsigned int length);
|
||||
void AssertEqualExampleStruct(const EXAMPLE_STRUCT_T expected, const EXAMPLE_STRUCT_T actual);
|
||||
|
||||
#define TEST_ASSERT_EQUAL_uint32_ARRAY(expected, actual, length) {AssertEqualUintArray(expected, actual, length);}
|
||||
#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, length) {AssertEqualIntArray(expected, actual, length);}
|
||||
#define TEST_ASSERT_FLOAT_ARRAY_WITHIN(tolerance, expected, actual, length) {AssertFloatArrayWithin(tolerance, expected, actual, length);}
|
||||
#define TEST_ASSERT_EQUAL_EXAMPLE_STRUCT_T(expected, actual) {AssertEqualExampleStruct(expected, actual);}
|
||||
|
||||
#endif // _TESTHELPER_H
|
Reference in New Issue
Block a user