Skip to content

Commit 1f853c0

Browse files
committed
Add tests for importing non-public inherited members
1 parent 0f8b97a commit 1f853c0

File tree

5 files changed

+418
-0
lines changed

5 files changed

+418
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module NonPublicInheritance {
2+
requires cplusplus
3+
header "non-public-inheritance.h"
4+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef NON_PUBLIC_INHERTIANCE_H
2+
#define NON_PUBLIC_INHERTIANCE_H
3+
4+
// TODO: dependent on private_fileid feature
5+
// #define BLESS __attribute__((__swift_attr__("private_fileid:main/blessed.swift")))
6+
#define BLESS
7+
8+
const int PUBL_RETURN_VAL = 1;
9+
const int PROT_RETURN_VAL = 2;
10+
const int PRIV_RETURN_VAL = 3;
11+
12+
class BLESS Base {
13+
public:
14+
int publ(void) const { return PUBL_RETURN_VAL; }
15+
protected:
16+
int prot(void) const { return PROT_RETURN_VAL; }
17+
private:
18+
int priv(void) const { return PRIV_RETURN_VAL; }
19+
};
20+
21+
class BLESS PublBase : public Base {};
22+
class BLESS ProtBase : protected Base {};
23+
class BLESS PrivBase : private Base {};
24+
25+
class BLESS PublPublBase : public PublBase {};
26+
class BLESS ProtPublBase : protected PublBase {};
27+
class BLESS PrivPublBase : private PublBase {};
28+
29+
class BLESS PublProtBase : public ProtBase {};
30+
class BLESS ProtProtBase : protected ProtBase {};
31+
class BLESS PrivProtBase : private ProtBase {};
32+
33+
class BLESS PublPrivBase : public PrivBase {};
34+
class BLESS ProtPrivBase : protected PrivBase {};
35+
class BLESS PrivPrivBase : private PrivBase {};
36+
37+
#endif /* NON_PUBLIC_INHERTIANCE_H */
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// Test that all accessible inherited methods can be called.
2+
//
3+
// Note that this test isn't very meaningful until we are allowed to access
4+
// non-public members (those are the TODOs). It is checked in for now as
5+
// a placeholder (and it _does_ at least ensure that things haven't gone
6+
// horribly wrong).
7+
//
8+
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -cxx-interoperability-mode=default)
9+
//
10+
// REQUIRES: executable_test
11+
12+
import StdlibUnittest
13+
import NonPublicInheritance
14+
15+
var Tests = TestSuite("NonPublicInheritance")
16+
Tests.test("Base") { Base().ext() }
17+
Tests.test("PublBase") { PublBase().ext() }
18+
Tests.test("ProtBase") { ProtBase().ext() }
19+
Tests.test("PrivBase") { PrivBase().ext() }
20+
Tests.test("PublPublBase") { PublPublBase().ext() }
21+
Tests.test("ProtPublBase") { ProtPublBase().ext() }
22+
Tests.test("PrivPublBase") { PrivPublBase().ext() }
23+
Tests.test("PublProtBase") { PublProtBase().ext() }
24+
Tests.test("ProtProtBase") { ProtProtBase().ext() }
25+
Tests.test("PrivProtBase") { PrivProtBase().ext() }
26+
Tests.test("PublPrivBase") { PublPrivBase().ext() }
27+
Tests.test("ProtPrivBase") { ProtPrivBase().ext() }
28+
Tests.test("PrivPrivBase") { PrivPrivBase().ext() }
29+
30+
extension Base {
31+
func ext() {
32+
expectEqual(publ(), PUBL_RETURN_VAL)
33+
// TODO: prot()
34+
// TODO: priv()
35+
}
36+
}
37+
38+
extension PublBase {
39+
func ext() {
40+
expectEqual(publ(), PUBL_RETURN_VAL)
41+
// TODO: prot()
42+
}
43+
}
44+
45+
extension PublPublBase {
46+
func ext() {
47+
expectEqual(publ(), PUBL_RETURN_VAL)
48+
// TODO: prot()
49+
}
50+
}
51+
52+
extension ProtPublBase {
53+
func ext() {
54+
// TODO: publ()
55+
// TODO: prot()
56+
}
57+
}
58+
59+
extension PrivPublBase {
60+
func ext() {
61+
// TODO: publ()
62+
// TODO: prot()
63+
}
64+
}
65+
66+
extension ProtBase {
67+
func ext() {
68+
// TODO: publ()
69+
// TODO: prot()
70+
}
71+
}
72+
73+
74+
extension PublProtBase {
75+
func ext() {
76+
// TODO: publ()
77+
// TODO: prot()
78+
}
79+
}
80+
81+
extension ProtProtBase {
82+
func ext() {
83+
// TODO: publ()
84+
// TODO: prot()
85+
}
86+
}
87+
88+
extension PrivProtBase {
89+
func ext() {
90+
// TODO: publ()
91+
// TODO: prot()
92+
}
93+
}
94+
95+
extension PrivBase {
96+
func ext() {
97+
// TODO: publ()
98+
// TODO: prot()
99+
}
100+
}
101+
102+
extension PublPrivBase {
103+
func ext() {
104+
// Nothing to test (nothing is accessible)
105+
}
106+
}
107+
108+
extension ProtPrivBase {
109+
func ext() {
110+
// Nothing to test (nothing is accessible)
111+
}
112+
}
113+
114+
extension PrivPrivBase {
115+
func ext() {
116+
// Nothing to test (nothing is accessible)
117+
}
118+
}
119+
120+
runAllTests()
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// RUN: %target-swift-ide-test -print-module -module-to-print=NonPublicInheritance -print-access -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s
2+
3+
// CHECK: public struct Base {
4+
// CHECK-NEXT: public init()
5+
// CHECK-NEXT: public func publ() -> Int32
6+
// CHECK-NEXT: private func prot() -> Int32
7+
// CHECK-NEXT: private func priv() -> Int32
8+
// CHECK-NEXT: }
9+
10+
// CHECK-NEXT: public struct PublBase {
11+
// CHECK-NEXT: public init()
12+
// CHECK-NEXT: public func publ() -> Int32
13+
// CHECK-NEXT: private func prot() -> Int32
14+
// CHECK-NEXT: }
15+
16+
// CHECK-NEXT: public struct ProtBase {
17+
// CHECK-NEXT: public init()
18+
// CHECK-NEXT: private func publ() -> Int32
19+
// CHECK-NEXT: private func prot() -> Int32
20+
// CHECK-NEXT: }
21+
22+
// CHECK-NEXT: public struct PrivBase {
23+
// CHECK-NEXT: public init()
24+
// CHECK-NEXT: private func publ() -> Int32
25+
// CHECK-NEXT: private func prot() -> Int32
26+
// CHECK-NEXT: }
27+
28+
// CHECK-NEXT: public struct PublPublBase {
29+
// CHECK-NEXT: public init()
30+
// CHECK-NEXT: public func publ() -> Int32
31+
// CHECK-NEXT: private func prot() -> Int32
32+
// CHECK-NEXT: }
33+
34+
// CHECK-NEXT: public struct ProtPublBase {
35+
// CHECK-NEXT: public init()
36+
// CHECK-NEXT: private func publ() -> Int32
37+
// CHECK-NEXT: private func prot() -> Int32
38+
// CHECK-NEXT: }
39+
40+
// CHECK-NEXT: public struct PrivPublBase {
41+
// CHECK-NEXT: public init()
42+
// CHECK-NEXT: private func publ() -> Int32
43+
// CHECK-NEXT: private func prot() -> Int32
44+
// CHECK-NEXT: }
45+
46+
// CHECK-NEXT: public struct PublProtBase {
47+
// CHECK-NEXT: public init()
48+
// CHECK-NEXT: private func publ() -> Int32
49+
// CHECK-NEXT: private func prot() -> Int32
50+
// CHECK-NEXT: }
51+
52+
// CHECK-NEXT: public struct ProtProtBase {
53+
// CHECK-NEXT: public init()
54+
// CHECK-NEXT: private func publ() -> Int32
55+
// CHECK-NEXT: private func prot() -> Int32
56+
// CHECK-NEXT: }
57+
58+
// CHECK-NEXT: public struct PrivProtBase {
59+
// CHECK-NEXT: public init()
60+
// CHECK-NEXT: private func publ() -> Int32
61+
// CHECK-NEXT: private func prot() -> Int32
62+
// CHECK-NEXT: }
63+
64+
// CHECK-NEXT: public struct PublPrivBase {
65+
// CHECK-NEXT: public init()
66+
// CHECK-NEXT: }
67+
68+
// CHECK-NEXT: public struct ProtPrivBase {
69+
// CHECK-NEXT: public init()
70+
// CHECK-NEXT: }
71+
72+
// CHECK-NEXT: public struct PrivPrivBase {
73+
// CHECK-NEXT: public init()
74+
// CHECK-NEXT: }
75+

0 commit comments

Comments
 (0)