Skip to content

Commit 3f78581

Browse files
committed
Add enum style test
Use the other enum style to verify that compilation is successful Signed-off-by: Martynas Gurskas <[email protected]>
1 parent 1bcbe76 commit 3f78581

File tree

12 files changed

+138
-0
lines changed

12 files changed

+138
-0
lines changed

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cpp-tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ test_case(coverall)
8686
test_case(uniffi_docstring)
8787
test_case(trait_methods)
8888
test_case(custom_types_builtin)
89+
test_case(enum_style_test)
8990

9091
scaffolding_test_case(arithmetic)
9192
scaffolding_test_case(callbacks)
@@ -99,6 +100,7 @@ scaffolding_test_case(todolist)
99100
scaffolding_test_case(traits)
100101
scaffolding_test_case(coverall)
101102
scaffolding_test_case(custom_types_builtin)
103+
scaffolding_test_case(enum_style_test)
102104

103105
add_library(uniffi_fixtures SHARED
104106
${SCAFFOLDING_LIB_FILES})
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <lib_enum_style_test.hpp>
2+
3+
enum_style_test::SimpleEnum enum_style_test::get_simple_enum() {
4+
return enum_style_test::SimpleEnum::VARIANT_ONE;
5+
}
6+
7+
void enum_style_test::set_simple_enum(enum_style_test::SimpleEnum) {
8+
}
9+
10+
enum_style_test::ComplexEnum enum_style_test::get_complex_enum() {
11+
return enum_style_test::ComplexEnum { enum_style_test::ComplexEnum::VARIANT_ONE { 1 } };
12+
}
13+
14+
void enum_style_test::set_complex_enum(enum_style_test::ComplexEnum) {
15+
}
16+
17+
18+
#include <enum_style_test_cpp_scaffolding.cpp>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <cstdint>
2+
#include <variant>
3+
4+
namespace {
5+
namespace enum_style_test {
6+
enum class SimpleEnum: int32_t {
7+
VARIANT_ONE = 1,
8+
VARIANT_TWO = 2,
9+
VARIANT_THREE = 3
10+
};
11+
12+
13+
class ComplexEnum {
14+
public:
15+
struct VARIANT_ONE { uint32_t num; };
16+
struct VARIANT_TWO { float flt; };
17+
18+
ComplexEnum(ComplexEnum::VARIANT_ONE variant) { this->variant = variant; }
19+
ComplexEnum(ComplexEnum::VARIANT_TWO variant) { this->variant = variant; }
20+
21+
std::variant<VARIANT_ONE, VARIANT_TWO> variant;
22+
};
23+
24+
SimpleEnum get_simple_enum();
25+
void set_simple_enum(SimpleEnum e);
26+
27+
ComplexEnum get_complex_enum();
28+
void set_complex_enum(ComplexEnum e);
29+
}
30+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include <test_common.hpp>
2+
3+
#include <enum_style_test.hpp>
4+
5+
int main() {
6+
auto simple = enum_style_test::get_simple_enum();
7+
enum_style_test::set_simple_enum(simple);
8+
9+
auto complex = enum_style_test::get_complex_enum();
10+
enum_style_test::set_complex_enum(complex);
11+
12+
return 0;
13+
}

fixtures/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ uniffi-fixture-docstring = { git = "https://github.com/NordSecurity/uniffi-rs.gi
2121
uniffi-fixture-time = { git = "https://github.com/NordSecurity/uniffi-rs.git", tag = "v0.3.1+v0.25.0" }
2222
uniffi-fixture-trait-methods = { git = "https://github.com/NordSecurity/uniffi-rs.git", tag = "v0.3.1+v0.25.0" }
2323
uniffi-custom-types-builtin = { path = "custom-types-builtin" }
24+
uniffi-enum-style-test = { path = "enum-style-test" }

fixtures/enum-style-test/Cargo.toml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "uniffi-enum-style-test"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
crate-type = ["lib", "cdylib"]
8+
name = "uniffi_enum_style_test"
9+
10+
[dependencies]
11+
uniffi = { workspace = true }
12+
13+
[build-dependencies]
14+
uniffi = { workspace = true, features = ["build"] }

fixtures/enum-style-test/build.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
uniffi::generate_scaffolding("src/enum_style_test.udl").unwrap();
3+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
enum SimpleEnum {
2+
"VariantOne",
3+
"VariantTwo",
4+
"VariantThree",
5+
};
6+
7+
[Enum]
8+
interface ComplexEnum {
9+
VariantOne(u32 num);
10+
VariantTwo(f32 flt);
11+
};
12+
13+
namespace enum_style_test {
14+
SimpleEnum get_simple_enum();
15+
void set_simple_enum(SimpleEnum e);
16+
17+
ComplexEnum get_complex_enum();
18+
void set_complex_enum(ComplexEnum e);
19+
};

fixtures/enum-style-test/src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
enum SimpleEnum {
2+
VariantOne,
3+
VariantTwo,
4+
VariantThree,
5+
}
6+
7+
enum ComplexEnum {
8+
VariantOne { num: u32 },
9+
VariantTwo { flt: f32 },
10+
}
11+
12+
fn get_simple_enum() -> SimpleEnum {
13+
SimpleEnum::VariantOne
14+
}
15+
16+
fn set_simple_enum(_: SimpleEnum) {}
17+
18+
fn get_complex_enum() -> ComplexEnum {
19+
ComplexEnum::VariantOne { num: 42 }
20+
}
21+
22+
fn set_complex_enum(_: ComplexEnum) {}
23+
24+
uniffi::include_scaffolding!("enum_style_test");

0 commit comments

Comments
 (0)