Skip to content

Instantly share code, notes, and snippets.

@mfilipelino
Last active May 20, 2016 02:22
Show Gist options
  • Save mfilipelino/b186635e0a94ba8b63e036cfc8e8146f to your computer and use it in GitHub Desktop.
Save mfilipelino/b186635e0a94ba8b63e036cfc8e8146f to your computer and use it in GitHub Desktop.
test unit integration file
// Framework unit_test c
#include <stdio.h>
#include <string.h>
// variaveis de teste
int a, *b;
// framework start
void tst_setup(char str[]){
printf(str);
a = 0;
b = (int*) malloc(sizeof(int));
}
void tst_teardown(char str[]){
free(b);
}
void tst_equal_int(int a, int b, char str[]){
printf("\nfunction: %-15s | expression: %-3d == %3d | ", str, a, b);
if(a == b){
printf("value: assert");
}
else{
printf("value: fail");
}
printf("\n");
}
void tst_equal_float(float a, float b, char str[]){
printf("\nfunction: %-15s | expression: %-3f == %3f | ", str, a, b);
if(a == b){
printf("value: assert");
}
else{
printf("value: fail");
}
printf("\n");
}
void tst_equal_str(char str1[], char str2[], char name[]){
printf("\nfunction: %-15s | expression: %s == %s | ", name, str1, str2);
if(strcmp(str1, str2) == 0){
printf("value: assert");
}
else{
printf("value: fail");
}
printf("\n");
}
void test_step1(char str[]){
tst_setup(str);
tst_equal_int(a, 0, "tst_equal_int");
tst_teardown("\n");
}
void test_step2(char str[]){
tst_setup(str);
tst_equal_str("aaa", "aaa", "tst_equal_str");
tst_teardown("\n");
}
void test_step3(char str[]){
tst_setup(str);
tst_equal_float(1.0, 1.0, "tst_equal_float");
tst_teardown("\n");
}
void group_test_full(){
test_step1("############ STEP 1 #############");
test_step2("############ STEP 2 #############");
test_step3("############ STEP 3 #############");
}
int main(int argc, char *argv[]) {
group_test_full();
return 0;
}
// framework end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment