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