OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/system/memory.h" | 5 #include "mojo/system/memory.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <limits> | 10 #include <limits> |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // implementation. | 169 // implementation. |
170 | 170 |
171 // These tests depend on |int32_t| and |int64_t| having nontrivial alignment. | 171 // These tests depend on |int32_t| and |int64_t| having nontrivial alignment. |
172 MOJO_COMPILE_ASSERT(MOJO_ALIGNOF(int32_t) != 1, | 172 MOJO_COMPILE_ASSERT(MOJO_ALIGNOF(int32_t) != 1, |
173 int32_t_does_not_have_to_be_aligned); | 173 int32_t_does_not_have_to_be_aligned); |
174 MOJO_COMPILE_ASSERT(MOJO_ALIGNOF(int64_t) != 1, | 174 MOJO_COMPILE_ASSERT(MOJO_ALIGNOF(int64_t) != 1, |
175 int64_t_does_not_have_to_be_aligned); | 175 int64_t_does_not_have_to_be_aligned); |
176 | 176 |
177 // Null: | 177 // Null: |
178 { | 178 { |
179 UserPointer<char> ptr(NULL); | 179 UserPointer<char> ptr(nullptr); |
180 char array[5] = {}; | 180 char array[5] = {}; |
181 EXPECT_DEATH_IF_SUPPORTED(ptr.Check(), kMemoryCheckFailedRegex); | 181 EXPECT_DEATH_IF_SUPPORTED(ptr.Check(), kMemoryCheckFailedRegex); |
182 EXPECT_DEATH_IF_SUPPORTED(ptr.Get(), kMemoryCheckFailedRegex); | 182 EXPECT_DEATH_IF_SUPPORTED(ptr.Get(), kMemoryCheckFailedRegex); |
183 EXPECT_DEATH_IF_SUPPORTED(ptr.Put('x'), kMemoryCheckFailedRegex); | 183 EXPECT_DEATH_IF_SUPPORTED(ptr.Put('x'), kMemoryCheckFailedRegex); |
184 EXPECT_DEATH_IF_SUPPORTED(ptr.CheckArray(5), kMemoryCheckFailedRegex); | 184 EXPECT_DEATH_IF_SUPPORTED(ptr.CheckArray(5), kMemoryCheckFailedRegex); |
185 EXPECT_DEATH_IF_SUPPORTED(ptr.GetArray(array, 5), kMemoryCheckFailedRegex); | 185 EXPECT_DEATH_IF_SUPPORTED(ptr.GetArray(array, 5), kMemoryCheckFailedRegex); |
186 EXPECT_DEATH_IF_SUPPORTED(ptr.PutArray(array, 5), kMemoryCheckFailedRegex); | 186 EXPECT_DEATH_IF_SUPPORTED(ptr.PutArray(array, 5), kMemoryCheckFailedRegex); |
187 } | 187 } |
188 { | 188 { |
189 UserPointer<int32_t> ptr(NULL); | 189 UserPointer<int32_t> ptr(nullptr); |
190 int32_t array[5] = {}; | 190 int32_t array[5] = {}; |
191 EXPECT_DEATH_IF_SUPPORTED(ptr.Check(), kMemoryCheckFailedRegex); | 191 EXPECT_DEATH_IF_SUPPORTED(ptr.Check(), kMemoryCheckFailedRegex); |
192 EXPECT_DEATH_IF_SUPPORTED(ptr.Get(), kMemoryCheckFailedRegex); | 192 EXPECT_DEATH_IF_SUPPORTED(ptr.Get(), kMemoryCheckFailedRegex); |
193 EXPECT_DEATH_IF_SUPPORTED(ptr.Put(123), kMemoryCheckFailedRegex); | 193 EXPECT_DEATH_IF_SUPPORTED(ptr.Put(123), kMemoryCheckFailedRegex); |
194 EXPECT_DEATH_IF_SUPPORTED(ptr.CheckArray(5), kMemoryCheckFailedRegex); | 194 EXPECT_DEATH_IF_SUPPORTED(ptr.CheckArray(5), kMemoryCheckFailedRegex); |
195 EXPECT_DEATH_IF_SUPPORTED(ptr.GetArray(array, 5), kMemoryCheckFailedRegex); | 195 EXPECT_DEATH_IF_SUPPORTED(ptr.GetArray(array, 5), kMemoryCheckFailedRegex); |
196 EXPECT_DEATH_IF_SUPPORTED(ptr.PutArray(array, 5), kMemoryCheckFailedRegex); | 196 EXPECT_DEATH_IF_SUPPORTED(ptr.PutArray(array, 5), kMemoryCheckFailedRegex); |
197 } | 197 } |
198 { | 198 { |
199 UserPointer<int64_t> ptr(NULL); | 199 UserPointer<int64_t> ptr(nullptr); |
200 int64_t array[5] = {}; | 200 int64_t array[5] = {}; |
201 EXPECT_DEATH_IF_SUPPORTED(ptr.Check(), kMemoryCheckFailedRegex); | 201 EXPECT_DEATH_IF_SUPPORTED(ptr.Check(), kMemoryCheckFailedRegex); |
202 EXPECT_DEATH_IF_SUPPORTED(ptr.Get(), kMemoryCheckFailedRegex); | 202 EXPECT_DEATH_IF_SUPPORTED(ptr.Get(), kMemoryCheckFailedRegex); |
203 EXPECT_DEATH_IF_SUPPORTED(ptr.Put(123), kMemoryCheckFailedRegex); | 203 EXPECT_DEATH_IF_SUPPORTED(ptr.Put(123), kMemoryCheckFailedRegex); |
204 EXPECT_DEATH_IF_SUPPORTED(ptr.CheckArray(5), kMemoryCheckFailedRegex); | 204 EXPECT_DEATH_IF_SUPPORTED(ptr.CheckArray(5), kMemoryCheckFailedRegex); |
205 EXPECT_DEATH_IF_SUPPORTED(ptr.GetArray(array, 5), kMemoryCheckFailedRegex); | 205 EXPECT_DEATH_IF_SUPPORTED(ptr.GetArray(array, 5), kMemoryCheckFailedRegex); |
206 EXPECT_DEATH_IF_SUPPORTED(ptr.PutArray(array, 5), kMemoryCheckFailedRegex); | 206 EXPECT_DEATH_IF_SUPPORTED(ptr.PutArray(array, 5), kMemoryCheckFailedRegex); |
207 } | 207 } |
208 // Also check a const pointer: | 208 // Also check a const pointer: |
209 { | 209 { |
210 UserPointer<const int32_t> ptr(NULL); | 210 UserPointer<const int32_t> ptr(nullptr); |
211 int32_t array[5] = {}; | 211 int32_t array[5] = {}; |
212 EXPECT_DEATH_IF_SUPPORTED(ptr.Check(), kMemoryCheckFailedRegex); | 212 EXPECT_DEATH_IF_SUPPORTED(ptr.Check(), kMemoryCheckFailedRegex); |
213 EXPECT_DEATH_IF_SUPPORTED(ptr.Get(), kMemoryCheckFailedRegex); | 213 EXPECT_DEATH_IF_SUPPORTED(ptr.Get(), kMemoryCheckFailedRegex); |
214 EXPECT_DEATH_IF_SUPPORTED(ptr.CheckArray(5), kMemoryCheckFailedRegex); | 214 EXPECT_DEATH_IF_SUPPORTED(ptr.CheckArray(5), kMemoryCheckFailedRegex); |
215 EXPECT_DEATH_IF_SUPPORTED(ptr.GetArray(array, 5), kMemoryCheckFailedRegex); | 215 EXPECT_DEATH_IF_SUPPORTED(ptr.GetArray(array, 5), kMemoryCheckFailedRegex); |
216 } | 216 } |
217 | 217 |
218 // Unaligned: | 218 // Unaligned: |
219 { | 219 { |
220 int32_t x[10]; | 220 int32_t x[10]; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 EXPECT_DEATH_IF_SUPPORTED(ptr.GetArray(&x, kTooBig), | 285 EXPECT_DEATH_IF_SUPPORTED(ptr.GetArray(&x, kTooBig), |
286 kMemoryCheckFailedRegex); | 286 kMemoryCheckFailedRegex); |
287 } | 287 } |
288 | 288 |
289 // TODO(vtl): Tests for |UserPointer{Reader,Writer,ReaderWriter}|. | 289 // TODO(vtl): Tests for |UserPointer{Reader,Writer,ReaderWriter}|. |
290 } | 290 } |
291 | 291 |
292 } // namespace | 292 } // namespace |
293 } // namespace system | 293 } // namespace system |
294 } // namespace mojo | 294 } // namespace mojo |
OLD | NEW |