1 ///////////////////////////////////////////////////////////////////////////////
3 /// \file create_compress_files.c
4 /// \brief Creates bunch of test files to be compressed
6 /// Using a test file generator program saves space in the source code
7 /// package considerably.
9 // Author: Lasse Collin
11 // This file has been put into the public domain.
12 // You can do whatever you want with this file.
14 ///////////////////////////////////////////////////////////////////////////////
20 // Avoid re-creating the test files every time the tests are run.
21 #define create_test(name) \
23 if (!file_exists("compress_generated_" #name)) { \
24 FILE *file = file_create("compress_generated_" #name); \
25 write_ ## name(file); \
26 file_finish(file, "compress_generated_" #name); \
32 file_exists(const char *filename
)
34 // Trying to be somewhat portable by avoiding stat().
35 FILE *file
= fopen(filename
, "rb");
50 file_create(const char *filename
)
52 FILE *file
= fopen(filename
, "wb");
64 file_finish(FILE *file
, const char *filename
)
66 const bool ferror_fail
= ferror(file
);
67 const bool fclose_fail
= fclose(file
);
69 if (ferror_fail
|| fclose_fail
) {
76 // File that repeats "abc\n" a few thousand times. This is targeted
77 // especially at Subblock filter's run-length encoder.
81 for (size_t i
= 0; i
< 12345; ++i
)
82 if (fwrite("abc\n", 4, 1, file
) != 1)
87 // File that doesn't compress. We always use the same random seed to
88 // generate identical files on all systems.
90 write_random(FILE *file
)
94 for (size_t i
= 0; i
< 123456; ++i
) {
95 n
= 101771 * n
+ 71777;
98 putc((n
>> 8) & 0xFF, file
);
99 putc((n
>> 16) & 0xFF, file
);
107 write_text(FILE *file
)
109 static const char *lorem
[] = {
110 "Lorem", "ipsum", "dolor", "sit", "amet,", "consectetur",
111 "adipisicing", "elit,", "sed", "do", "eiusmod", "tempor",
112 "incididunt", "ut", "labore", "et", "dolore", "magna",
113 "aliqua.", "Ut", "enim", "ad", "minim", "veniam,", "quis",
114 "nostrud", "exercitation", "ullamco", "laboris", "nisi",
115 "ut", "aliquip", "ex", "ea", "commodo", "consequat.",
116 "Duis", "aute", "irure", "dolor", "in", "reprehenderit",
117 "in", "voluptate", "velit", "esse", "cillum", "dolore",
118 "eu", "fugiat", "nulla", "pariatur.", "Excepteur", "sint",
119 "occaecat", "cupidatat", "non", "proident,", "sunt", "in",
120 "culpa", "qui", "officia", "deserunt", "mollit", "anim",
121 "id", "est", "laborum."
124 // Let the first paragraph be the original text.
125 for (size_t w
= 0; w
< ARRAY_SIZE(lorem
); ++w
) {
126 fprintf(file
, "%s ", lorem
[w
]);
132 // The rest shall be (hopefully) meaningless combinations of
136 for (size_t p
= 0; p
< 500; ++p
) {
137 fprintf(file
, "\n\n");
139 for (size_t w
= 0; w
< ARRAY_SIZE(lorem
); ++w
) {
140 n
= 101771 * n
+ 71777;
142 fprintf(file
, "%s ", lorem
[n
% ARRAY_SIZE(lorem
)]);