CUnit testing void functions

74 Views Asked by At

Hi Im new to Cunit tests and testing in general. I cant find a way to test this void functon. Wondering how to properly do it or how to refactor it. Any tips on how to properly test void functions? Thanks.

void validate_arg(int argc, char *argv[], struct Statistics *stats) {
   if (argc == 4 && strcmp(argv[2], "-G") == 0) {
      FILE *file = fopen(argv[3], "w");
      stop_prog(write_stats(file, stats), err1);
      fclose(file);
   }
   free(stats);
}

The Cunit test I wrote but I cant assert anything since its a void and I cant test if my file to write was created since since it gets deallocated inside the if.

void test_validate_args_0(void) {
   struct Stats *stats = malloc(sizeof(struct Stats));  
   char* argv[] = {"TEST", "dummy", "-G", NULL};
   CU_ASSERT_EQUAL(validate_arg(4, argv, stats), 0);  
   free(stats);  
}  
0

There are 0 best solutions below