From 4f78f0114ff36d8ff363645079b6dc6d040a941c Mon Sep 17 00:00:00 2001 From: Aivaras Saulius Date: Wed, 24 Jul 2024 08:37:56 +0300 Subject: [PATCH] Add null to empty string configuration test Signed-off-by: Aivaras Saulius --- Cargo.lock | 11 +++++++++++ .../TestNullToEmptyString.cs | 17 +++++++++++++++++ fixtures/Cargo.toml | 1 + fixtures/null-to-empty-string/Cargo.toml | 18 ++++++++++++++++++ fixtures/null-to-empty-string/build.rs | 7 +++++++ fixtures/null-to-empty-string/src/lib.rs | 9 +++++++++ .../src/null_to_empty_string.udl | 7 +++++++ fixtures/null-to-empty-string/uniffi.toml | 4 ++++ fixtures/src/lib.rs | 1 + 9 files changed, 75 insertions(+) create mode 100644 dotnet-tests/UniffiCS.BindingTests/TestNullToEmptyString.cs create mode 100644 fixtures/null-to-empty-string/Cargo.toml create mode 100644 fixtures/null-to-empty-string/build.rs create mode 100644 fixtures/null-to-empty-string/src/lib.rs create mode 100644 fixtures/null-to-empty-string/src/null_to_empty_string.udl create mode 100644 fixtures/null-to-empty-string/uniffi.toml diff --git a/Cargo.lock b/Cargo.lock index 4c8e079..9ef76c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -635,6 +635,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "null-to-empty-string" +version = "1.0.0" +dependencies = [ + "once_cell", + "thiserror", + "uniffi", + "uniffi_macros", +] + [[package]] name = "num-integer" version = "0.1.45" @@ -1189,6 +1199,7 @@ name = "uniffi-bindgen-cs-fixtures" version = "0.1.0" dependencies = [ "global-methods-class-name", + "null-to-empty-string", "uniffi-cs-custom-types-builtin", "uniffi-cs-disposable-fixture", "uniffi-cs-optional-parameters-fixture", diff --git a/dotnet-tests/UniffiCS.BindingTests/TestNullToEmptyString.cs b/dotnet-tests/UniffiCS.BindingTests/TestNullToEmptyString.cs new file mode 100644 index 0000000..e62a69d --- /dev/null +++ b/dotnet-tests/UniffiCS.BindingTests/TestNullToEmptyString.cs @@ -0,0 +1,17 @@ +// 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/. + +using uniffi.null_to_empty_string; + +namespace UniffiCS.BindingTests; + +public class TestNullToEmptyString +{ + [Fact] + public void NullToEmptyStringWorks() + { + Assert.Equal("hello", LibGreeter.HelloWorld("hello")); + Assert.Equal("", LibGreeter.HelloWorld(null)); + } +} diff --git a/fixtures/Cargo.toml b/fixtures/Cargo.toml index 94c9635..3f105f3 100644 --- a/fixtures/Cargo.toml +++ b/fixtures/Cargo.toml @@ -10,6 +10,7 @@ crate-type = ["cdylib", "lib"] [dependencies] global-methods-class-name = { path = "global-methods-class-name" } +null-to-empty-string = { path = "null-to-empty-string" } uniffi-cs-custom-types-builtin = { path = "custom-types-builtin" } uniffi-cs-disposable-fixture = { path = "disposable" } uniffi-cs-optional-parameters-fixture = { path = "optional-parameters" } diff --git a/fixtures/null-to-empty-string/Cargo.toml b/fixtures/null-to-empty-string/Cargo.toml new file mode 100644 index 0000000..9bd0002 --- /dev/null +++ b/fixtures/null-to-empty-string/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "null-to-empty-string" +version = "1.0.0" +edition = "2021" +publish = false + +[lib] +crate-type = ["lib", "cdylib"] +name = "null_to_empty_string" + +[dependencies] +once_cell = "1.12" +thiserror = "1.0" +uniffi = {path = "../../3rd-party/uniffi-rs/uniffi", features=["build"]} +uniffi_macros = {path = "../../3rd-party/uniffi-rs/uniffi_macros"} + +[build-dependencies] +uniffi = {path = "../../3rd-party/uniffi-rs/uniffi", features=["bindgen-tests"]} diff --git a/fixtures/null-to-empty-string/build.rs b/fixtures/null-to-empty-string/build.rs new file mode 100644 index 0000000..2c6d0a2 --- /dev/null +++ b/fixtures/null-to-empty-string/build.rs @@ -0,0 +1,7 @@ +/* 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/. */ + +fn main() { + uniffi::generate_scaffolding("./src/null_to_empty_string.udl").unwrap(); +} diff --git a/fixtures/null-to-empty-string/src/lib.rs b/fixtures/null-to-empty-string/src/lib.rs new file mode 100644 index 0000000..1d86eae --- /dev/null +++ b/fixtures/null-to-empty-string/src/lib.rs @@ -0,0 +1,9 @@ +/* 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/. */ + +pub fn hello_world(greet: String) -> String { + return greet; +} + +uniffi::include_scaffolding!("null_to_empty_string"); diff --git a/fixtures/null-to-empty-string/src/null_to_empty_string.udl b/fixtures/null-to-empty-string/src/null_to_empty_string.udl new file mode 100644 index 0000000..860ead1 --- /dev/null +++ b/fixtures/null-to-empty-string/src/null_to_empty_string.udl @@ -0,0 +1,7 @@ +/* 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/. */ + +namespace null_to_empty_string { + string hello_world(string greet); +}; diff --git a/fixtures/null-to-empty-string/uniffi.toml b/fixtures/null-to-empty-string/uniffi.toml new file mode 100644 index 0000000..1b08b90 --- /dev/null +++ b/fixtures/null-to-empty-string/uniffi.toml @@ -0,0 +1,4 @@ +[bindings.csharp] +cdylib_name = "uniffi_fixtures" +global_methods_class_name = "LibGreeter" +null_string_to_empty = true diff --git a/fixtures/src/lib.rs b/fixtures/src/lib.rs index 018f36e..f35f0ac 100644 --- a/fixtures/src/lib.rs +++ b/fixtures/src/lib.rs @@ -18,6 +18,7 @@ mod uniffi_fixtures { uniffi_trait_methods::uniffi_reexport_scaffolding!(); global_methods_class_name::uniffi_reexport_scaffolding!(); + null_to_empty_string::uniffi_reexport_scaffolding!(); uniffi_cs_custom_types_builtin::uniffi_reexport_scaffolding!(); uniffi_cs_disposable::uniffi_reexport_scaffolding!(); uniffi_cs_optional_parameters::uniffi_reexport_scaffolding!();