summaryrefslogtreecommitdiffstats
path: root/intl/l10n/rust/gtest
diff options
context:
space:
mode:
Diffstat (limited to 'intl/l10n/rust/gtest')
-rw-r--r--intl/l10n/rust/gtest/Cargo.toml14
-rw-r--r--intl/l10n/rust/gtest/Test.cpp23
-rw-r--r--intl/l10n/rust/gtest/moz.build11
-rw-r--r--intl/l10n/rust/gtest/test.rs58
4 files changed, 106 insertions, 0 deletions
diff --git a/intl/l10n/rust/gtest/Cargo.toml b/intl/l10n/rust/gtest/Cargo.toml
new file mode 100644
index 0000000000..ebc532f599
--- /dev/null
+++ b/intl/l10n/rust/gtest/Cargo.toml
@@ -0,0 +1,14 @@
+[package]
+name = "l10nregistry-ffi-gtest"
+version = "0.1.0"
+authors = ["The Mozilla Project Developers"]
+license = "MPL-2.0"
+description = "Tests for rust bindings to l10nRegistry"
+edition = "2018"
+
+[dependencies]
+l10nregistry-ffi = { path = "../l10nregistry-ffi" }
+moz_task = { path = "../../../../xpcom/rust/moz_task" }
+
+[lib]
+path = "test.rs"
diff --git a/intl/l10n/rust/gtest/Test.cpp b/intl/l10n/rust/gtest/Test.cpp
new file mode 100644
index 0000000000..98e7a8b5c6
--- /dev/null
+++ b/intl/l10n/rust/gtest/Test.cpp
@@ -0,0 +1,23 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "gtest/gtest.h"
+
+extern "C" void Rust_L10NLoadAsync(bool* aItWorked);
+
+TEST(RustL10N, LoadAsync)
+{
+ bool itWorked = false;
+ Rust_L10NLoadAsync(&itWorked);
+ EXPECT_TRUE(itWorked);
+}
+
+extern "C" void Rust_L10NLoadSync(bool* aItWorked);
+
+TEST(RustL10N, LoadSync)
+{
+ bool itWorked = false;
+ Rust_L10NLoadSync(&itWorked);
+ EXPECT_TRUE(itWorked);
+}
diff --git a/intl/l10n/rust/gtest/moz.build b/intl/l10n/rust/gtest/moz.build
new file mode 100644
index 0000000000..7c73e04fc8
--- /dev/null
+++ b/intl/l10n/rust/gtest/moz.build
@@ -0,0 +1,11 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+UNIFIED_SOURCES += [
+ "Test.cpp",
+]
+
+FINAL_LIBRARY = "xul-gtest"
diff --git a/intl/l10n/rust/gtest/test.rs b/intl/l10n/rust/gtest/test.rs
new file mode 100644
index 0000000000..3e993f4789
--- /dev/null
+++ b/intl/l10n/rust/gtest/test.rs
@@ -0,0 +1,58 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+use l10nregistry_ffi::load::{load_async, load_sync};
+use moz_task;
+use std::borrow::Borrow;
+
+// We want to test a file that ships in every platform configuration, so we take
+// something from `toolkit/`. But we don't want to depend on the specifics of
+// the text, or the packaging of that text, since those can change. It would be
+// best to register an untranslated `.ftl` for this test, but that's difficult.
+// Second best is to ship an untranslated `.ftl`, but that is not well-supported
+// by existing processes either. So we settle for depending on the form of
+// specific identifiers, whose names will appear in future searches, while
+// depending on the specific messages or the file packaging.
+fn assert_about_about_correct<T: Borrow<[u8]>> (res: T) {
+ assert!(res.borrow().len() > 0);
+
+ // `windows` is a convenient, if inefficient, way to look for a subslice.
+ let needle = b"about-about-title";
+ assert!(res.borrow().windows(needle.len()).position(|window| window == needle).is_some());
+
+ let needle = b"about-about-note";
+ assert!(res.borrow().windows(needle.len()).position(|window| window == needle).is_some());
+}
+
+#[no_mangle]
+pub extern "C" fn Rust_L10NLoadAsync(it_worked: *mut bool) {
+ let future = async move {
+ match load_async("resource://gre/localization/en-US/toolkit/about/aboutAbout.ftl").await {
+ Ok(res) => {
+ assert_about_about_correct(res);
+ unsafe {
+ *it_worked = true;
+ }
+ }
+ Err(err) => panic!("{:?}", err),
+ }
+ };
+
+ unsafe {
+ moz_task::gtest_only::spin_event_loop_until("Rust_L10NLoadAsync", future).unwrap();
+ }
+}
+
+#[no_mangle]
+pub extern "C" fn Rust_L10NLoadSync(it_worked: *mut bool) {
+ match load_sync("resource://gre/localization/en-US/toolkit/about/aboutAbout.ftl") {
+ Ok(res) => {
+ assert_about_about_correct(res);
+ unsafe {
+ *it_worked = true;
+ }
+ }
+ Err(err) => panic!("{:?}", err),
+ }
+}