This source file includes following definitions.
- byte_at
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21 #include <scratch_buffer.h>
22
23 #include <string.h>
24 #include "macros.h"
25
26 static int
27 byte_at (unsigned long long int i)
28 {
29 return ((i % 13) + ((i * i) % 251)) & 0xff;
30 }
31
32 int
33 main ()
34 {
35
36 {
37 size_t sizes[] = { 100, 1000, 10000, 100000 };
38 size_t s;
39 for (s = 0; s < SIZEOF (sizes); s++)
40 {
41 size_t size = sizes[s];
42 struct scratch_buffer buf;
43 bool ok;
44 size_t i;
45
46 scratch_buffer_init (&buf);
47
48 ok = scratch_buffer_set_array_size (&buf, size, 1);
49 ASSERT (ok);
50
51 for (i = 0; i < size; i++)
52 ((unsigned char *) buf.data)[i] = byte_at (i);
53
54 memset (buf.data, 'x', buf.length);
55 memset (buf.data, 'y', size);
56
57 scratch_buffer_free (&buf);
58 }
59 }
60
61
62 {
63 size_t sizes[] = { 100, 1000, 10000, 100000 };
64 size_t s;
65 for (s = 0; s < SIZEOF (sizes); s++)
66 {
67 size_t size = sizes[s];
68 struct scratch_buffer buf;
69 bool ok;
70 size_t i;
71
72 scratch_buffer_init (&buf);
73
74 while (buf.length < size)
75 {
76 ok = scratch_buffer_grow (&buf);
77 ASSERT (ok);
78 }
79
80 for (i = 0; i < size; i++)
81 ((unsigned char *) buf.data)[i] = byte_at (i);
82
83 memset (buf.data, 'x', buf.length);
84 memset (buf.data, 'y', size);
85
86 scratch_buffer_free (&buf);
87 }
88 }
89
90
91 {
92 size_t sizes[] = { 100, 1000, 10000, 100000 };
93 struct scratch_buffer buf;
94 size_t s;
95 size_t size;
96 bool ok;
97 size_t i;
98
99 scratch_buffer_init (&buf);
100
101 s = 0;
102 size = sizes[s];
103 ok = scratch_buffer_set_array_size (&buf, size, 1);
104 ASSERT (ok);
105
106 for (i = 0; i < size; i++)
107 ((unsigned char *) buf.data)[i] = byte_at (i);
108
109 for (; s < SIZEOF (sizes); s++)
110 {
111 size_t oldsize = size;
112 size = sizes[s];
113
114 while (buf.length < size)
115 {
116 ok = scratch_buffer_grow_preserve (&buf);
117 ASSERT (ok);
118 }
119
120 for (i = 0; i < oldsize; i++)
121 ASSERT(((unsigned char *) buf.data)[i] == byte_at (i));
122 for (i = oldsize; i < size; i++)
123 ((unsigned char *) buf.data)[i] = byte_at (i);
124 }
125
126 scratch_buffer_free (&buf);
127 }
128
129 return 0;
130 }