diff options
Diffstat (limited to 'test cases/swift/11 mixed cpp')
-rw-r--r-- | test cases/swift/11 mixed cpp/main.swift | 6 | ||||
-rw-r--r-- | test cases/swift/11 mixed cpp/meson.build | 12 | ||||
-rw-r--r-- | test cases/swift/11 mixed cpp/mylib.cpp | 22 | ||||
-rw-r--r-- | test cases/swift/11 mixed cpp/mylib.h | 13 |
4 files changed, 53 insertions, 0 deletions
diff --git a/test cases/swift/11 mixed cpp/main.swift b/test cases/swift/11 mixed cpp/main.swift new file mode 100644 index 0000000..c055dcd --- /dev/null +++ b/test cases/swift/11 mixed cpp/main.swift @@ -0,0 +1,6 @@ +testCallFromSwift() +testCallWithParam("Calling C++ function from Swift with param is working") + +var test = Test() +var testtwo = Test(1) +test.testCallFromClass() diff --git a/test cases/swift/11 mixed cpp/meson.build b/test cases/swift/11 mixed cpp/meson.build new file mode 100644 index 0000000..6027341 --- /dev/null +++ b/test cases/swift/11 mixed cpp/meson.build @@ -0,0 +1,12 @@ +project('mixed cpp', 'cpp', 'swift') + +swiftc = meson.get_compiler('swift') + +# Testing C++ and Swift interoperability requires Swift 5.9 +if not swiftc.version().version_compare('>= 5.9') + error('MESON_SKIP_TEST Test requires Swift 5.9') +endif + +lib = static_library('mylib', 'mylib.cpp') +exe = executable('prog', 'main.swift', 'mylib.h', link_with: lib, swift_interoperability_mode: 'cpp') +test('cpp interface', exe) diff --git a/test cases/swift/11 mixed cpp/mylib.cpp b/test cases/swift/11 mixed cpp/mylib.cpp new file mode 100644 index 0000000..0c61681 --- /dev/null +++ b/test cases/swift/11 mixed cpp/mylib.cpp @@ -0,0 +1,22 @@ +#include "mylib.h" +#include <iostream> + +Test::Test() { + std::cout << "Test initialized" << std::endl; +} + +Test::Test(int param) { + std::cout << "Test initialized with param " << param << std::endl; +} + +void Test::testCallFromClass() { + std::cout << "Calling C++ class function from Swift is working" << std::endl; +} + +void testCallFromSwift() { + std::cout << "Calling this C++ function from Swift is working" << std::endl; +} + +void testCallWithParam(const std::string ¶m) { + std::cout << param << std::endl; +} diff --git a/test cases/swift/11 mixed cpp/mylib.h b/test cases/swift/11 mixed cpp/mylib.h new file mode 100644 index 0000000..c465be4 --- /dev/null +++ b/test cases/swift/11 mixed cpp/mylib.h @@ -0,0 +1,13 @@ +#pragma once +#include <string> + +class Test { +public: + Test(); + Test(int param); + + void testCallFromClass(); +}; + +void testCallFromSwift(); +void testCallWithParam(const std::string ¶m); |