test_demo


#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;
}

文章作者: Vyron Su
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 Vyron Su !