File: setter-in-cxx-execution.cpp

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (67 lines) | stat: -rw-r--r-- 2,691 bytes parent folder | download
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;
}