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 package org.chromium.mojo; | 5 package org.chromium.mojo; |
6 | 6 |
7 import java.nio.ByteBuffer; | 7 import java.nio.ByteBuffer; |
| 8 import java.nio.ByteOrder; |
8 import java.util.Random; | 9 import java.util.Random; |
9 | 10 |
10 /** | 11 /** |
11 * Utilities methods for tests. | 12 * Utilities methods for tests. |
12 */ | 13 */ |
13 public final class TestUtils { | 14 public final class TestUtils { |
14 | 15 |
15 private static final Random RANDOM = new Random(); | 16 private static final Random RANDOM = new Random(); |
16 | 17 |
17 /** | 18 /** |
18 * Returns a new direct ByteBuffer of the given size with random (but reprod
ucible) data. | 19 * Returns a new direct ByteBuffer of the given size with random (but reprod
ucible) data. |
19 */ | 20 */ |
20 public static ByteBuffer newRandomBuffer(int size) { | 21 public static ByteBuffer newRandomBuffer(int size) { |
21 byte bytes[] = new byte[size]; | 22 byte bytes[] = new byte[size]; |
22 RANDOM.setSeed(size); | 23 RANDOM.setSeed(size); |
23 RANDOM.nextBytes(bytes); | 24 RANDOM.nextBytes(bytes); |
24 ByteBuffer data = ByteBuffer.allocateDirect(size); | 25 ByteBuffer data = ByteBuffer.allocateDirect(size); |
| 26 data.order(ByteOrder.nativeOrder()); |
25 data.put(bytes); | 27 data.put(bytes); |
26 data.flip(); | 28 data.flip(); |
27 return data; | 29 return data; |
28 } | 30 } |
29 | 31 |
30 } | 32 } |
OLD | NEW |