-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The following APIs are not available in net48: - `BitConverter.SingleToInt32Bits` - `BitConverter.Int32BitsToSingle` - `Dictionary.TryGetValue` - `DateTime.UnixEpoch` Signed-off-by: Kristupas Antanavičius <[email protected]>
- Loading branch information
Showing
12 changed files
with
199 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System; | ||
using System.IO; | ||
using System.Runtime.InteropServices; | ||
using uniffi.stringify; | ||
|
||
namespace UniffiCS.BindingTests; | ||
|
||
public class TestNumericLimits | ||
{ | ||
[Fact] | ||
public void NumericLimitsAreTheSame() | ||
{ | ||
// At first, I tried to write this test by stringifying values in C# and Rust, then | ||
// comparing the stringified result. Turns out C# and Rust format floating point values | ||
// differently, so comparing the result is useless. I tried to change the formatting | ||
// settings in few ways, but I couldn't find formatting settings that would produce | ||
// exact results. | ||
|
||
var meanValue = 0x1234_5678_9123_4567; | ||
|
||
ParseTest<sbyte>( | ||
StringifyMethods.ParseI8, | ||
SByte.MinValue, | ||
SByte.MaxValue, | ||
(sbyte)meanValue); | ||
|
||
ParseTest<short>( | ||
StringifyMethods.ParseI16, | ||
Int16.MinValue, | ||
Int16.MaxValue, | ||
(short)meanValue); | ||
|
||
ParseTest<int>( | ||
StringifyMethods.ParseI32, | ||
Int32.MinValue, | ||
Int32.MaxValue, | ||
(int)meanValue); | ||
|
||
ParseTest<long>( | ||
StringifyMethods.ParseI64, | ||
Int64.MinValue, | ||
Int64.MaxValue, | ||
(long)meanValue); | ||
|
||
ParseTest<byte>( | ||
StringifyMethods.ParseU8, | ||
Byte.MinValue, | ||
Byte.MaxValue, | ||
(byte)meanValue); | ||
|
||
ParseTest<ushort>( | ||
StringifyMethods.ParseU16, | ||
UInt16.MinValue, | ||
UInt16.MaxValue, | ||
(ushort)meanValue); | ||
|
||
ParseTest<uint>( | ||
StringifyMethods.ParseU32, | ||
UInt32.MinValue, | ||
UInt32.MaxValue, | ||
(uint)meanValue); | ||
|
||
ParseTest<ulong>( | ||
StringifyMethods.ParseU64, | ||
UInt64.MinValue, | ||
UInt64.MaxValue, | ||
(ulong)meanValue); | ||
|
||
ParseTest<float>( | ||
StringifyMethods.ParseF32, | ||
Single.MinValue, | ||
Single.MaxValue, | ||
Single.Epsilon); | ||
|
||
ParseTest<double>( | ||
StringifyMethods.ParseF64, | ||
Double.MinValue, | ||
Double.MaxValue, | ||
Double.Epsilon); | ||
} | ||
|
||
static void ParseTest<T>( | ||
Func<String, T> parseMethod, | ||
T minValue, | ||
T maxValue, | ||
T meanValue | ||
) | ||
{ | ||
// Possible null reference assignment | ||
#pragma warning disable 8602 | ||
#pragma warning disable 8604 | ||
Assert.Equal(minValue, parseMethod(minValue.ToString())); | ||
Assert.Equal(maxValue, parseMethod(maxValue.ToString())); | ||
Assert.Equal(meanValue, parseMethod(meanValue.ToString())); | ||
#pragma warning restore 8602 | ||
#pragma warning restore 8604 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<TargetFrameworks>net48;net6.0</TargetFrameworks> | ||
<LangVersion>10.0</LangVersion> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<!-- Allow testing internals of generated code --> | ||
<ItemGroup> | ||
<InternalsVisibleTo Include="UniffiCS.BindingTests" /> | ||
<PackageReference Include="IsExternalInit" Version="1.0.3"/> | ||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "uniffi-cs-stringify" | ||
version = "1.0.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[lib] | ||
crate-type = ["lib", "cdylib"] | ||
name = "stringify" | ||
|
||
[dependencies] | ||
paste = "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"]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* 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 paste::paste; | ||
|
||
uniffi::setup_scaffolding!(); | ||
|
||
macro_rules! define_parse_function { | ||
($type:ty) => { | ||
paste! { | ||
#[uniffi::export] | ||
fn [<to_string_ $type>](value: $type) -> String { | ||
value.to_string() | ||
} | ||
|
||
#[uniffi::export] | ||
fn [<parse_ $type>](value: String) -> $type { | ||
value.parse::<$type>().unwrap() | ||
} | ||
} | ||
}; | ||
} | ||
|
||
define_parse_function!(i8); | ||
define_parse_function!(i16); | ||
define_parse_function!(i32); | ||
define_parse_function!(i64); | ||
define_parse_function!(u8); | ||
define_parse_function!(u16); | ||
define_parse_function!(u32); | ||
define_parse_function!(u64); | ||
define_parse_function!(f32); | ||
define_parse_function!(f64); |