initial commit for tests
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
#include "digio_mock.h"
|
||||
#undef DIG_IO_ENTRY
|
||||
#define DIG_IO_ENTRY(name, port, pin, mode) DigIo DigIo::name;
|
||||
DIG_IO_LIST
|
||||
|
||||
#undef ANA_IN_ENTRY
|
||||
#define ANA_IN_ENTRY(name, port, pin) AnaIn AnaIn::name;
|
||||
ANA_IN_LIST
|
||||
#undef ANA_IN_ENTRY
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
#include "../libopeninv/include/my_fp.h"
|
||||
#include <stdio.h>
|
||||
#include "../include/digio_prj.h"
|
||||
#include "../include/anain_prj.h"
|
||||
#ifndef TEST_MOCK_H
|
||||
#define TEST_MOCK_H
|
||||
class Can {
|
||||
public:
|
||||
void Send(uint32_t canId, uint32_t data[2]) { Send(canId, data, 8); }
|
||||
void Send(uint32_t canId, uint32_t data[2], uint8_t len) {} ;
|
||||
};
|
||||
//void Can::Send(uint32_t canId, uint32_t data[2], uint8_t len){ };
|
||||
|
||||
|
||||
class DigIo{
|
||||
public:
|
||||
#define DIG_IO_ENTRY(name, port, pin, mode) static DigIo name;
|
||||
DIG_IO_LIST
|
||||
#undef DIG_IO_ENTRY
|
||||
|
||||
bool val = 0;
|
||||
|
||||
bool Get() { return val; }
|
||||
void Set() { val = 1;}
|
||||
void Clear() { val = 0;}
|
||||
};
|
||||
|
||||
class AnaIn{
|
||||
public:
|
||||
#define ANA_IN_ENTRY(name, port, pin) static AnaIn name;
|
||||
ANA_IN_LIST
|
||||
#undef ANA_IN_ENTRY
|
||||
|
||||
bool Get() { return 1; }
|
||||
void Set() {}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
#include "../libopeninv/include/my_fp.h"
|
||||
#include "../libopeninv/include/my_math.h"
|
||||
#include "../libopeninv/include/params.h"
|
||||
#include "test.h"
|
||||
#include "test_can.h"
|
||||
#include "test_state.h"
|
||||
|
||||
extern void Param::Change(Param::PARAM_NUM ParamNum){ };
|
||||
|
||||
// To add a test:
|
||||
// 1) write void function test_x (see existing includes)
|
||||
// 2) register function & name to test_cases below
|
||||
|
||||
int main() {
|
||||
//Test Case register
|
||||
TestCase tests[] = {
|
||||
(TestCase){"test_is_evse_input", test_is_evse_input},
|
||||
(TestCase){"test_check_unplugged", test_check_unplugged},
|
||||
// Example:
|
||||
//(TestCase){"Your tests name", function_name_without_brackets}
|
||||
//...
|
||||
};
|
||||
|
||||
run_suite(tests, sizeof(tests)/sizeof(TestCase));
|
||||
return 0;
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct{
|
||||
char name[50];
|
||||
void (*func)(void);
|
||||
} TestCase;
|
||||
|
||||
|
||||
void run_suite(TestCase tests[], int num_cases){
|
||||
for(int i = 0; i < num_cases; i++){
|
||||
tests[i].func();
|
||||
printf("\r%d \033[0;32m\tPASSED\t%s\e[0m\n",i,tests[i].name);
|
||||
}
|
||||
printf("\033[0;32m ALL %d CASES PASSED\e[0m\n",num_cases);
|
||||
}
|
||||
|
||||
void run_case(TestCase tests[], int num_cases, char name[50]){
|
||||
printf("\rRUNNING INDIVIDUAL TEST \033[0;32m\t\t\e[0m\n");
|
||||
for(int i = 0; i < num_cases; i++){
|
||||
int res = strcmp(tests[i].name, name);
|
||||
if(0 == res)
|
||||
{
|
||||
tests[i].func();
|
||||
printf("\r%d \033[0;32m\tPASSED\t%s\e[0m\n",i,tests[i].name);
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,8 @@
|
||||
#ifndef TEST_CAN_H
|
||||
#define TEST_CAN_H
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include "test_common.h"
|
||||
#include "../libopeninv/include/my_fp.h"
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
|
||||
#ifndef TEST_COMMON_H
|
||||
#define TEST_COMMON_H
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
#ifndef TEST_STATE_H
|
||||
#define TEST_STATE_H
|
||||
#endif
|
||||
#include <assert.h>
|
||||
#include "test_common.h"
|
||||
#include "functions.h"
|
||||
|
||||
void test_is_evse_input()
|
||||
{
|
||||
|
||||
bool res = false;
|
||||
|
||||
res = IsEvseInput();
|
||||
assert(res);
|
||||
|
||||
Param::SetInt(Param::inputype, INP_MANUAL);
|
||||
res = IsEvseInput();
|
||||
assert(!res);
|
||||
}
|
||||
|
||||
void test_check_unplugged()
|
||||
{
|
||||
bool res = false;
|
||||
|
||||
Param::SetInt(Param::inputype, INP_TYPE1);
|
||||
//TODO: surprising behaviour with Param::Set(Param::proximity, true); // as it expects s32fp
|
||||
|
||||
Param::SetInt(Param::proximity, 1);
|
||||
res = CheckUnplugged();
|
||||
assert(!res);
|
||||
|
||||
Param::SetInt(Param::proximity, 0);
|
||||
res = CheckUnplugged();
|
||||
assert(res);
|
||||
}
|
||||
Reference in New Issue
Block a user