Files
swift-mirror/test/Interop/SwiftToCxx/properties/setter-in-cxx-execution.cpp
Alex Lorenz 3a9b6dce9d [interop][SwiftToCxx] add support for emitting Swift stdlib dependency in one header file
This is the default behavior. You can disable this by specifying the -clang-header-expose-decls= flag explicitly when generating the header
2022-09-28 08:08:48 -07:00

68 lines
2.6 KiB
C++

// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend %S/setter-in-cxx.swift -typecheck -module-name Properties -clang-header-expose-decls=all-public -emit-clang-header-path %t/properties.h
// RUN: %target-interop-build-clangxx -c %s -I %t -o %t/swift-props-execution.o
// RUN: %target-interop-build-swift %S/setter-in-cxx.swift -o %t/swift-props-execution -Xlinker %t/swift-props-execution.o -module-name Properties -Xfrontend -entry-point-function-name -Xfrontend swiftMain
// RUN: %target-codesign %t/swift-props-execution
// RUN: %target-run %t/swift-props-execution | %FileCheck %s
// REQUIRES: executable_test
#include <assert.h>
#include "properties.h"
int main() {
using namespace Properties;
auto smallStructWithProps = createSmallStructWithProps();
smallStructWithProps.setStoredInt(12);
assert(smallStructWithProps.getStoredInt() == 12);
assert(smallStructWithProps.getComputedInt() == 14);
smallStructWithProps.setComputedInt(45);
assert(smallStructWithProps.getStoredInt() == 43);
assert(smallStructWithProps.getComputedInt() == 45);
auto largeStructWithProps = smallStructWithProps.getLargeStructWithProps();
assert(largeStructWithProps.getStoredSmallStruct().getX() == 0xFAE);
largeStructWithProps.setStoredSmallStruct(createFirstSmallStruct(999));
assert(largeStructWithProps.getStoredSmallStruct().getX() == 999);
auto firstSmallStruct = largeStructWithProps.getStoredSmallStruct();
assert(firstSmallStruct.getX() == 999);
firstSmallStruct.setX(42);
assert(firstSmallStruct.getX() == 42);
largeStructWithProps.setStoredLargeStruct(largeStructWithProps.getStoredLargeStruct());
smallStructWithProps.setLargeStructWithProps(largeStructWithProps);
// CHECK: SET: LargeStruct(x1: 90, x2: 1, x3: 2, x4: 3, x5: 4, x6: 5), FirstSmallStruct(x: 999)
auto largeStruct = largeStructWithProps.getStoredLargeStruct();
largeStruct.setX1(0);
largeStruct.setX2(largeStruct.getX2() * 2);
largeStruct.setX3(-72);
largeStructWithProps.setStoredLargeStruct(largeStruct);
smallStructWithProps.setLargeStructWithProps(largeStructWithProps);
// CHECK-NEXT: SET: LargeStruct(x1: 0, x2: 2, x3: -72, x4: 3, x5: 4, x6: 5), FirstSmallStruct(x: 999)
auto propsInClass = createPropsInClass(-1234);
assert(propsInClass.getStoredInt() == -1234);
propsInClass.setStoredInt(45);
assert(propsInClass.getStoredInt() == 45);
propsInClass.setComputedInt(-11);
assert(propsInClass.getComputedInt() == -11);
assert(propsInClass.getStoredInt() == -13);
{
auto x = LargeStruct::getStaticX();
assert(x == 0);
LargeStruct::setStaticX(13);
x = LargeStruct::getStaticX();
assert(x == 13);
}
return 0;
}