Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1204)

Unified Diff: mojo/android/javatests/src/org/chromium/mojo/bindings/ValidationTestUtil.java

Issue 508033004: mojo: Utility class to parse .data file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Follow review Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/android/javatests/src/org/chromium/mojo/bindings/ValidationTestUtil.java
diff --git a/mojo/android/javatests/src/org/chromium/mojo/bindings/ValidationTestUtil.java b/mojo/android/javatests/src/org/chromium/mojo/bindings/ValidationTestUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..7d78c19e93254f6d445b1386a3a933a8caad7f55
--- /dev/null
+++ b/mojo/android/javatests/src/org/chromium/mojo/bindings/ValidationTestUtil.java
@@ -0,0 +1,68 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.mojo.bindings;
+
+import org.chromium.base.CalledByNative;
+import org.chromium.base.JNINamespace;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+/**
+ * Utility class for testing message validation. The file format used to describe a message is
+ * described in The format is described in
+ * mojo/public/cpp/bindings/tests/validation_test_input_parser.h
+ */
+@JNINamespace("mojo::android")
+public class ValidationTestUtil {
+
+ /**
+ * Content of a '.data' file.
+ */
+ public static class Data {
+ private final ByteBuffer mData;
+ private final int mHandlesCount;
+ private final String mErrorMessage;
+
+ public ByteBuffer getData() {
+ return mData;
+ }
+
+ public int getHandlesCount() {
+ return mHandlesCount;
+ }
+
+ public String getErrorMessage() {
+ return mErrorMessage;
+ }
+
+ private Data(ByteBuffer data, int handlesCount, String errorMessage) {
+ this.mData = data;
+ this.mHandlesCount = handlesCount;
+ this.mErrorMessage = errorMessage;
+ }
+ }
+
+ /**
+ * Parse a '.data' file.
+ */
+ public static Data parseData(String dataAsString) {
+ return nativeParseData(dataAsString);
+ }
+
+ private static native Data nativeParseData(String dataAsString);
+
+ @CalledByNative
+ private static Data buildData(ByteBuffer data, int handlesCount, String errorMessage) {
+ ByteBuffer copiedData = null;
+ if (data != null) {
+ copiedData = ByteBuffer.allocateDirect(data.limit());
+ copiedData.order(ByteOrder.nativeOrder());
+ copiedData.put(data);
+ copiedData.flip();
+ }
+ return new Data(copiedData, handlesCount, errorMessage);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698