1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
// 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;
}
|