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

Unified Diff: mojo/public/rust/tests/util/mod.rs

Issue 2213563002: Rust: Add encoder/decoder tests (Closed) Base URL: git@github.com:domokit/mojo.git@decoding
Patch Set: Propagate decoding/hashmap fix Created 4 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/public/rust/tests/util/mod.rs
diff --git a/mojo/public/rust/tests/util/mod.rs b/mojo/public/rust/tests/util/mod.rs
index 8464d5834789bef8062de85c5c9e5bfb0de98992..16fbaebba525946bc8e088c11584cd0f249715f2 100644
--- a/mojo/public/rust/tests/util/mod.rs
+++ b/mojo/public/rust/tests/util/mod.rs
@@ -4,6 +4,12 @@
//! This module contains useful functions and macros for testing.
+pub mod mojom_validation;
+
+use std::ffi::CString;
+use std::os::raw::c_char;
+use std::ptr;
+
/// This macro sets up tests by adding in Mojo embedder
/// initialization.
macro_rules! tests {
@@ -33,3 +39,41 @@ extern "C" {
pub fn InitializeMojoEmbedder();
}
+#[link(name = "validation_parser")]
+extern "C" {
+ #[allow(dead_code)]
+ fn ParseValidationTest(input: *const c_char,
+ num_handles: *mut usize,
+ data: *mut *mut u8,
+ data_len: *mut usize)
+ -> *mut c_char;
+}
+
+#[allow(dead_code)]
+pub fn parse_validation_test(input: &str) -> Result<(Vec<u8>, usize), String> {
+ let input_c = CString::new(input.to_string()).unwrap();
+ let mut num_handles: usize = 0;
+ let mut data: *mut u8 = ptr::null_mut();
+ let mut data_len: usize = 0;
+ let error = unsafe {
+ ParseValidationTest(input_c.as_ptr(),
+ &mut num_handles as *mut usize,
+ &mut data as *mut *mut u8,
+ &mut data_len as *mut usize)
+ };
+ if error == ptr::null_mut() {
+ if data == ptr::null_mut() {
+ // We assume we were just given an empty file
+ Ok((Vec::new(), 0))
+ } else {
+ let buffer = unsafe {
+ Vec::from_raw_parts(data, data_len, data_len)
+ };
+ Ok((buffer, num_handles))
+ }
+ } else {
+ Err(unsafe {
+ CString::from_raw(error)
+ }.into_string().expect("Could not convert error message to UTF-8!"))
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698