Skip to content

Commit d4b1152

Browse files
committed
Add raw pointer handling test for virtual inheritance
This is a test added for D in previous commit, now expanded to all target languages. Tidy up counting object instances.
1 parent 910fd1e commit d4b1152

20 files changed

+236
-224
lines changed

Examples/test-suite/csharp/cpp11_std_unique_ptr_runme.cs

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ private static void checkCount(int expected_count)
1818

1919
public static void Main()
2020
{
21+
// Test raw pointer handling involving virtual inheritance
22+
using (KlassInheritance kini = new KlassInheritance("KlassInheritanceInput")) {
23+
checkCount(1);
24+
string s = cpp11_std_unique_ptr.useKlassRawPtr(kini);
25+
if (s != "KlassInheritanceInput")
26+
throw new ApplicationException("Incorrect string: " + s);
27+
}
28+
checkCount(0);
29+
2130
// unique_ptr as input
2231
using (Klass kin = new Klass("KlassInput")) {
2332
checkCount(1);
@@ -63,7 +72,7 @@ public static void Main()
6372
}
6473
if (!exception_thrown)
6574
throw new ApplicationException("Should have thrown 'Cannot release ownership as memory is not owned' error");
66-
checkCount(1);
75+
checkCount(1);
6776
}
6877
checkCount(0);
6978

@@ -84,49 +93,22 @@ public static void Main()
8493
throw new Exception("wrong object label");
8594

8695
Klass k2 = cpp11_std_unique_ptr.makeKlassUniquePtr("second");
87-
if (Klass.getTotal_count() != 2)
88-
throw new Exception("number of objects should be 2");
96+
checkCount(2);
8997

9098
using (Klass k3 = cpp11_std_unique_ptr.makeKlassUniquePtr("second")) {
91-
if (Klass.getTotal_count() != 3)
92-
throw new Exception("number of objects should be 3");
99+
checkCount(3);
93100
}
94-
if (Klass.getTotal_count() != 2)
95-
throw new Exception("number of objects should be 2");
101+
checkCount(2);
96102

103+
k1.Dispose();
97104
k1 = null;
98-
{
99-
int countdown = 500;
100-
int expectedCount = 1;
101-
while (true) {
102-
WaitForGC();
103-
if (--countdown == 0)
104-
break;
105-
if (Klass.getTotal_count() == expectedCount)
106-
break;
107-
};
108-
int actualCount = Klass.getTotal_count();
109-
if (actualCount != expectedCount)
110-
Console.Error.WriteLine("Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't
111-
}
105+
checkCount(1);
112106

113107
if (k2.getLabel() != "second")
114108
throw new Exception("wrong object label");
115109

110+
k2.Dispose();
116111
k2 = null;
117-
{
118-
int countdown = 500;
119-
int expectedCount = 0;
120-
while (true) {
121-
WaitForGC();
122-
if (--countdown == 0)
123-
break;
124-
if (Klass.getTotal_count() == expectedCount)
125-
break;
126-
}
127-
int actualCount = Klass.getTotal_count();
128-
if (actualCount != expectedCount)
129-
Console.Error.WriteLine("Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't
130-
}
112+
checkCount(0);
131113
}
132114
}

Examples/test-suite/csharp/li_std_auto_ptr_runme.cs

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ private static void checkCount(int expected_count)
1818

