mirror of
https://github.com/ThrowTheSwitch/Unity.git
synced 2026-01-23 08:25:58 +01:00
Updated makefile to run tests after building and added :clean and :all tasks.
Added UnityHelper module in order to show how to extend Unity. git-svn-id: http://unity.svn.sourceforge.net/svnroot/unity/trunk@2 e7d17a6e-8845-0410-bbbc-c8efb4fdad7e
This commit is contained in:
39
src/UnityHelper.c
Normal file
39
src/UnityHelper.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "unity.h"
|
||||
#include "UnityHelper.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static char message[1024];
|
||||
|
||||
void AssertEqualArrayUint(unsigned int* expected, unsigned int* actual, 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 AssertEqualArrayInt(int* expected, int* actual, 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 AssertEqualArrayFloatWithin(float tolerance, float* expected, float* actual, 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);
|
||||
}
|
||||
}
|
||||
12
src/UnityHelper.h
Normal file
12
src/UnityHelper.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef _TESTHELPER_H
|
||||
#define _TESTHELPER_H
|
||||
|
||||
void AssertEqualArrayUint(unsigned int* expected, unsigned int* actual, unsigned int length);
|
||||
void AssertEqualArrayInt(int* expected, int* actual, unsigned int length);
|
||||
void AssertEqualArrayFloatWithin(float tolerance, float* expected, float* actual, unsigned int length);
|
||||
|
||||
#define TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, length) {TEST_WRAP(AssertEqualArrayUint(expected, actual, length));}
|
||||
#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, length) {TEST_WRAP(AssertEqualArrayInt(expected, actual, length));}
|
||||
#define TEST_ASSERT_FLOAT_ARRAY_WITHIN(tolerance, expected, actual, length) {TEST_WRAP(AssertEqualArrayFloatWithin(tolerance, expected, actual, length));}
|
||||
|
||||
#endif // _TESTHELPER_H
|
||||
@@ -334,3 +334,7 @@ void UnityEnd(void)
|
||||
}
|
||||
}
|
||||
|
||||
int UnityGetNumFailures(void)
|
||||
{
|
||||
return Unity.TestFailures;
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ void CreateResults();
|
||||
|
||||
void UnityBegin();
|
||||
void UnityEnd(void);
|
||||
int UnityGetNumFailures(void);
|
||||
|
||||
void UnityPrintChar(char ch);
|
||||
void UnityPrint(const char *string);
|
||||
|
||||
Reference in New Issue
Block a user