GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / tools / misc / xz / tests / create_compress_files.c
blob44367d8f18eca5fd28cf18fdd2df9b9938a2a6fc
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 /// \file create_compress_files.c
4 /// \brief Creates bunch of test files to be compressed
5 ///
6 /// Using a test file generator program saves space in the source code
7 /// package considerably.
8 //
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 ///////////////////////////////////////////////////////////////////////////////
16 #include "sysdefs.h"
17 #include <stdio.h>
20 // Avoid re-creating the test files every time the tests are run.
21 #define create_test(name) \
22 do { \
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); \
27 } \
28 } while (0)
31 static bool
32 file_exists(const char *filename)
34 // Trying to be somewhat portable by avoiding stat().
35 FILE *file = fopen(filename, "rb");
36 bool ret;
38 if (file != NULL) {
39 fclose(file);
40 ret = true;
41 } else {
42 ret = false;
45 return ret;
49 static FILE *
50 file_create(const char *filename)
52 FILE *file = fopen(filename, "wb");
54 if (file == NULL) {
55 perror(filename);
56 exit(1);
59 return file;
63 static void
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) {
70 perror(filename);
71 exit(1);
76 // File that repeats "abc\n" a few thousand times. This is targeted
77 // especially at Subblock filter's run-length encoder.
78 static void
79 write_abc(FILE *file)
81 for (size_t i = 0; i < 12345; ++i)
82 fwrite("abc\n", 4, 1, file);
86 // File that doesn't compress. We always use the same random seed to
87 // generate identical files on all systems.
88 static void
89 write_random(FILE *file)
91 uint32_t n = 5;
93 for (size_t i = 0; i < 123456; ++i) {
94 n = 101771 * n + 71777;
96 putc(n & 0xFF, file);
97 putc((n >> 8) & 0xFF, file);
98 putc((n >> 16) & 0xFF, file);
99 putc(n >> 24, file);
104 // Text file
105 static void
106 write_text(FILE *file)
108 static const char *lorem[] = {
109 "Lorem", "ipsum", "dolor", "sit", "amet,", "consectetur",
110 "adipisicing", "elit,", "sed", "do", "eiusmod", "tempor",
111 "incididunt", "ut", "labore", "et", "dolore", "magna",
112 "aliqua.", "Ut", "enim", "ad", "minim", "veniam,", "quis",
113 "nostrud", "exercitation", "ullamco", "laboris", "nisi",
114 "ut", "aliquip", "ex", "ea", "commodo", "consequat.",
115 "Duis", "aute", "irure", "dolor", "in", "reprehenderit",
116 "in", "voluptate", "velit", "esse", "cillum", "dolore",
117 "eu", "fugiat", "nulla", "pariatur.", "Excepteur", "sint",
118 "occaecat", "cupidatat", "non", "proident,", "sunt", "in",
119 "culpa", "qui", "officia", "deserunt", "mollit", "anim",
120 "id", "est", "laborum."
123 // Let the first paragraph be the original text.
124 for (size_t w = 0; w < ARRAY_SIZE(lorem); ++w) {
125 fprintf(file, "%s ", lorem[w]);
127 if (w % 7 == 6)
128 fprintf(file, "\n");
131 // The rest shall be (hopefully) meaningless combinations of
132 // the same words.
133 uint32_t n = 29;
135 for (size_t p = 0; p < 500; ++p) {
136 fprintf(file, "\n\n");
138 for (size_t w = 0; w < ARRAY_SIZE(lorem); ++w) {
139 n = 101771 * n + 71777;
141 fprintf(file, "%s ", lorem[n % ARRAY_SIZE(lorem)]);
143 if (w % 7 == 6)
144 fprintf(file, "\n");
151 main(void)
153 create_test(abc);
154 create_test(random);
155 create_test(text);
156 return 0;