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.
5 package org.chromium.mojo.bindings;
7 import org.chromium.base.CalledByNative;
8 import org.chromium.base.JNINamespace;
10 import java.nio.ByteBuffer;
11 import java.nio.ByteOrder;
14 * Utility class for testing message validation. The file format used to describe a message is
15 * described in The format is described in
16 * mojo/public/cpp/bindings/tests/validation_test_input_parser.h
18 @JNINamespace("mojo::android")
19 public class ValidationTestUtil {
22 * Content of a '.data' file.
24 public static class Data {
25 private final ByteBuffer mData;
26 private final int mHandlesCount;
27 private final String mErrorMessage;
29 public ByteBuffer getData() {
33 public int getHandlesCount() {
37 public String getErrorMessage() {
41 private Data(ByteBuffer data, int handlesCount, String errorMessage) {
43 this.mHandlesCount = handlesCount;
44 this.mErrorMessage = errorMessage;
49 * Parse a '.data' file.
51 public static Data parseData(String dataAsString) {
52 return nativeParseData(dataAsString);
55 private static native Data nativeParseData(String dataAsString);
58 private static Data buildData(ByteBuffer data, int handlesCount, String errorMessage) {
59 ByteBuffer copiedData = null;
61 copiedData = ByteBuffer.allocateDirect(data.limit());
62 copiedData.order(ByteOrder.nativeOrder());
66 return new Data(copiedData, handlesCount, errorMessage);