1919
public static void Main()
2020
{
21+
// Test raw pointer handling involving virtual inheritance
22+
using (KlassInheritance kini = new KlassInheritance("KlassInheritanceInput")) {
23+
checkCount(1);
24+
string s = li_std_auto_ptr.useKlassRawPtr(kini);
25+
if (s != "KlassInheritanceInput")
26+
throw new ApplicationException("Incorrect string: " + s);
27+
}
28+
checkCount(0);
29+
2130
// auto_ptr as input
2231
using (Klass kin = new Klass("KlassInput")) {
2332
checkCount(1);
@@ -84,49 +93,22 @@ public static void Main()
8493
throw new Exception("wrong object label");
8594

8695
Klass k2 = li_std_auto_ptr.makeKlassAutoPtr("second");
87-
if (Klass.getTotal_count() != 2)
88-
throw new Exception("number of objects should be 2");
96+
checkCount(2);
8997

9098
using (Klass k3 = li_std_auto_ptr.makeKlassAutoPtr("second")) {
91-
if (Klass.getTotal_count() != 3)
92-
throw new Exception("number of objects should be 3");
99+
checkCount(3);
93100
}
94-
if (Klass.getTotal_count() != 2)
95-
throw new Exception("number of objects should be 2");
101+
checkCount(2);
96102

103+
k1.Dispose();
97104
k1 = null;
98-
{
99-
int countdown = 500;
100-
int expectedCount = 1;
101-
while (true) {
102-
WaitForGC();
103-
if (--countdown == 0)
104-
break;
105-
if (Klass.getTotal_count() == expectedCount)
106-
break;
107-
};
108-
int actualCount = Klass.getTotal_count();
109-
if (actualCount != expectedCount)
110-
Console.Error.WriteLine("Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't
111-
}
105+
checkCount(1);
112106

113107
if (k2.getLabel() != "second")
114108
throw new Exception("wrong object label");
115109

110+
k2.Dispose();
116111
k2 = null;
117-
{
118-
int countdown = 500;
119-
int expectedCount = 0;
120-
while (true) {
121-
WaitForGC();
122-
if (--countdown == 0)
123-
break;
124-
if (Klass.getTotal_count() == expectedCount)
125-
break;
126-
}
127-
int actualCount = Klass.getTotal_count();
128-
if (actualCount != expectedCount)
129-
Console.Error.WriteLine("Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't
130-
}
112+
checkCount(0);
131113
}
132114
}

Examples/test-suite/d/cpp11_std_unique_ptr_runme.1.d

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,14 @@ void main() {
9393
throw new Exception("wrong object label");
9494

9595
Klass k2 = makeKlassUniquePtr("second");
96-
if (Klass.getTotal_count() != 2)
97-
throw new Exception("number of objects should be 2");
96+
checkCount(2);
9897

9998
k1.dispose();
100-
if (Klass.getTotal_count() != 1)
101-
throw new Exception("number of objects should be 1");
99+
checkCount(1);
102100

103101
if (k2.getLabel() != "second")
104102
throw new Exception("wrong object label");
105103

106104
k2.dispose();
107-
if (Klass.getTotal_count() != 0)
108-
throw new Exception("no objects should be left");
105+
checkCount(0);
109106
}

Examples/test-suite/d/cpp11_std_unique_ptr_runme.2.d

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,14 @@ void main() {
9393
throw new Exception("wrong object label");
9494

9595
Klass k2 = makeKlassUniquePtr("second");
96-
if (Klass.getTotal_count() != 2)
97-
throw new Exception("number of objects should be 2");
96+
checkCount(2);
9897

9998
k1.dispose();
100-
if (Klass.getTotal_count() != 1)
101-
throw new Exception("number of objects should be 1");
99+
checkCount(1);
102100

103101
if (k2.getLabel() != "second")
104102
throw new Exception("wrong object label");
105103

106104
k2.dispose();
107-
if (Klass.getTotal_count() != 0)
108-
throw new Exception("no objects should be left");
105+
checkCount(0);
109106
}

Examples/test-suite/d/li_std_auto_ptr_runme.1.d

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,14 @@ void main() {
9393
throw new Exception("wrong object label");
9494

9595
Klass k2 = makeKlassAutoPtr("second");
96-
if (Klass.getTotal_count() != 2)
97-
throw new Exception("number of objects should be 2");
96+
checkCount(2);
9897

9998
k1.dispose();
100-
if (Klass.getTotal_count() != 1)
101-
throw new Exception("number of objects should be 1");
99+
checkCount(1);
102100

103101
if (k2.getLabel() != "second")
104102
throw new Exception("wrong object label");
105103

106104
k2.dispose();
107-
if (Klass.getTotal_count() != 0)
108-
throw new Exception("no objects should be left");
105+
checkCount(0);
109106
}

Examples/test-suite/d/li_std_auto_ptr_runme.2.d

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ void main() {
1818
scope KlassInheritance kini = new KlassInheritance("KlassInheritanceInput");
1919
checkCount(1);
2020
string s = useKlassRawPtr(kini);
21-
checkCount(1);
2221
if (s != "KlassInheritanceInput")
2322
throw new Exception("Incorrect string: " ~ s);
2423
}
@@ -94,17 +93,14 @@ void main() {
9493
throw new Exception("wrong object label");
9594

9695
Klass k2 = makeKlassAutoPtr("second");
97-
if (Klass.getTotal_count() != 2)
98-
throw new Exception("number of objects should be 2");
96+
checkCount(2);
9997

10098
k1.dispose();
101-
if (Klass.getTotal_count() != 1)
102-
throw new Exception("number of objects should be 1");
99+
checkCount(1);
103100

104101
if (k2.getLabel() != "second")
105102
throw new Exception("wrong object label");
106103

107104
k2.dispose();
108-
if (Klass.getTotal_count() != 0)
109-
throw new Exception("no objects should be left");
105+
checkCount(0);
110106
}

Examples/test-suite/java/cpp11_std_unique_ptr_runme.java

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ private static void checkCount(int expected_count) {
2828

2929
public static void main(String argv[]) throws Throwable
3030
{
31+
// Test raw pointer handling involving virtual inheritance
32+
{
33+
KlassInheritance kini = new KlassInheritance("KlassInheritanceInput");
34+
checkCount(1);
35+
String s = cpp11_std_unique_ptr.useKlassRawPtr(kini);
36+
if (!s.equals("KlassInheritanceInput"))
37+
throw new RuntimeException("Incorrect string: " + s);
38+
kini.delete();
39+
checkCount(0);
40+
}
41+
3142
// unique_ptr as input
3243
{
3344
Klass kin = new Klass("KlassInput");
@@ -102,42 +113,17 @@ public static void main(String argv[]) throws Throwable
102113
throw new RuntimeException("wrong object label");
103114

104115
Klass k2 = cpp11_std_unique_ptr.makeKlassUniquePtr("second");
105-
if (Klass.getTotal_count() != 2)
106-
throw new RuntimeException("number of objects should be 2");
116+
checkCount(2);
107117

118+
k1.delete();
108119
k1 = null;
109-
{
110-
int countdown = 500;
111-
int expectedCount = 1;
112-
while (true) {
113-
WaitForGC();
114-
if (--countdown == 0)
115-
break;
116-
if (Klass.getTotal_count() == expectedCount)
117-
break;
118-
}
119-
int actualCount = Klass.getTotal_count();
120-
if (actualCount != expectedCount)
121-
System.err.println("GC failed to run (cpp11_std_unique_ptr 1). Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't
122-
}
120+
checkCount(1);
123121

124122
if (!k2.getLabel().equals("second"))
125123
throw new RuntimeException("wrong object label");
126124

125+
k2.delete();
127126
k2 = null;
128-
{
129-
int countdown = 500;
130-
int expectedCount = 0;
131-
while (true) {
132-
WaitForGC();
133-
if (--countdown == 0)
134-
break;
135-
if (Klass.getTotal_count() == expectedCount)
136-
break;
137-
};
138-
int actualCount = Klass.getTotal_count();
139-
if (actualCount != expectedCount)
140-
System.err.println("GC failed to run (cpp11_std_unique_ptr 2). Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't
141-
}
127+
checkCount(0);
142128
}
143129
}

Examples/test-suite/java/li_std_auto_ptr_runme.java

Lines changed: 16 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ private static void checkCount(int expected_count) {
2828

2929
public static void main(String argv[]) throws Throwable
3030
{
31+
// Test raw pointer handling involving virtual inheritance
32+
{
33+
KlassInheritance kini = new KlassInheritance("KlassInheritanceInput");
34+
checkCount(1);
35+
String s = li_std_auto_ptr.useKlassRawPtr(kini);
36+
if (!s.equals("KlassInheritanceInput"))
37+
throw new RuntimeException("Incorrect string: " + s);
38+
kini.delete();
39+
checkCount(0);
40+
}
41+
3142
// auto_ptr as input
3243
{
3344
Klass kin = new Klass("KlassInput");
@@ -102,42 +113,17 @@ public static void main(String argv[]) throws Throwable
102113
throw new RuntimeException("wrong object label");
103114

104115
Klass k2 = li_std_auto_ptr.makeKlassAutoPtr("second");
105-
if (Klass.getTotal_count() != 2)
106-
throw new RuntimeException("number of objects should be 2");
116+
checkCount(2);
107117

118+
k1.delete();
108119
k1 = null;
109-
{
110-
int countdown = 500;
111-
int expectedCount = 1;
112-
while (true) {
113-
WaitForGC();
114-
if (--countdown == 0)
115-
break;
116-
if (Klass.getTotal_count() == expectedCount)
117-
break;
118-
}
119-
int actualCount = Klass.getTotal_count();
120-
if (actualCount != expectedCount)
121-
System.err.println("GC failed to run (li_std_auto_ptr 1). Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't
122-
}
120+
checkCount(1);
123121

124122
if (!k2.getLabel().equals("second"))
125123
throw new RuntimeException("wrong object label");
126124

125+
k2.delete();
127126
k2 = null;
128-
{
129-
int countdown = 500;
130-
int expectedCount = 0;
131-
while (true) {
132-
WaitForGC();
133-
if (--countdown == 0)
134-
break;
135-
if (Klass.getTotal_count() == expectedCount)
136-
break;
137-
};
138-
int actualCount = Klass.getTotal_count();
139-
if (actualCount != expectedCount)
140-
System.err.println("GC failed to run (li_std_auto_ptr 2). Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't
141-
}
127+
checkCount(0);
142128
}
143129
}

0 commit comments

Comments
 (0)