OLD | NEW |
1 // Copyright (c) 2004, Google Inc. | 1 // Copyright (c) 2004, Google Inc. |
2 // All rights reserved. | 2 // All rights reserved. |
3 // | 3 // |
4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
6 // met: | 6 // met: |
7 // | 7 // |
8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
(...skipping 15 matching lines...) Expand all Loading... |
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 // --- | 30 // --- |
31 // Author: Sanjay Ghemawat | 31 // Author: Sanjay Ghemawat |
32 // | 32 // |
33 // Test realloc() functionality | 33 // Test realloc() functionality |
34 | 34 |
35 #include "config_for_unittests.h" | 35 #include "config_for_unittests.h" |
| 36 #include <assert.h> // for assert |
36 #include <stdio.h> | 37 #include <stdio.h> |
37 #include <stdlib.h> | 38 #include <stddef.h> // for size_t, NULL |
38 #include <algorithm> // for min() | 39 #include <stdlib.h> // for free, malloc, realloc |
| 40 #include <algorithm> // for min |
39 #include "base/logging.h" | 41 #include "base/logging.h" |
40 | 42 |
41 using std::min; | 43 using std::min; |
42 | 44 |
| 45 |
43 // Fill a buffer of the specified size with a predetermined pattern | 46 // Fill a buffer of the specified size with a predetermined pattern |
44 static void Fill(unsigned char* buffer, int n) { | 47 static void Fill(unsigned char* buffer, int n) { |
45 for (int i = 0; i < n; i++) { | 48 for (int i = 0; i < n; i++) { |
46 buffer[i] = (i & 0xff); | 49 buffer[i] = (i & 0xff); |
47 } | 50 } |
48 } | 51 } |
49 | 52 |
50 // Check that the specified buffer has the predetermined pattern | 53 // Check that the specified buffer has the predetermined pattern |
51 // generated by Fill() | 54 // generated by Fill() |
52 static bool Valid(unsigned char* buffer, int n) { | 55 static bool Valid(unsigned char* buffer, int n) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 for (int i = 0; i < kNumEntries; i++) { | 115 for (int i = 0; i < kNumEntries; i++) { |
113 sum += p[i][1000]; | 116 sum += p[i][1000]; |
114 free(p[i]); | 117 free(p[i]); |
115 } | 118 } |
116 CHECK_EQ(kNumEntries/2 * (kNumEntries - 1), sum); // assume kNE is even | 119 CHECK_EQ(kNumEntries/2 * (kNumEntries - 1), sum); // assume kNE is even |
117 free(p); | 120 free(p); |
118 | 121 |
119 printf("PASS\n"); | 122 printf("PASS\n"); |
120 return 0; | 123 return 0; |
121 } | 124 } |
OLD | NEW |