Skip to content

Commit

Permalink
Merge pull request #34 from NordSecurity/cs_bindgen_tests
Browse files Browse the repository at this point in the history
C# Tests
  • Loading branch information
Lipt0nas authored Mar 13, 2024
2 parents 70580f7 + cd8909d commit 7defd99
Show file tree
Hide file tree
Showing 9 changed files with 103 additions and 22 deletions.
54 changes: 44 additions & 10 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,80 @@ env:
CARGO_TERM_COLOR: always

jobs:
build:
build-scaffolding:
runs-on: ubuntu-latest
container:
image: rust:1.72-bullseye
image: ghcr.io/nordsecurity/uniffi-bindgen-cpp-test-runner:v0.3.0
steps:
- uses: actions/checkout@v3
- name: Build
- name: Build scaffolding
shell: bash
env:
# Github sets HOME to /github/home and breaks dependencies in Docker image..
# https://github.com/actions/runner/issues/863
HOME: /root
run: |
cargo build --release --package uniffi-bindgen-cpp
source ~/.bashrc
./build_bindgen.sh
./build_scaffolding.sh
- uses: actions/upload-artifact@v3
with:
name: scaffolding_lib
path: cpp-tests/build/libuniffi_fixtures.so

test-bindings:
run-tests:
runs-on: ubuntu-latest
container:
image: ghcr.io/nordsecurity/uniffi-bindgen-cpp-test-runner:v0.3.0
steps:
- uses: actions/checkout@v3
- name: Test bindings
- name: Run tests
shell: bash
env:
# Github sets HOME to /github/home and breaks dependencies in Docker image..
# https://github.com/actions/runner/issues/863
HOME: /root
run: |
source ~/.bashrc
./build_bindgen.sh
./test_bindings.sh
test-scaffolding-go:
runs-on: ubuntu-latest
container:
image: ghcr.io/nordsecurity/uniffi-bindgen-cpp-test-runner:v0.3.0
needs: build-scaffolding
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/download-artifact@v3
with:
name: scaffolding_lib
path: cpp-tests/build/
- name: Test scaffolding Go
shell: bash
env:
# Github sets HOME to /github/home and breaks dependencies in Docker image..
# https://github.com/actions/runner/issues/863
HOME: /root
run: |
source ~/.bashrc
./test_scaffolding_go.sh
test-scaffolding-cs:
runs-on: ubuntu-latest
container:
image: ghcr.io/nordsecurity/uniffi-bindgen-cs-test-runner:v0.1.0
needs: build-scaffolding
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/download-artifact@v3
with:
name: scaffolding_lib
path: cpp-tests/build/
- name: Test scaffolding C#
shell: bash
env:
HOME: /root
run: |
source ~/.bashrc
./test_scaffolding_cs.sh
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "3rd-party/uniffi-bindgen-go"]
path = 3rd-party/uniffi-bindgen-go
url = https://github.com/NordSecurity/uniffi-bindgen-go
[submodule "3rd-party/uniffi-bindgen-cs"]
path = 3rd-party/uniffi-bindgen-cs
url = https://github.com/NordSecurity/uniffi-bindgen-cs
1 change: 1 addition & 0 deletions 3rd-party/uniffi-bindgen-cs
Submodule uniffi-bindgen-cs added at be8027
4 changes: 4 additions & 0 deletions build_bindgen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
set -euxo pipefail

cargo build --release --package uniffi-bindgen-cpp
7 changes: 7 additions & 0 deletions build_scaffolding.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -euxo pipefail

mkdir -p cpp-tests/build
cd cpp-tests/build
cmake -DCMAKE_BUILD_TYPE=Debug ..
make uniffi_fixtures
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ bool fixture_callbacks::RustGetters::get_bool(std::shared_ptr<fixture_callbacks:
std::string fixture_callbacks::RustGetters::get_string(std::shared_ptr<fixture_callbacks::ForeignGetters> foreign, std::string v, bool argument_two) {
try {
return foreign->get_string(v, argument_two);
} catch (const fixture_callbacks::simple_error::BadArgument &e) {
throw e;
} catch (const std::runtime_error &e) {
throw fixture_callbacks::simple_error::UnexpectedError(e.what());
}
Expand Down
14 changes: 12 additions & 2 deletions cpp-tests/scaffolding_tests/rondpoint/lib_rondpoint.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "lib_rondpoint.hpp"

#include <sstream>

int8_t rondpoint::Retourneur::identique_i8(int8_t value) {
return value;
}
Expand Down Expand Up @@ -98,11 +100,19 @@ std::string rondpoint::Stringifier::to_string_u64(uint64_t value) {
}

std::string rondpoint::Stringifier::to_string_float(float value) {
return std::to_string(value);
std::stringstream ss;
ss.precision(8);
ss << value;

return ss.str();
}

std::string rondpoint::Stringifier::to_string_double(double value) {
return std::to_string(value);
std::stringstream ss;
ss.precision(17);
ss << value;

return ss.str();
}

std::string rondpoint::Stringifier::to_string_boolean(bool value) {
Expand Down
29 changes: 29 additions & 0 deletions test_scaffolding_cs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
set -euxo pipefail

SCRIPT_DIR="${SCRIPT_DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )}"
ROOT_DIR="$SCRIPT_DIR"

GENERATOR_DIR="$ROOT_DIR/3rd-party/uniffi-bindgen-cs"
SOLUTION_DIR="dotnet-tests"
BINARIES_DIR="$ROOT_DIR/cpp-tests/build"

pushd $GENERATOR_DIR
./build.sh
./generate_bindings.sh

export LD_LIBRARY_PATH="$BINARIES_DIR:${LD_LIBRARY_PATH:-}"
cd $SOLUTION_DIR
dotnet test --filter \
"FullyQualifiedName!~Docstring \
& FullyQualifiedName!~Numeric \
& FullyQualifiedName!~Stringify \
& FullyQualifiedName!~Disposable \
& FullyQualifiedName!~TestTraitMethods \
& FullyQualifiedName!~OptionalParameterTests \
& FullyQualifiedName!~TestCustomTypes \
& FullyQualifiedName!~TestGlobalMethodsClassName \
& FullyQualifiedName!~DateTimeMinMax \
& FullyQualifiedName!~ChronologicalWorks \
& FullyQualifiedName!~TimespanMax" \
-l "console;verbosity=normal"
11 changes: 1 addition & 10 deletions test_scaffolding_go.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
#!/bin/bash
set -euxo pipefail

mkdir -p cpp-tests/build
pushd cpp-tests/build
cmake -DCMAKE_BUILD_TYPE=Debug ..
make uniffi_fixtures

popd

SCRIPT_DIR="${SCRIPT_DIR:-$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )}"
ROOT_DIR="$SCRIPT_DIR"

Expand All @@ -16,12 +9,10 @@ BINDINGS_DIR="$GENERATOR_DIR/binding_tests"
BINARIES_DIR="$ROOT_DIR/cpp-tests/build"

pushd $GENERATOR_DIR
cargo build
./build.sh
./build_bindings.sh


pushd $BINDINGS_DIR

# We exclude tests that are not part of the main Rust fixtures
EXCLUDE_LIST="custom_types_test\
|destroy_test\
Expand Down

0 comments on commit 7defd99

Please sign in to comment.