1
0
mirror of https://github.com/ThrowTheSwitch/Unity.git synced 2026-01-26 09:51:36 +01:00

Add example

This commit is contained in:
ml-physec
2025-04-16 19:21:48 +02:00
parent c359bf37b0
commit bfc785c665
8 changed files with 287 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
/* =========================================================================
Unity - A Test Framework for C
ThrowTheSwitch.org
Copyright (c) 2007-25 Mike Karlesky, Mark VanderVoord, & Greg Williams
SPDX-License-Identifier: MIT
========================================================================= */
#include "ProductionCode.h"
#include "unity.h"
const int* current_expected_bits = NULL;
UNITY_LINE_TYPE current_vector_line = 0;
typedef struct {
UNITY_LINE_TYPE line;
uint8_t value;
bit_direction_t dir;
int expected_bits[8];
} test_vector_t;
void setUp(void)
{
}
void tearDown(void)
{
}
static void be_bit_tester(int position, int value) {
UNITY_TEST_ASSERT_EQUAL_INT(current_expected_bits[position], value, current_vector_line, "Unexpected bit value");
}
void test_BitExtractor(void)
{
const test_vector_t test_vectors[] = {
{__LINE__, 7, BIT_DIRECTION_UP, {1,1,1,0,0,0,0,0}},
{__LINE__, 7, BIT_DIRECTION_DOWN, {0,0,0,0,0,1,0,1}},
{0}
};
const test_vector_t* tv;
for (tv = test_vectors; tv->line; tv++) {
current_vector_line = tv->line;
current_expected_bits = tv->expected_bits;
BitExtractor(tv->dir, tv->value, be_bit_tester);
}
}

View File

@@ -0,0 +1,48 @@
/* AUTOGENERATED FILE. DO NOT EDIT. */
/*=======Test Runner Used To Run Each Test Below=====*/
#define RUN_TEST(TestFunc, TestLineNum) \
{ \
Unity.CurrentTestName = #TestFunc; \
Unity.CurrentTestLineNumber = TestLineNum; \
Unity.NumberOfTests++; \
if (TEST_PROTECT()) \
{ \
setUp(); \
TestFunc(); \
} \
if (TEST_PROTECT()) \
{ \
tearDown(); \
} \
UnityConcludeTest(); \
}
/*=======Automagically Detected Files To Include=====*/
#include "unity.h"
#include <setjmp.h>
#include <stdio.h>
#include "ProductionCode.h"
/*=======External Functions This Runner Calls=====*/
extern void setUp(void);
extern void tearDown(void);
extern void test_BitExtractor(void);
/*=======Test Reset Option=====*/
void resetTest(void);
void resetTest(void)
{
tearDown();
setUp();
}
/*=======MAIN=====*/
int main(void)
{
UnityBegin("test/TestProductionCode.c");
RUN_TEST(test_BitExtractor, 32);
return UNITY_END();
}

View File

@@ -0,0 +1,18 @@
#define UNITY_DETAIL_STACK_SIZE 5
#define LABEL_AS_INT32 "#\x18" /*UNITY_DISPLAY_STYLE_INT32 = 0x18 */
#define LABEL_AS_HEX8 "#\x41" /* UNITY_DISPLAY_STYLE_HEX8 = 0x41 */
#define UNITY_DETAIL_LABEL_NAMES { 0, \
UNITY_DETAIL1_NAME, \
UNITY_DETAIL2_NAME, \
"During call", \
LABEL_AS_INT32 "Bit Position", \
LABEL_AS_HEX8 "Bit Mask", \
}
typedef enum {
UNITY_DETAIL_NONE = 0,
UNITY_DETAIL_D1 = 1,
UNITY_DETAIL_D2 = 2,
UNITY_DETAIL_CALL,
UNITY_DETAIL_BIT_POS,
UNITY_DETAIL_BIT_MASK,
} UNITY_DETAIL_LABEL_T;