Using Unity (a special library for C for Unit tests)

This commit is contained in:
andrey 2026-01-22 18:18:03 +07:00
parent 857d79e572
commit fd7c6c91cd
10 changed files with 4638 additions and 24 deletions

View file

@ -49,6 +49,8 @@
<Unit filename="main.c"> <Unit filename="main.c">
<Option compilerVar="CC" /> <Option compilerVar="CC" />
</Unit> </Unit>
<Unit filename="main.h" />
<Unit filename="test_utilities.h" />
<Unit filename="tests/complex.c"> <Unit filename="tests/complex.c">
<Option compilerVar="CC" /> <Option compilerVar="CC" />
</Unit> </Unit>
@ -229,6 +231,11 @@
<Option compilerVar="CC" /> <Option compilerVar="CC" />
</Unit> </Unit>
<Unit filename="tests/versor/versor_swap.h" /> <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 /> <Extensions />
</Project> </Project>
</CodeBlocks_project_file> </CodeBlocks_project_file>

View file

@ -1,28 +1,19 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "helpers.h" #include "main.h"
#include "tests/utilities.h" #include "unity/unity.h"
#include "tests/vector2.h"
#include "tests/vector3.h" void setUp()
#include "tests/complex.h" {
#include "tests/quaternion.h" }
#include "tests/versor.h"
void tearDown()
{
}
int main() int main()
{ {
test_utilities();
test_vector2();
test_vector3();
test_complex();
test_quaternion();
test_versor();
return 0; return 0;
} }

View file

@ -0,0 +1,8 @@
#ifndef BGC_TEST_MAIN_H_INCLUDED
#define BGC_TEST_MAIN_H_INCLUDED
void setUp();
void tearDown();
#endif

View file

@ -0,0 +1,8 @@
#ifndef BGC_TEST_UTILITIES_H_INCLUDED
#define BGC_TEST_UTILITIES_H_INCLUDED
#include "unity/unity.h"
#endif

View file

@ -11,9 +11,10 @@ void test_complex()
test_complex_is_zero(); test_complex_is_zero();
test_complex_is_unit(); test_complex_is_unit();
test_complex_modulus(); test_complex_modulus();
/*
test_complex_add(); test_complex_add();
test_complex_subtract(); test_complex_subtract();
test_complex_multiply(); test_complex_multiply();
test_complex_divide(); test_complex_divide();
*/
} }

View file

@ -1,4 +1,4 @@
#include "vector2.h" #include "./vector2.h"
void test_vector2() void test_vector2()
{ {
@ -11,11 +11,12 @@ void test_vector2()
test_vector2_is_zero(); test_vector2_is_zero();
test_vector2_is_unit(); test_vector2_is_unit();
test_vector2_modulus(); test_vector2_modulus();
/*
test_vector2_add(); test_vector2_add();
test_vector2_subtract(); test_vector2_subtract();
test_vector2_multiply(); test_vector2_multiply();
test_vector2_divide(); test_vector2_divide();
*/
} }

View file

@ -1,4 +1,6 @@
#include "vector3.h" #include "./vector3.h"
#include "./../helpers.h"
void test_vector3() void test_vector3()
{ {
@ -11,9 +13,10 @@ void test_vector3()
test_vector3_is_zero(); test_vector3_is_zero();
test_vector3_is_unit(); test_vector3_is_unit();
test_vector3_modulus(); test_vector3_modulus();
/*
test_vector3_add(); test_vector3_add();
test_vector3_subtract(); test_vector3_subtract();
test_vector3_multiply(); test_vector3_multiply();
test_vector3_divide(); test_vector3_divide();
*/
} }

File diff suppressed because it is too large Load diff

View file

Internal server error - Personal Git Server: Beyond coding. We Forge.

500

Internal server error

Forgejo version: 11.0.1+gitea-1.22.0

@ -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