Using Unity (a special library for C for Unit tests)
This commit is contained in:
parent
857d79e572
commit
fd7c6c91cd
10 changed files with 4638 additions and 24 deletions
|
|
@ -49,6 +49,8 @@
|
|||
<Unit filename="main.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="main.h" />
|
||||
<Unit filename="test_utilities.h" />
|
||||
<Unit filename="tests/complex.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
|
|
@ -229,6 +231,11 @@
|
|||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="tests/versor/versor_swap.h" />
|
||||
<Unit filename="unity/unity.c">
|
||||
<Option compilerVar="CC" />
|
||||
</Unit>
|
||||
<Unit filename="unity/unity.h" />
|
||||
<Unit filename="unity/unity_internals.h" />
|
||||
<Extensions />
|
||||
</Project>
|
||||
</CodeBlocks_project_file>
|
||||
|
|
|
|||
|
|
@ -1,28 +1,19 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "helpers.h"
|
||||
#include "main.h"
|
||||
|
||||
#include "tests/utilities.h"
|
||||
#include "tests/vector2.h"
|
||||
#include "tests/vector3.h"
|
||||
#include "tests/complex.h"
|
||||
#include "tests/quaternion.h"
|
||||
#include "tests/versor.h"
|
||||
#include "unity/unity.h"
|
||||
|
||||
void setUp()
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
test_utilities();
|
||||
|
||||
test_vector2();
|
||||
|
||||
test_vector3();
|
||||
|
||||
test_complex();
|
||||
|
||||
test_quaternion();
|
||||
|
||||
test_versor();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
8
basic-geometry-test/main.h
Normal file
8
basic-geometry-test/main.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef BGC_TEST_MAIN_H_INCLUDED
|
||||
#define BGC_TEST_MAIN_H_INCLUDED
|
||||
|
||||
void setUp();
|
||||
|
||||
void tearDown();
|
||||
|
||||
#endif
|
||||
8
basic-geometry-test/test_utilities.h
Normal file
8
basic-geometry-test/test_utilities.h
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#ifndef BGC_TEST_UTILITIES_H_INCLUDED
|
||||
#define BGC_TEST_UTILITIES_H_INCLUDED
|
||||
|
||||
#include "unity/unity.h"
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -11,9 +11,10 @@ void test_complex()
|
|||
test_complex_is_zero();
|
||||
test_complex_is_unit();
|
||||
test_complex_modulus();
|
||||
|
||||
/*
|
||||
test_complex_add();
|
||||
test_complex_subtract();
|
||||
test_complex_multiply();
|
||||
test_complex_divide();
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#include "vector2.h"
|
||||
#include "./vector2.h"
|
||||
|
||||
void test_vector2()
|
||||
{
|
||||
|
|
@ -11,11 +11,12 @@ void test_vector2()
|
|||
test_vector2_is_zero();
|
||||
test_vector2_is_unit();
|
||||
test_vector2_modulus();
|
||||
|
||||
/*
|
||||
test_vector2_add();
|
||||
test_vector2_subtract();
|
||||
test_vector2_multiply();
|
||||
test_vector2_divide();
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
#include "vector3.h"
|
||||
#include "./vector3.h"
|
||||
|
||||
#include "./../helpers.h"
|
||||
|
||||
void test_vector3()
|
||||
{
|
||||
|
|
@ -11,9 +13,10 @@ void test_vector3()
|
|||
test_vector3_is_zero();
|
||||
test_vector3_is_unit();
|
||||
test_vector3_modulus();
|
||||
|
||||
/*
|
||||
test_vector3_add();
|
||||
test_vector3_subtract();
|
||||
test_vector3_multiply();
|
||||
test_vector3_divide();
|
||||
*/
|
||||
}
|
||||
|
|
|
|||
2626
basic-geometry-test/unity/unity.c
Normal file
2626
basic-geometry-test/unity/unity.c
Normal file
File diff suppressed because it is too large
Load diff
698
basic-geometry-test/unity/unity.h
Normal file
698
basic-geometry-test/unity/unity.h
Normal file
|
|
@ -0,0 +1,698 @@
|
|||
/* =========================================================================
|
||||
Unity - A Test Framework for C
|
||||
ThrowTheSwitch.org
|
||||
Copyright (c) 2007-25 Mike Karlesky, Mark VanderVoord, & Greg Williams
|
||||
SPDX-License-Identifier: MIT
|
||||
========================================================================= */
|
||||
|
||||
#ifndef UNITY_FRAMEWORK_H
|
||||
#define UNITY_FRAMEWORK_H
|
||||
#define UNITY
|
||||
|
||||
#define UNITY_VERSION_MAJOR 2
|
||||
#define UNITY_VERSION_MINOR 6
|
||||
#define UNITY_VERSION_BUILD 2
|
||||
#define UNITY_VERSION ((UNITY_VERSION_MAJOR << 16) | (UNITY_VERSION_MINOR << 8) | UNITY_VERSION_BUILD)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include "unity_internals.h"
|
||||
|
||||
/*-------------------------------------------------------
|
||||
* Test Setup / Teardown
|
||||
*-------------------------------------------------------*/
|
||||
|
||||
/* These functions are intended to be called before and after each test.
|
||||
* If using unity directly, these will need to be provided for each test
|
||||
* executable built. If you are using the test runner generator and/or
|
||||
* Ceedling, these are optional. */
|
||||
void setUp(void);
|
||||
void tearDown(void);
|
||||
|
||||
/* These functions are intended to be called at the beginning and end of an
|
||||
* entire test suite. suiteTearDown() is passed the number of tests that
|
||||
* failed, and its return value becomes the exit code of main(). If using
|
||||
* Unity directly, you're in charge of calling these if they are desired.
|
||||
* If using Ceedling or the test runner generator, these will be called
|
||||
* automatically if they exist. */
|
||||
void suiteSetUp(void);
|
||||
int suiteTearDown(int num_failures);
|
||||
|
||||
/*-------------------------------------------------------
|
||||
* Test Reset and Verify
|
||||
*-------------------------------------------------------*/
|
||||
|
||||
/* These functions are intended to be called before or during tests in order
|
||||
* to support complex test loops, etc. Both are NOT built into Unity. Instead
|
||||
* the test runner generator will create them. resetTest will run teardown and
|
||||
* setup again, verifying any end-of-test needs between. verifyTest will only
|
||||
* run the verification. */
|
||||
void resetTest(void);
|
||||
void verifyTest(void);
|
||||
|
||||
/*-------------------------------------------------------
|
||||
* Configuration Options
|
||||
*-------------------------------------------------------
|
||||
* All options described below should be passed as a compiler flag to all files using Unity. If you must add #defines, place them BEFORE the #include above.
|
||||
|
||||
* Integers/longs/pointers
|
||||
* - Unity attempts to automatically discover your integer sizes
|
||||
* - define UNITY_EXCLUDE_STDINT_H to stop attempting to look in <stdint.h>
|
||||
* - define UNITY_EXCLUDE_LIMITS_H to stop attempting to look in <limits.h>
|
||||
* - If you cannot use the automatic methods above, you can force Unity by using these options:
|
||||
* - define UNITY_SUPPORT_64
|
||||
* - set UNITY_INT_WIDTH
|
||||
* - set UNITY_LONG_WIDTH
|
||||
* - set UNITY_POINTER_WIDTH
|
||||
|
||||
* Floats
|
||||
* - define UNITY_EXCLUDE_FLOAT to disallow floating point comparisons
|
||||
* - define UNITY_FLOAT_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_FLOAT
|
||||
* - define UNITY_FLOAT_TYPE to specify doubles instead of single precision floats
|
||||
* - define UNITY_INCLUDE_DOUBLE to allow double floating point comparisons
|
||||
* - define UNITY_EXCLUDE_DOUBLE to disallow double floating point comparisons (default)
|
||||
* - define UNITY_DOUBLE_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_DOUBLE
|
||||
* - define UNITY_DOUBLE_TYPE to specify something other than double
|
||||
* - define UNITY_EXCLUDE_FLOAT_PRINT to trim binary size, won't print floating point values in errors
|
||||
|
||||
* Output
|
||||
* - by default, Unity prints to standard out with putchar. define UNITY_OUTPUT_CHAR(a) with a different function if desired
|
||||
* - define UNITY_DIFFERENTIATE_FINAL_FAIL to print FAILED (vs. FAIL) at test end summary - for automated search for failure
|
||||
|
||||
* Optimization
|
||||
* - by default, line numbers are stored in unsigned shorts. Define UNITY_LINE_TYPE with a different type if your files are huge
|
||||
* - by default, test and failure counters are unsigned shorts. Define UNITY_COUNTER_TYPE with a different type if you want to save space or have more than 65535 Tests.
|
||||
|
||||
* Test Cases
|
||||
* - define UNITY_SUPPORT_TEST_CASES to include the TEST_CASE macro, though really it's mostly about the runner generator script
|
||||
|
||||
* Parameterized Tests
|
||||
* - you'll want to create a define of TEST_CASE(...), TEST_RANGE(...) and/or TEST_MATRIX(...) which basically evaluates to nothing
|
||||
|
||||
* Tests with Arguments
|
||||
* - you'll want to define UNITY_USE_COMMAND_LINE_ARGS if you have the test runner passing arguments to Unity
|
||||
|
||||
*-------------------------------------------------------
|
||||
* Basic Fail and Ignore
|
||||
*-------------------------------------------------------*/
|
||||
|
||||
#define TEST_FAIL_MESSAGE(message) UNITY_TEST_FAIL(__LINE__, (message))
|
||||
#define TEST_FAIL() UNITY_TEST_FAIL(__LINE__, NULL)
|
||||
#define TEST_IGNORE_MESSAGE(message) UNITY_TEST_IGNORE(__LINE__, (message))
|
||||
#define TEST_IGNORE() UNITY_TEST_IGNORE(__LINE__, NULL)
|
||||
#define TEST_MESSAGE(message) UnityMessage((message), __LINE__)
|
||||
#define TEST_ONLY()
|
||||
#ifdef UNITY_INCLUDE_PRINT_FORMATTED
|
||||
#define TEST_PRINTF(message, ...) UnityPrintF(__LINE__, (message), ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
/* It is not necessary for you to call PASS. A PASS condition is assumed if nothing fails.
|
||||
* This method allows you to abort a test immediately with a PASS state, ignoring the remainder of the test. */
|
||||
#define TEST_PASS() TEST_ABORT()
|
||||
#define TEST_PASS_MESSAGE(message) do { UnityMessage((message), __LINE__); TEST_ABORT(); } while (0)
|
||||
|
||||
/*-------------------------------------------------------
|
||||
* Build Directives
|
||||
*-------------------------------------------------------
|
||||
|
||||
* These macros do nothing, but they are useful for additional build context.
|
||||
* Tools (like Ceedling) can scan for these directives and make use of them for
|
||||