Skip to content

Commit

Permalink
Add proc-macro test fixture with simple function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jplatte committed Jun 1, 2022
1 parent bb784e7 commit 3b6c2cf
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ members = [
"fixtures/regressions/cdylib-crate-type-dependency/cdylib-dependency",
"fixtures/uitests",
"fixtures/uniffi-fixture-time",
"fixtures/simple-fns",
"fixtures/swift-omit-labels",
]

Expand Down
22 changes: 22 additions & 0 deletions fixtures/simple-fns/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "uniffi-fixture-simple-fns"
version = "0.17.0"
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
edition = "2018"
license = "MPL-2.0"
publish = false

[lib]
name = "uniffi_simple_fns"
crate-type = ["cdylib"]

[dependencies]
uniffi = { path = "../../uniffi", features = ["builtin-bindgen"] }
thiserror = "1.0"
lazy_static = "1.4"

[build-dependencies]
uniffi_build = { path = "../../uniffi_build", features = ["builtin-bindgen"] }

[dev-dependencies]
uniffi_macros = { path = "../../uniffi_macros" }
3 changes: 3 additions & 0 deletions fixtures/simple-fns/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# A basic test for uniffi components

This test covers basic free-standing functions.
7 changes: 7 additions & 0 deletions fixtures/simple-fns/build.rs
Original file line number Diff line number Diff line change
@@ -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_build::generate_scaffolding("./src/simple-fns.udl").unwrap();
}
25 changes: 25 additions & 0 deletions fixtures/simple-fns/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* 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/. */

#[uniffi::export]
fn get_string() -> String {
"String created by Rust".to_owned()
}

#[uniffi::export]
fn get_int() -> i32 {
1289
}

#[uniffi::export]
fn string_identity(s: String) -> String {
s
}

#[uniffi::export]
fn byte_to_u32(byte: u8) -> u32 {
byte.into()
}

include!(concat!(env!("OUT_DIR"), "/simple-fns.uniffi.rs"));
1 change: 1 addition & 0 deletions fixtures/simple-fns/src/simple-fns.udl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
namespace uniffi_simple_fns {};
10 changes: 10 additions & 0 deletions fixtures/simple-fns/tests/bindings/test_simple_fns.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* 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/. */

import uniffi.fixture.simple_fns.*;

assert(getString() == "String created by Rust")
assert(getInt() == 1289)
assert(stringIdentity("String created by Kotlin") == "String created by Kotlin")
assert(byteToU32(255U) == 255U)
10 changes: 10 additions & 0 deletions fixtures/simple-fns/tests/bindings/test_simple_fns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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/.

from uniffi_simple_fns import *

assert get_string() == "String created by Rust"
assert get_int() == 1289
assert string_identity("String created by Python") == "String created by Python"
assert byte_to_u32(255) == 255
10 changes: 10 additions & 0 deletions fixtures/simple-fns/tests/bindings/test_simple_fns.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* 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/. */

import uniffi_simple_fns

assert(getString() == "String created by Rust")
assert(getInt() == 1289)
assert(stringIdentity(s: "String created by Kotlin") == "String created by Kotlin")
assert(byteToU32(byte: 255) == 255)
8 changes: 8 additions & 0 deletions fixtures/simple-fns/tests/test_generated_bindings.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
uniffi_macros::build_foreign_language_testcases!(
["src/simple-fns.udl"],
[
"tests/bindings/test_simple_fns.kts",
"tests/bindings/test_simple_fns.swift",
"tests/bindings/test_simple_fns.py",
]
);
9 changes: 9 additions & 0 deletions fixtures/simple-fns/uniffi.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[bindings.kotlin]
package_name = "uniffi.fixture.simple_fns"
cdylib_name = "uniffi_simple_fns"

[bindings.python]
cdylib_name = "uniffi_simple_fns"

[bindings.swift]
cdylib_name = "uniffi_simple_fns"

0 comments on commit 3b6c2cf

Please sign in to comment.