13
13
#include < cstring>
14
14
#include < cstdlib>
15
15
#include < cstdio>
16
+ #include < cassert>
16
17
#include " export.h"
17
18
18
19
#include < chrono>
19
20
#include < iostream>
20
21
21
22
#include " common.h"
22
23
24
+ #if defined(__linux__)
25
+ #define LIBTEST_MAIN
26
+ #endif
27
+
23
28
#ifdef LIBTEST_MAIN // add LIBTEST #define to compile the test with static library
24
29
25
30
int main (int argc, char *argv[])
26
31
{
27
- const char presetInput[] = " sample.txt" ;
32
+ int bits = DEFAULT_MAX_BITS;
33
+ bool bits_set = false ;
34
+
35
+ char inputFile [PATH_MAX] = { 0 };
28
36
29
- const char *inputFile = presetInput ;
37
+ char compressedFile [PATH_MAX] = { 0 } ;
30
38
31
- char compressedFile [PATH_MAX], outputFile [PATH_MAX] ;
39
+ char outputFile [PATH_MAX] = { 0 } ;
32
40
33
- if (argc == 2 )
41
+ if (2 == argc)
42
+ {
43
+ strcpy_s (inputFile, PATH_MAX, argv[1 ]);
44
+ }
45
+ else if (3 == argc)
34
46
{
35
- inputFile = argv[1 ];
47
+ if (0 == strncmp (argv[1 ], " -b" , 2 ))
48
+ {
49
+ char *ptr = argv[1 ];
50
+ bits = atoi (ptr + 2 );
51
+
52
+ bits_set = true ;
53
+
54
+ strcpy_s (inputFile, PATH_MAX, argv[2 ]);
55
+ }
56
+ }
57
+
58
+ if (strlen (inputFile) == 0 || (bits < 9 || bits > SUPPORTED_MAX_BITS))
59
+ {
60
+ printf (" Usage: %s [-b{12-16}] fileToCompress\n " , argv[0 ]);
61
+ return EXIT_FAILURE;
36
62
}
37
63
38
64
printf (" Testing compression on: %s\n " , inputFile);
@@ -41,13 +67,20 @@ int main (int argc, char *argv[])
41
67
42
68
tmpnam_s (outputFile, sizeof (outputFile));
43
69
70
+ assert (strlen (compressedFile) > 0 && strlen (outputFile) > 0 );
71
+
44
72
std::chrono::high_resolution_clock::time_point start;
45
73
46
74
start = std::chrono::high_resolution_clock::now ();
47
75
48
- int ret = Compress (inputFile, compressedFile, VERBOSE_OUTPUT);
76
+ int ret = 0 ;
77
+
78
+ if (!bits_set)
79
+ ret = Compress (inputFile, compressedFile, VERBOSE_OUTPUT);
80
+ else
81
+ ret = Compress2 (inputFile, compressedFile, VERBOSE_OUTPUT, bits);
49
82
50
- printf (" Compression : %s.\n " , ret ? " Successful " : " Failed " );
83
+ printf (" Compression %s.\n " , ret ? " successful " : " failed " );
51
84
52
85
if (!ret)
53
86
return EXIT_FAILURE;
@@ -61,7 +94,7 @@ int main (int argc, char *argv[])
61
94
62
95
ret = Decompress (compressedFile, outputFile, VERBOSE_OUTPUT);
63
96
64
- printf (" Decompression : %s.\n " , ret ? " Successful " : " Failed " );
97
+ printf (" Decompression %s.\n " , ret ? " successful " : " failed " );
65
98
66
99
if (!ret)
67
100
return EXIT_FAILURE;
0 commit comments