This commit is contained in:
Rens Pastoor
2025-05-27 22:41:46 +02:00
parent d141296aea
commit 11b391b8a1
416 changed files with 25232 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
#include "unity.h"
#include "unity_test_module.h"
#include "channel.h"
// I rather dislike keeping line numbers updated, so I made my own macro to ditch the line number
#define MY_RUN_TEST(func) RUN_TEST(func, 0)
extern void channel_setUp(void)
{
// This is run before EACH test
}
extern void channel_tearDown(void)
{
// This is run after EACH test
}
static void test_channel(void)
{
TEST_ASSERT_EQUAL(1, 0);
}
void run_channel_tests()
{
UnityRegisterSetupTearDown( channel_setUp, channel_tearDown);
MY_RUN_TEST(test_channel);
UnityUnregisterSetupTearDown();
}

View File

@@ -0,0 +1,30 @@
#include "unity.h"
#include "unity_test_module.h"
#include "decode.h"
// I rather dislike keeping line numbers updated, so I made my own macro to ditch the line number
#define MY_RUN_TEST(func) RUN_TEST(func, 0)
extern void decode_setUp(void)
{
// This is run before EACH test
}
extern void decode_tearDown(void)
{
// This is run after EACH test
}
void test_decode(void)
{
TEST_ASSERT_EQUAL(1, 0);
}
void run_decode_tests()
{
UnityRegisterSetupTearDown( decode_setUp, decode_tearDown);
MY_RUN_TEST(test_decode);
UnityUnregisterSetupTearDown();
}

View File

@@ -0,0 +1,87 @@
#include <stdlib.h>
#include <unistd.h> // for close()
#include "unity.h"
#include "parity.h"
#include "unity_test_module.h"
#include "encode.h"
// Macro om zonder regelnummers te testen
#define MY_RUN_TEST(func) RUN_TEST(func, 0)
// Setup/teardown hooks
extern void encode_setUp(void) {}
extern void encode_tearDown(void) {}
/// --- TEST: encode_get_nibbles ---
void test_encode_get_nibbles_normal(void) {
uint8_t high, low;
encode_get_nibbles(0xAB, &high, &low); // 0xAB = 10101011
TEST_ASSERT_EQUAL_UINT8(0x0A, high); // 1010
TEST_ASSERT_EQUAL_UINT8(0x0B, low); // 1011
}
void test_encode_get_nibbles_null_ptrs(void) {
uint8_t value = 0xAA;
encode_get_nibbles(value, NULL, NULL); // mag niet crashen
// Geen assert nodig; slaagt bij geen crash
}
void test_encode_value_normal(void) {
uint8_t high, low;
encode_value(0xAC, &high, &low); // 0xA = 1010, 0xC = 1100
TEST_ASSERT_EQUAL_UINT8(add_parity(0xA), high);
TEST_ASSERT_EQUAL_UINT8(add_parity(0xC), low);
}
void test_encode_value_null_pointers(void) {
encode_value(0x55, NULL, NULL); // mag niet crashen
}
void test_encode_value_all_zeros(void) {
uint8_t high, low;
encode_value(0x00, &high, &low);
TEST_ASSERT_EQUAL_UINT8(add_parity(0x00), high);
TEST_ASSERT_EQUAL_UINT8(add_parity(0x00), low);
}
void test_encode_value_all_ones(void) {
uint8_t high, low;
encode_value(0xFF, &high, &low);
TEST_ASSERT_EQUAL_UINT8(add_parity(0x0F), high); // 1111
TEST_ASSERT_EQUAL_UINT8(add_parity(0x0F), low); // 1111
}
void test_encode_value_output_differs_from_input(void) {
uint8_t input = 0x3C;
uint8_t high, low;
encode_value(input, &high, &low);
TEST_ASSERT_NOT_EQUAL(input, high);
TEST_ASSERT_NOT_EQUAL(input, low);
}
void test_encode_value_is_consistent(void) {
uint8_t h1, l1, h2, l2;
encode_value(0x6E, &h1, &l1);
encode_value(0x6E, &h2, &l2);
TEST_ASSERT_EQUAL_UINT8(h1, h2);
TEST_ASSERT_EQUAL_UINT8(l1, l2);
}
void run_encode_tests() {
UnityRegisterSetupTearDown(encode_setUp, encode_tearDown);
MY_RUN_TEST(test_encode_get_nibbles_normal);
MY_RUN_TEST(test_encode_get_nibbles_null_ptrs);
MY_RUN_TEST(test_encode_value_normal);
MY_RUN_TEST(test_encode_value_null_pointers);
MY_RUN_TEST(test_encode_value_all_zeros);
MY_RUN_TEST(test_encode_value_all_ones);
MY_RUN_TEST(test_encode_value_output_differs_from_input);
MY_RUN_TEST(test_encode_value_is_consistent);
UnityUnregisterSetupTearDown();
}

View File

@@ -0,0 +1,27 @@
#include "unity_test_module.h"
/* As an alternative for header files we can declare that
* the following methos are available 'extern'ally.
*/
extern void run_encode_tests();
extern void run_channel_tests();
extern void run_decode_tests();
/*
* You can add here additional run_XXX_tests modules, if needed. Can be handy when you have
* code that can be used by the encoder as well as the decoder.
* Then you need to add additional files!
*
*/
int main (int argc, char * argv[])
{
UnityTestModule allModules[] = { { "encode", run_encode_tests},
{ "channel", run_channel_tests},
{ "decode", run_decode_tests}
};
size_t number_of_modules = sizeof(allModules)/sizeof(allModules[0]);
return UnityTestModuleRun(argc, argv, allModules, number_of_modules);
}