-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
33 lines (30 loc) · 795 Bytes
/
test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <stdio.h>
#include <assert.h>
#include <string.h>
// Declare the function from the other file
extern void compressFile(FILE *fp);
void test_compressFile() {
// Create a temporary file
FILE *temp = tmpfile();
// Write some data to the file
fputs("AAAABBB", temp);
// Rewind the file to the beginning
rewind(temp);
// Redirect stdout to a buffer
char buffer[256];
freopen("/dev/null", "a", stdout);
setbuf(stdout, buffer);
// Call the function to test
compressFile(temp);
// Restore stdout
freopen("/dev/tty", "a", stdout);
// Check the result
assert(strcmp(buffer, "4A3B") == 0);
// Close the temporary file
fclose(temp);
}
int main() {
test_compressFile();
printf("All tests passed.\n");
return 0;
}