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

Unified Diff: mojo/android/javatests/validation_test_util.cc

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
« no previous file with comments | « mojo/android/javatests/validation_test_util.h ('k') | mojo/mojo_base.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/android/javatests/validation_test_util.cc
diff --git a/mojo/android/javatests/validation_test_util.cc b/mojo/android/javatests/validation_test_util.cc
new file mode 100644
index 0000000000000000000000000000000000000000..31aa3699b1f3cb7f79fe79e5fe63f4c8453b1616
--- /dev/null
+++ b/mojo/android/javatests/validation_test_util.cc
@@ -0,0 +1,42 @@
+// 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.
+
+#include "mojo/android/javatests/validation_test_util.h"
+
+#include "base/android/jni_android.h"
+#include "base/android/jni_string.h"
+#include "base/android/scoped_java_ref.h"
+#include "base/test/test_support_android.h"
+#include "jni/ValidationTestUtil_jni.h"
+#include "mojo/public/cpp/bindings/tests/validation_test_input_parser.h"
+
+namespace mojo {
+namespace android {
+
+bool RegisterValidationTestUtil(JNIEnv* env) {
+ return RegisterNativesImpl(env);
+}
+
+jobject ParseData(JNIEnv* env, jclass jcaller, jstring data_as_string) {
+ std::string input =
+ base::android::ConvertJavaStringToUTF8(env, data_as_string);
+ std::vector<uint8_t> data;
+ size_t num_handles;
+ std::string error_message;
+ if (!test::ParseValidationTestInput(
+ input, &data, &num_handles, &error_message)) {
+ ScopedJavaLocalRef<jstring> j_error_message =
+ base::android::ConvertUTF8ToJavaString(env, error_message);
+ return Java_ValidationTestUtil_buildData(
+ env, NULL, 0, j_error_message.obj()).Release();
+ }
+
+ jobject byte_buffer =
+ env->NewDirectByteBuffer(&data[0], data.size());
+ return Java_ValidationTestUtil_buildData(env, byte_buffer, num_handles, NULL)
+ .Release();
+}
+
+} // namespace android
+} // namespace mojo
« no previous file with comments | « mojo/android/javatests/validation_test_util.h ('k') | mojo/mojo_base.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698