Bug 1161339 - Add gtest calling rust code. r=cajbir
authorRalph Giles <giles@mozilla.com>
Thu, 07 May 2015 12:15:00 -0700
changeset 243084 083d678bb7fd7a4a057eb74ee86d1824188b7700
parent 243083 ea593c621ffe1ce2c4cc16bf91a33bc8ab9027fa
child 243085 e7cb51e17cc081e4e056e70f560bcd19046bad11
push id59592
push userrgiles@mozilla.com
push dateSat, 09 May 2015 04:41:02 +0000
treeherdermozilla-inbound@083d678bb7fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscajbir
bugs1161339
milestone40.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1161339 - Add gtest calling rust code. r=cajbir This is mostly to verify compilation and linkage. The test itself just verifies the contents of an returned string.
dom/media/gtest/TestRust.cpp
dom/media/gtest/hello.rs
dom/media/gtest/moz.build
new file mode 100644
--- /dev/null
+++ b/dom/media/gtest/TestRust.cpp
@@ -0,0 +1,8 @@
+#include <stdint.h>
+
+extern "C" uint8_t* test_rust();
+
+TEST(rust, CallFromCpp) {
+  auto greeting = test_rust();
+  EXPECT_STREQ(reinterpret_cast<char*>(greeting), "hello from rust.");
+}
new file mode 100644
--- /dev/null
+++ b/dom/media/gtest/hello.rs
@@ -0,0 +1,6 @@
+#[no_mangle]
+pub extern fn test_rust() -> *const u8 {
+    // NB: rust &str aren't null terminated.
+    let greeting = "hello from rust.\0";
+    greeting.as_ptr()
+}
--- a/dom/media/gtest/moz.build
+++ b/dom/media/gtest/moz.build
@@ -24,16 +24,21 @@ if CONFIG['MOZ_EME']:
 
 if CONFIG['MOZ_WEBM_ENCODER']:
     UNIFIED_SOURCES += [
         'TestVideoTrackEncoder.cpp',
         'TestVorbisTrackEncoder.cpp',
         'TestWebMWriter.cpp',
     ]
 
+if CONFIG['MOZ_RUST']:
+    SOURCES += ['hello.rs',]
+    UNIFIED_SOURCES += ['TestRust.cpp',]
+
+
 TEST_HARNESS_FILES.gtest += [
     '../test/gizmo-frag.mp4',
     '../test/gizmo.mp4',
     'dash_dashinit.mp4',
     'mediasource_test.mp4',
     'test.webm',
 ]