|
8 | 8 | // RUN: %target-codesign %t/swift-enums-execution
|
9 | 9 | // RUN: %target-run %t/swift-enums-execution
|
10 | 10 |
|
| 11 | +// RUN: %empty-directory(%t-evo) |
| 12 | + |
| 13 | +// RUN: %target-swift-frontend %S/enum-associated-value-class-type-cxx.swift -typecheck -module-name Enums -clang-header-expose-decls=all-public -enable-library-evolution -emit-clang-header-path %t-evo/enums.h |
| 14 | + |
| 15 | +// RUN: %target-interop-build-clangxx -c %s -I %t-evo -o %t-evo/swift-enums-execution.o |
| 16 | +// RUN: %target-interop-build-swift %S/enum-associated-value-class-type-cxx.swift -o %t-evo/swift-enums-execution -Xlinker %t-evo/swift-enums-execution.o -module-name Enums -enable-library-evolution -Xfrontend -entry-point-function-name -Xfrontend swiftMain |
| 17 | + |
| 18 | +// RUN: %target-codesign %t-evo/swift-enums-execution |
| 19 | +// RUN: %target-run %t-evo/swift-enums-execution |
| 20 | + |
11 | 21 | // REQUIRES: executable_test
|
12 | 22 |
|
13 | 23 | #include <cassert>
|
14 | 24 | #include "enums.h"
|
15 | 25 |
|
16 | 26 | using namespace Enums;
|
17 | 27 |
|
| 28 | +extern "C" size_t swift_retainCount(void * _Nonnull obj); |
| 29 | + |
| 30 | +size_t getRetainCount(const C & obj) { |
| 31 | + void *p = swift::_impl::_impl_RefCountedClass::getOpaquePointer(obj); |
| 32 | + return swift_retainCount(p); |
| 33 | +} |
| 34 | + |
18 | 35 | int main() {
|
19 | 36 | auto c = C::init(1234);
|
20 | 37 | assert(c.getX() == 1234);
|
| 38 | + assert(getRetainCount(c) == 1); |
| 39 | + |
| 40 | + { |
| 41 | + auto e = E::c(c); |
| 42 | + assert(e.isC()); |
| 43 | + assert(getRetainCount(c) == 2); |
| 44 | + |
| 45 | + auto extracted = e.getC(); |
| 46 | + assert(getRetainCount(c) == 3); |
| 47 | + assert(getRetainCount(extracted) == 3); |
| 48 | + assert(extracted.getX() == 1234); |
21 | 49 |
|
22 |
| - auto e1 = E::c(c); |
23 |
| - assert(e1.isC()); |
24 |
| - assert(e1.getC().getX() == 1234); |
| 50 | + extracted.setX(5678); |
| 51 | + assert(extracted.getX() == 5678); |
| 52 | + assert(c.getX() == 5678); |
| 53 | + } |
25 | 54 |
|
26 |
| - auto e2 = E::i(5678); |
27 |
| - assert(e2.isI()); |
28 |
| - assert(e2.getI() == 5678); |
| 55 | + assert(getRetainCount(c) == 1); |
29 | 56 | return 0;
|
30 | 57 | }
|
0 commit comments