C ordening
This commit is contained in:
31
C/C5 and C6 Adidas/test/channel_test.c
Normal file
31
C/C5 and C6 Adidas/test/channel_test.c
Normal 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();
|
||||
}
|
||||
30
C/C5 and C6 Adidas/test/decode_test.c
Normal file
30
C/C5 and C6 Adidas/test/decode_test.c
Normal 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();
|
||||
}
|
||||
64
C/C5 and C6 Adidas/test/encode_test.c
Normal file
64
C/C5 and C6 Adidas/test/encode_test.c
Normal file
@@ -0,0 +1,64 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#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)
|
||||
|
||||
extern void encode_setUp(void) {}
|
||||
extern void encode_tearDown(void) {}
|
||||
|
||||
void test_encode_get_nibbles_normal(void) {
|
||||
uint8_t high, low;
|
||||
encode_get_nibbles(0xAB, &high, &low);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x0A, high); // High nibble of 0xAB is 0xA
|
||||
TEST_ASSERT_EQUAL_UINT8(0x0B, low); // Low nibble of 0xAB is 0xB
|
||||
}
|
||||
|
||||
void test_encode_get_nibbles_null_ptrs(void) {
|
||||
encode_get_nibbles(0xAA, NULL, NULL); // Should not crash
|
||||
}
|
||||
|
||||
void test_encode_value_normal(void) {
|
||||
uint8_t high, low;
|
||||
encode_value(0x41, &high, &low);
|
||||
//0x41 = 01000001 --> nibHigh = 0x04, and nibLow = 0x01
|
||||
// Format: [0][d3][d2][d1][d0][p2][p1][p0] (MSB first)
|
||||
//high: 0 0100 101 --> 0x25
|
||||
//low: 0 0001 111 --> 0x0F
|
||||
TEST_ASSERT_EQUAL_HEX8(0x25, high);
|
||||
TEST_ASSERT_EQUAL_HEX8(0x0F, low);
|
||||
}
|
||||
|
||||
void test_encode_value_null_pointers(void) {
|
||||
encode_value(0x55, NULL, NULL); // Should not crash
|
||||
}
|
||||
|
||||
void test_encode_value_all_zeros(void) {
|
||||
uint8_t high, low;
|
||||
encode_value(0x00, &high, &low);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x00, high);
|
||||
TEST_ASSERT_EQUAL_UINT8(0x00, low);
|
||||
}
|
||||
|
||||
void test_encode_nibble_values(void) {
|
||||
TEST_ASSERT_EQUAL_UINT8(0x00, encode_nibble(0x00)); // All zeros
|
||||
TEST_ASSERT_EQUAL_UINT8(0x7F, encode_nibble(0x0F)); // All ones in nibble
|
||||
TEST_ASSERT_EQUAL_UINT8(0x55, encode_nibble(0x0A)); // 1010 pattern
|
||||
}
|
||||
|
||||
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_nibble_values);
|
||||
|
||||
UnityUnregisterSetupTearDown();
|
||||
}
|
||||
29
C/C5 and C6 Adidas/test/main.c
Normal file
29
C/C5 and C6 Adidas/test/main.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#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();
|
||||
extern void run_parity_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},
|
||||
{ "parity", run_parity_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);
|
||||
}
|
||||
42
C/C5 and C6 Adidas/test/parity_test.c
Normal file
42
C/C5 and C6 Adidas/test/parity_test.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "unity.h"
|
||||
#include "unity_test_module.h"
|
||||
#include "parity.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 parity_setUp(void){
|
||||
// This is run before EACH test
|
||||
}
|
||||
|
||||
extern void parity_tearDown(void){
|
||||
// This is run after EACH test
|
||||
}
|
||||
|
||||
void test_calculate_parity_bits_all_zeros(void) {
|
||||
uint8_t p0, p1, p2;
|
||||
calculate_parity_bits(0x00, &p0, &p1, &p2);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, p0);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, p1);
|
||||
TEST_ASSERT_EQUAL_UINT8(0, p2);
|
||||
}
|
||||
|
||||
void test_calculate_parity_bits_all_ones(void) {
|
||||
uint8_t p0, p1, p2;
|
||||
calculate_parity_bits(0x0F, &p0, &p1, &p2);
|
||||
// 0x0F = 1111
|
||||
// dus p0, p1 en p2 zijn '1'
|
||||
TEST_ASSERT_EQUAL_UINT8(1, p0);
|
||||
TEST_ASSERT_EQUAL_UINT8(1, p1);
|
||||
TEST_ASSERT_EQUAL_UINT8(1, p2);
|
||||
}
|
||||
|
||||
// Update run_parity_tests function
|
||||
void run_parity_tests(void) {
|
||||
UnityRegisterSetupTearDown(parity_setUp, parity_tearDown);
|
||||
|
||||
MY_RUN_TEST(test_calculate_parity_bits_all_zeros);
|
||||
MY_RUN_TEST(test_calculate_parity_bits_all_ones);
|
||||
|
||||
UnityUnregisterSetupTearDown();
|
||||
}
|
||||
Reference in New Issue
Block a user