Skip to content

Commit b27f35b

Browse files
committed
improve test case: add retainCount check
1 parent 3aea6a8 commit b27f35b

File tree

1 file changed

+33
-6
lines changed

1 file changed

+33
-6
lines changed

test/Interop/SwiftToCxx/enums/enum-associated-value-class-type-cxx.cpp

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,50 @@
88
// RUN: %target-codesign %t/swift-enums-execution
99
// RUN: %target-run %t/swift-enums-execution
1010

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+
1121
// REQUIRES: executable_test
1222

1323
#include <cassert>
1424
#include "enums.h"
1525

1626
using namespace Enums;
1727

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+
1835
int main() {
1936
auto c = C::init(1234);
2037
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);
2149

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+
}
2554

26-
auto e2 = E::i(5678);
27-
assert(e2.isI());
28-
assert(e2.getI() == 5678);
55+
assert(getRetainCount(c) == 1);
2956
return 0;
3057
}

0 commit comments

Comments
 (0)