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 // Copyright (C) 2008 Lasse Collin
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
21 ///////////////////////////////////////////////////////////////////////////////
27 // Avoid re-creating the test files every time the tests are run.
28 #define create_test(name) \
30 if (!file_exists("compress_generated_" #name)) { \
31 FILE *file = file_create("compress_generated_" #name); \
32 write_ ## name(file); \
33 file_finish(file, "compress_generated_" #name); \
39 file_exists(const char *filename
)
41 // Trying to be somewhat portable by avoiding stat().
42 FILE *file
= fopen(filename
, "rb");
57 file_create(const char *filename
)
59 FILE *file
= fopen(filename
, "wb");
71 file_finish(FILE *file
, const char *filename
)
73 const bool ferror_fail
= ferror(file
);
74 const bool fclose_fail
= fclose(file
);
76 if (ferror_fail
|| fclose_fail
) {
83 // File that repeats "abc\n" a few thousand times. This is targeted
84 // especially at Subblock filter's run-length encoder.
88 for (size_t i
= 0; i
< 12345; ++i
)
89 fwrite("abc\n", 4, 1, file
);
93 // File that doesn't compress. We always use the same random seed to
94 // generate identical files on all systems.
96 write_random(FILE *file
)
100 for (size_t i
= 0; i
< 123456; ++i
) {
101 n
= 101771 * n
+ 71777;
103 putc(n
& 0xFF, file
);
104 putc((n
>> 8) & 0xFF, file
);
105 putc((n
>> 16) & 0xFF, file
);
113 write_text(FILE *file
)
115 static const char *lorem
[] = {
116 "Lorem", "ipsum", "dolor", "sit", "amet,", "consectetur",
117 "adipisicing", "elit,", "sed", "do", "eiusmod", "tempor",
118 "incididunt", "ut", "labore", "et", "dolore", "magna",
119 "aliqua.", "Ut", "enim", "ad", "minim", "veniam,", "quis",
120 "nostrud", "exercitation", "ullamco", "laboris", "nisi",
121 "ut", "aliquip", "ex", "ea", "commodo", "consequat.",
122 "Duis", "aute", "irure", "dolor", "in", "reprehenderit",
123 "in", "voluptate", "velit", "esse", "cillum", "dolore",
124 "eu", "fugiat", "nulla", "pariatur.", "Excepteur", "sint",
125 "occaecat", "cupidatat", "non", "proident,", "sunt", "in",
126 "culpa", "qui", "officia", "deserunt", "mollit", "anim",
127 "id", "est", "laborum."
130 // Let the first paragraph be the original text.
131 for (size_t w
= 0; w
< ARRAY_SIZE(lorem
); ++w
) {
132 fprintf(file
, "%s ", lorem
[w
]);
138 // The rest shall be (hopefully) meaningless combinations of
142 for (size_t p
= 0; p
< 500; ++p
) {
143 fprintf(file
, "\n\n");
145 for (size_t w
= 0; w
< ARRAY_SIZE(lorem
); ++w
) {
146 n
= 101771 * n
+ 71777;
148 fprintf(file
, "%s ", lorem
[n
% ARRAY_SIZE(lorem
)]);