in reply to Re: CPAN automated tests for IPC
in thread CPAN automated tests for IPC
The C code is interactive, so my mock test should "interact" with the program, giving commands to it and expecting output. Again, I'm not sure if using another Perl script would have any issue (only thing that comes to my mind is that I need print buffering).
Here is the C code anyway:
#include <stdio.h> #include <stdlib.h> #include <string.h> #define COMP_SIZE 265 #define COMP_TYPES_SIZE 428 int main() { FILE *input_file; char comp_file[13] = "list_comp.txt"; char comp_types_file[19] = "list_comp_types.txt"; char command[30]; while(1) { printf("srvrmgr> "); fgets(command, sizeof(command), stdin); /*removes new line*/ command[ strlen(command) - 1] = '\0'; switch(strlen(command)) { /*list comp*/ case 9 : { char comp_line[COMP_SIZE]; input_file = fopen(comp_file, "r"); if (input_file == NULL) { printf("Error reading %s\n", comp_file); perror(comp_file); exit(1); } while(fgets(comp_line, COMP_SIZE, input_file)) { printf("%s", comp_line); } fclose(input_file); break; } /*list comp types*/ case 15 : { char comp_types_line[COMP_TYPES_SIZE]; input_file = fopen(comp_types_file, "r"); if (input_file == NULL) { printf("Error reading %s\n", comp_types_file); perror(comp_types_file); exit(1); } while(fgets(comp_types_line, COMP_TYPES_SIZE, input_fi +le)) { printf("%s", comp_types_line); } fclose(input_file); break; } /*exit*/ case 4 : { printf("Disconnecting...\n"); exit(0); } default : { printf("Invalid command\n"); break; } } /*end of switch...case*/ } /*end of while(1)*/ exit(0); }
I'm sure I could write something better in pure Perl, but I'm confident that it wouldn't compromisse the testing results.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: CPAN automated tests for IPC
by BrowserUk (Patriarch) on Mar 17, 2012 at 16:40 UTC | |
by glasswalk3r (Friar) on Mar 17, 2012 at 17:31 UTC |