Newer
Older
#include "run.h"
#include <CUnit/CUnit.h>
#include <CUnit/TestRun.h>
#include <CUnit/CUError.h>
void test_is_div(void){
CU_ASSERT_TRUE(is_div(14,7));
}
void test_is_prime(void){
CU_ASSERT_TRUE(is_prime(13));
}
void test_is_not_prime(void){
CU_ASSERT_FALSE(is_prime(14));
}
int err = run("Test_files/empty_input.txt","actual_output.txt",4);
if (err == -1){
CU_FAIL("method run failed");
return;
}
file1 = fopen("actual_output.txt","r");
if (file1 == NULL){
CU_FAIL("actual_output opening fail");
return;
}
char chaine1[20];
CU_ASSERT_EQUAL(fgets(chaine1,20,file1),NULL);
fclose(file1);
}
void short_file_test(void){
FILE *file1 = NULL;
FILE *file2 = NULL;
file1 = fopen("Test_files/short_expected_output.txt","r");
if (file1 == NULL){
CU_FAIL("short_expected_output opening fail");
return;
}
int err = run("Test_files/short_input.txt","actual_output.txt",4);
file2 = fopen("actual_output.txt","r");
if (file2 == NULL){
CU_FAIL("actual_output opening fail");
return;
}
char chaine1[50];
char chaine2[50];
while (fgets(chaine1,50,file1) != NULL && fgets(chaine2,50,file2) != NULL)
{
//printf("%s\n",chaine1);
//printf("%s\n",chaine2);
CU_ASSERT_STRING_EQUAL(chaine1,chaine2);
}
fclose(file1);
fclose(file2);
}
if (file1 == NULL){
CU_FAIL("expected_output opening fail");
return;
}
int err = run("Test_files/input.txt","actual_output.txt",4);
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
fclose(file1);
return;
}
file2 = fopen("actual_output.txt","r");
if (file2 == NULL){
CU_FAIL("actual_output opening fail");
fclose(file1);
return;
}
char chaine2[50];
int n = 0;
while (fgets(chaine2,50,file2) != NULL)
{
n++;
}
CU_ASSERT_EQUAL(n,100);
fclose(file1);
fclose(file2);
}
void file_test_N_1(void){
FILE *file1 = NULL;
FILE *file2 = NULL;
file1 = fopen("Test_files/expected_output.txt","r");
if (file1 == NULL){
CU_FAIL("expected_output opening fail");
int err = run("Test_files/input.txt","actual_output.txt",1);
if (err == -1){
CU_FAIL("method run failed");
fclose(file1);
return;
}
if (file2 == NULL){
CU_FAIL("actual_output opening fail");
int n = 0;
while (fgets(chaine2,50,file2) != NULL)
if (CUE_SUCCESS != CU_initialize_registry())
{
return CU_get_error();
}
if (NULL == pSuite)
{
CU_cleanup_registry();
return CU_get_error();
if (NULL == CU_add_test(pSuite,"test_is_div",test_is_div) ||
NULL == CU_add_test(pSuite, "test_is_prime",test_is_prime) ||
NULL == CU_add_test(pSuite, "test_is_not_prime",test_is_not_prime) ||
NULL == CU_add_test(pSuite,"empty_file_test",empty_file_test) ||
NULL == CU_add_test(pSuite,"short_file_test",short_file_test) ||
NULL == CU_add_test(pSuite,"file_test : N = 4",file_test_N_4) ||
NULL == CU_add_test(pSuite,"file_test N = 1",file_test_N_1))
CU_basic_run_tests();
CU_automated_run_tests();
CU_basic_show_failures(CU_get_failure_list());
return EXIT_SUCCESS;
}