summaryrefslogtreecommitdiffstats
path: root/toolkit/components/glean/tests/gtest/test.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /toolkit/components/glean/tests/gtest/test.rs
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/glean/tests/gtest/test.rs')
-rw-r--r--toolkit/components/glean/tests/gtest/test.rs55
1 files changed, 55 insertions, 0 deletions
diff --git a/toolkit/components/glean/tests/gtest/test.rs b/toolkit/components/glean/tests/gtest/test.rs
new file mode 100644
index 0000000000..90ad67aebb
--- /dev/null
+++ b/toolkit/components/glean/tests/gtest/test.rs
@@ -0,0 +1,55 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+extern crate firefox_on_glean;
+use firefox_on_glean::metrics;
+
+extern crate nsstring;
+use nsstring::nsString;
+
+fn nonfatal_fail(msg: String) {
+ extern "C" {
+ fn GTest_FOG_ExpectFailure(message: *const ::std::os::raw::c_char);
+ }
+ unsafe {
+ let msg = ::std::ffi::CString::new(msg).unwrap();
+ GTest_FOG_ExpectFailure(msg.as_ptr());
+ }
+}
+
+/// This macro checks if the expression evaluates to true,
+/// and causes a non-fatal GTest test failure if it doesn't.
+macro_rules! expect {
+ ($x:expr) => {
+ match (&$x) {
+ true => {}
+ false => nonfatal_fail(format!(
+ "check failed: (`{}`) at {}:{}",
+ stringify!($x),
+ file!(),
+ line!()
+ )),
+ }
+ };
+}
+
+#[no_mangle]
+pub extern "C" fn Rust_TestRustInGTest() {
+ // Just a smoke test, we show here how tests might work that both
+ // a) Are in Rust, and
+ // b) Require Gecko
+ // This demonstration doesn't actually require Gecko. But we pretend it
+ // does so we remember how to do this rust-in-gtest pattern.
+ metrics::test_only::bad_code.add(12);
+ expect!(metrics::test_only::bad_code.test_get_value(None) == Some(12));
+}
+
+#[no_mangle]
+pub extern "C" fn Rust_TestJogfile() {
+ // Ensure that the generated jogfile in t/c/g/tests/pytest
+ // (which is installed nearby using TEST_HARNESS_FILES)
+ // can be consumed by JOG's inner workings
+ //
+ // If it can't, that's perhaps a sign that the inner workings need to be updated.
+ expect!(jog::jog_load_jogfile(&nsString::from("jogfile_output")));
+}