#include <stdio.h>
#include <stdlib.h>
typedef struct EM_Test{
int a, b;
int output;
int (*TestEMFunc)(int, int);
}T_EMTest;
T_EMTest* addFunc(int (*TestEMFunc)(int, int), int a, int b, int output){
T_EMTest *m_EMTest = (T_EMTest *)malloc(sizeof(T_EMTest));
m_EMTest->a = a;
m_EMTest->b = b;
m_EMTest->output = output;
m_EMTest->TestEMFunc = TestEMFunc;
return m_EMTest;
}
int add(int a, int b){
// a = 10;
return a + b;
}
void runEMTest(T_EMTest *p_EMTest){
if(p_EMTest != NULL){
int ans = p_EMTest->TestEMFunc(p_EMTest->a, p_EMTest->b);
if(ans == p_EMTest->output){
printf("Successful!\n");
}else{
printf("Fail!\n %d != %d", ans, p_EMTest->output);
}
free(p_EMTest);
}
}
int main(void){
printf("app start...\n");
T_EMTest *m_EMTest = addFunc(add, 1, 2, 3);
runEMTest(m_EMTest);
return 0;
}
上一篇
stm32-1 GPIO
STM学习笔记1
2022-06-10
下一篇
Zlog
2022-06-07