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.
This commit is contained in:
parent
910fd1e3cf
commit
d4b1152d4b
20 changed files with 236 additions and 224 deletions
|
|
@ -18,6 +18,15 @@ public class cpp11_std_unique_ptr_runme {
|
||||||
|
|
||||||
public static void Main()
|
public static void Main()
|
||||||
{
|
{
|
||||||
|
// Test raw pointer handling involving virtual inheritance
|
||||||
|
using (KlassInheritance kini = new KlassInheritance("KlassInheritanceInput")) {
|
||||||
|
checkCount(1);
|
||||||
|
string s = cpp11_std_unique_ptr.useKlassRawPtr(kini);
|
||||||
|
if (s != "KlassInheritanceInput")
|
||||||
|
throw new ApplicationException("Incorrect string: " + s);
|
||||||
|
}
|
||||||
|
checkCount(0);
|
||||||
|
|
||||||
// unique_ptr as input
|
// unique_ptr as input
|
||||||
using (Klass kin = new Klass("KlassInput")) {
|
using (Klass kin = new Klass("KlassInput")) {
|
||||||
checkCount(1);
|
checkCount(1);
|
||||||
|
|
@ -63,7 +72,7 @@ public class cpp11_std_unique_ptr_runme {
|
||||||
}
|
}
|
||||||
if (!exception_thrown)
|
if (!exception_thrown)
|
||||||
throw new ApplicationException("Should have thrown 'Cannot release ownership as memory is not owned' error");
|
throw new ApplicationException("Should have thrown 'Cannot release ownership as memory is not owned' error");
|
||||||
checkCount(1);
|
checkCount(1);
|
||||||
}
|
}
|
||||||
checkCount(0);
|
checkCount(0);
|
||||||
|
|
||||||
|
|
@ -84,49 +93,22 @@ public class cpp11_std_unique_ptr_runme {
|
||||||
throw new Exception("wrong object label");
|
throw new Exception("wrong object label");
|
||||||
|
|
||||||
Klass k2 = cpp11_std_unique_ptr.makeKlassUniquePtr("second");
|
Klass k2 = cpp11_std_unique_ptr.makeKlassUniquePtr("second");
|
||||||
if (Klass.getTotal_count() != 2)
|
checkCount(2);
|
||||||
throw new Exception("number of objects should be 2");
|
|
||||||
|
|
||||||
using (Klass k3 = cpp11_std_unique_ptr.makeKlassUniquePtr("second")) {
|
using (Klass k3 = cpp11_std_unique_ptr.makeKlassUniquePtr("second")) {
|
||||||
if (Klass.getTotal_count() != 3)
|
checkCount(3);
|
||||||
throw new Exception("number of objects should be 3");
|
|
||||||
}
|
}
|
||||||
if (Klass.getTotal_count() != 2)
|
checkCount(2);
|
||||||
throw new Exception("number of objects should be 2");
|
|
||||||
|
|
||||||
|
k1.Dispose();
|
||||||
k1 = null;
|
k1 = null;
|
||||||
{
|
checkCount(1);
|
||||||
int countdown = 500;
|
|
||||||
int expectedCount = 1;
|
|
||||||
while (true) {
|
|
||||||
WaitForGC();
|
|
||||||
if (--countdown == 0)
|
|
||||||
break;
|
|
||||||
if (Klass.getTotal_count() == expectedCount)
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
int actualCount = Klass.getTotal_count();
|
|
||||||
if (actualCount != expectedCount)
|
|
||||||
Console.Error.WriteLine("Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't
|
|
||||||
}
|
|
||||||
|
|
||||||
if (k2.getLabel() != "second")
|
if (k2.getLabel() != "second")
|
||||||
throw new Exception("wrong object label");
|
throw new Exception("wrong object label");
|
||||||
|
|
||||||
|
k2.Dispose();
|
||||||
k2 = null;
|
k2 = null;
|
||||||
{
|
checkCount(0);
|
||||||
int countdown = 500;
|
|
||||||
int expectedCount = 0;
|
|
||||||
while (true) {
|
|
||||||
WaitForGC();
|
|
||||||
if (--countdown == 0)
|
|
||||||
break;
|
|
||||||
if (Klass.getTotal_count() == expectedCount)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
int actualCount = Klass.getTotal_count();
|
|
||||||
if (actualCount != expectedCount)
|
|
||||||
Console.Error.WriteLine("Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,15 @@ public class li_std_auto_ptr_runme {
|
||||||
|
|
||||||
public static void Main()
|
public static void Main()
|
||||||
{
|
{
|
||||||
|
// Test raw pointer handling involving virtual inheritance
|
||||||
|
using (KlassInheritance kini = new KlassInheritance("KlassInheritanceInput")) {
|
||||||
|
checkCount(1);
|
||||||
|
string s = li_std_auto_ptr.useKlassRawPtr(kini);
|
||||||
|
if (s != "KlassInheritanceInput")
|
||||||
|
throw new ApplicationException("Incorrect string: " + s);
|
||||||
|
}
|
||||||
|
checkCount(0);
|
||||||
|
|
||||||
// auto_ptr as input
|
// auto_ptr as input
|
||||||
using (Klass kin = new Klass("KlassInput")) {
|
using (Klass kin = new Klass("KlassInput")) {
|
||||||
checkCount(1);
|
checkCount(1);
|
||||||
|
|
@ -84,49 +93,22 @@ public class li_std_auto_ptr_runme {
|
||||||
throw new Exception("wrong object label");
|
throw new Exception("wrong object label");
|
||||||
|
|
||||||
Klass k2 = li_std_auto_ptr.makeKlassAutoPtr("second");
|
Klass k2 = li_std_auto_ptr.makeKlassAutoPtr("second");
|
||||||
if (Klass.getTotal_count() != 2)
|
checkCount(2);
|
||||||
throw new Exception("number of objects should be 2");
|
|
||||||
|
|
||||||
using (Klass k3 = li_std_auto_ptr.makeKlassAutoPtr("second")) {
|
using (Klass k3 = li_std_auto_ptr.makeKlassAutoPtr("second")) {
|
||||||
if (Klass.getTotal_count() != 3)
|
checkCount(3);
|
||||||
throw new Exception("number of objects should be 3");
|
|
||||||
}
|
}
|
||||||
if (Klass.getTotal_count() != 2)
|
checkCount(2);
|
||||||
throw new Exception("number of objects should be 2");
|
|
||||||
|
|
||||||
|
k1.Dispose();
|
||||||
k1 = null;
|
k1 = null;
|
||||||
{
|
checkCount(1);
|
||||||
int countdown = 500;
|
|
||||||
int expectedCount = 1;
|
|
||||||
while (true) {
|
|
||||||
WaitForGC();
|
|
||||||
if (--countdown == 0)
|
|
||||||
break;
|
|
||||||
if (Klass.getTotal_count() == expectedCount)
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
int actualCount = Klass.getTotal_count();
|
|
||||||
if (actualCount != expectedCount)
|
|
||||||
Console.Error.WriteLine("Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't
|
|
||||||
}
|
|
||||||
|
|
||||||
if (k2.getLabel() != "second")
|
if (k2.getLabel() != "second")
|
||||||
throw new Exception("wrong object label");
|
throw new Exception("wrong object label");
|
||||||
|
|
||||||
|
k2.Dispose();
|
||||||
k2 = null;
|
k2 = null;
|
||||||
{
|
checkCount(0);
|
||||||
int countdown = 500;
|
|
||||||
int expectedCount = 0;
|
|
||||||
while (true) {
|
|
||||||
WaitForGC();
|
|
||||||
if (--countdown == 0)
|
|
||||||
break;
|
|
||||||
if (Klass.getTotal_count() == expectedCount)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
int actualCount = Klass.getTotal_count();
|
|
||||||
if (actualCount != expectedCount)
|
|
||||||
Console.Error.WriteLine("Expected count: " + expectedCount + " Actual count: " + actualCount); // Finalizers are not guaranteed to be run and sometimes they just don't
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,17 +93,14 @@ void main() {
|
||||||
throw new Exception("wrong object label");
|
throw new Exception("wrong object label");
|
||||||
|
|
||||||
Klass k2 = makeKlassUniquePtr("second");
|
Klass k2 = makeKlassUniquePtr("second");
|
||||||
if (Klass.getTotal_count() != 2)
|
checkCount(2);
|
||||||
throw new Exception("number of objects should be 2");
|
|
||||||
|
|
||||||
k1.dispose();
|
k1.dispose();
|
||||||
if (Klass.getTotal_count() != 1)
|
checkCount(1);
|
||||||
throw new Exception("number of objects should be 1");
|
|
||||||
|
|
||||||
if (k2.getLabel() != "second")
|
if (k2.getLabel() != "second")
|
||||||
throw new Exception("wrong object label");
|
throw new Exception("wrong object label");
|
||||||
|
|
||||||
k2.dispose();
|
k2.dispose();
|
||||||
if (Klass.getTotal_count() != 0)
|
checkCount(0);
|
||||||
throw new Exception("no objects should be left");
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,17 +93,14 @@ void main() {
|
||||||
throw new Exception("wrong object label");
|
throw new Exception("wrong object label");
|
||||||
|
|
||||||
Klass k2 = makeKlassUniquePtr("second");
|
Klass k2 = makeKlassUniquePtr("second");
|
||||||
if (Klass.getTotal_count() != 2)
|
checkCount(2);
|
||||||
throw new Exception("number of objects should be 2");
|
|
||||||
|
|
||||||
k1.dispose();
|
k1.dispose();
|
||||||
if (Klass.getTotal_count() != 1)
|
checkCount(1);
|
||||||
throw new Exception("number of objects should be 1");
|
|
||||||
|
|
||||||
if (k2.getLabel() != "second")
|
if (k2.getLabel() != "second")
|
||||||
throw new Exception("wrong object label");
|
throw new Exception("wrong object label");
|
||||||
|
|
||||||
k2.dispose();
|
k2.dispose();
|
||||||
if (Klass.getTotal_count() != 0)
|
checkCount(0);
|
||||||
throw new Exception("no objects should be left");
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -93,17 +93,14 @@ void main() {
|
||||||
throw new Exception("wrong object label");
|
throw new Exception("wrong object label");
|
||||||
|
|
||||||
Klass k2 = makeKlassAutoPtr("second");
|
Klass k2 = makeKlassAutoPtr("second");
|
||||||
if (Klass.getTotal_count() != 2)
|
checkCount(2);
|
||||||
throw new Exception("number of objects should be 2");
|
|
||||||
|
|
||||||
k1.dispose();
|
k1.dispose();
|
||||||
if (Klass.getTotal_count() != 1)
|
checkCount(1);
|
||||||
throw new Exception("number of objects should be 1");
|
|
||||||
|
|
||||||
if (k2.getLabel() != "second")
|
if (k2.getLabel() != "second")
|
||||||
throw new Exception("wrong object label");
|
throw new Exception("wrong object label");
|
||||||
|
|
||||||
k2.dispose();
|
k2.dispose();
|
||||||
if (Klass.getTotal_count() != 0)
|
checkCount(0);
|
||||||
throw new Exception("no objects should be left");
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ void main() {
|
||||||
scope KlassInheritance kini = new KlassInheritance("KlassInheritanceInput");
|
scope KlassInheritance kini = new KlassInheritance("KlassInheritanceInput");
|
||||||
checkCount(1);
|
checkCount(1);
|
||||||
string s = useKlassRawPtr(kini);
|
string s = useKlassRawPtr(kini);
|
||||||
checkCount(1);
|
|
||||||
if (s != "KlassInheritanceInput")
|
if (s != "KlassInheritanceInput")
|
||||||
throw new Exception("Incorrect string: " ~ s);
|
throw new Exception("Incorrect string: " ~ s);
|
||||||
}
|
}
|
||||||
|
|
@ -94,17 +93,14 @@ void main() {
|
||||||
throw new Exception("wrong object label");
|
throw new Exception("wrong object label");
|
||||||
|
|
||||||
Klass k2 = makeKlassAutoPtr("second");
|
Klass k2 = makeKlassAutoPtr("second");
|
||||||
if (Klass.getTotal_count() != 2)
|
checkCount(2);
|
||||||
throw new Exception("number of objects should be 2");
|
|
||||||
|
|
||||||
k1.dispose();
|
k1.dispose();
|
||||||
if (Klass.getTotal_count() != 1)
|
checkCount(1);
|
||||||
throw new Exception("number of objects should be 1");
|
|
||||||
|
|
||||||
if (k2.getLabel() != "second")
|
if (k2.getLabel() != "second")
|
||||||
throw new Exception("wrong object label");
|
throw new Exception("wrong object label");
|
||||||
|
|
||||||
k2.dispose();
|
k2.dispose();
|
||||||
if (Klass.getTotal_count() != 0)
|
checkCount(0);
|
||||||
throw new Exception("no objects should be left");
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,17 @@ public class cpp11_std_unique_ptr_runme {
|
||||||
|
|
||||||
public static void main(String argv[]) throws Throwable
|
public static void main(String argv[]) throws Throwable
|
||||||
{
|
{
|
||||||
|
// Test raw pointer handling involving virtual inheritance
|
||||||
|
{
|
||||||
|
KlassInheritance kini = new KlassInheritance("KlassInheritanceInput");
|
||||||
|
checkCount(1);
|
||||||
|
String s = cpp11_std_unique_ptr.useKlassRawPtr(kini);
|
||||||
|
if (!s.equals("KlassInheritanceInput"))
|
||||||
|
throw new RuntimeException("Incorrect string: " + s);
|
||||||
|
kini.delete();
|
||||||
|
checkCount(0);
|
||||||
|
}
|
||||||
|
|
||||||
// unique_ptr as input
|
// unique_ptr as input
|
||||||
{
|
{
|
||||||
Klass kin = new Klass("KlassInput");
|
Klass kin = new Klass("KlassInput");
|
||||||
|
|
@ -102,42 +113,17 @@ public class cpp11_std_unique_ptr_runme {
|
||||||
throw new RuntimeException("wrong object label");
|
throw new RuntimeException("wrong object label");
|
||||||
|
|
||||||
Klass k2 = cpp11_std_unique_ptr.makeKlassUniquePtr("second");
|
Klass k2 = cpp11_std_unique_ptr.makeKlassUniquePtr("second");
|
||||||
if (Klass.getTotal_count() != 2)
|
checkCount(2);
|
||||||
throw new RuntimeException("number of objects should be 2");
|
|
||||||
|
|
||||||
|
k1.delete();
|
||||||
k1 = null;
|
k1 = null;
|
||||||
{
|
checkCount(1);
|
||||||
int countdown = 500;
|
|
||||||
int expectedCount = 1;
|
|
||||||
while (true) {
|
|
||||||
WaitForGC();
|
|
||||||
if (--countdown == 0)
|
|
||||||
break;
|
|
||||||
if (Klass.getTotal_count() == expectedCount)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
int actualCount = Klass.getTotal_count();
|
|
||||||
if (actualCount != expectedCount)
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!k2.getLabel().equals("second"))
|
if (!k2.getLabel().equals("second"))
|
||||||
throw new RuntimeException("wrong object label");
|
throw new RuntimeException("wrong object label");
|
||||||
|
|
||||||
|
k2.delete();
|
||||||
k2 = null;
|
k2 = null;
|
||||||
{
|
checkCount(0);
|
||||||
int countdown = 500;
|
|
||||||
int expectedCount = 0;
|
|
||||||
while (true) {
|
|
||||||
WaitForGC();
|
|
||||||
if (--countdown == 0)
|
|
||||||
break;
|
|
||||||
if (Klass.getTotal_count() == expectedCount)
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
int actualCount = Klass.getTotal_count();
|
|
||||||
if (actualCount != expectedCount)
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,17 @@ public class li_std_auto_ptr_runme {
|
||||||
|
|
||||||
public static void main(String argv[]) throws Throwable
|
public static void main(String argv[]) throws Throwable
|
||||||
{
|
{
|
||||||
|
// Test raw pointer handling involving virtual inheritance
|
||||||
|
{
|
||||||
|
KlassInheritance kini = new KlassInheritance("KlassInheritanceInput");
|
||||||
|
checkCount(1);
|
||||||
|
String s = li_std_auto_ptr.useKlassRawPtr(kini);
|
||||||
|
if (!s.equals("KlassInheritanceInput"))
|
||||||
|
throw new RuntimeException("Incorrect string: " + s);
|
||||||
|
kini.delete();
|
||||||
|
checkCount(0);
|
||||||
|
}
|
||||||
|
|
||||||
// auto_ptr as input
|
// auto_ptr as input
|
||||||
{
|
{
|
||||||
Klass kin = new Klass("KlassInput");
|
Klass kin = new Klass("KlassInput");
|
||||||
|
|
@ -102,42 +113,17 @@ public class li_std_auto_ptr_runme {
|
||||||
throw new RuntimeException("wrong object label");
|
throw new RuntimeException("wrong object label");
|
||||||
|
|
||||||
Klass k2 = li_std_auto_ptr.makeKlassAutoPtr("second");
|
Klass k2 = li_std_auto_ptr.makeKlassAutoPtr("second");
|
||||||
if (Klass.getTotal_count() != 2)
|
checkCount(2);
|
||||||
throw new RuntimeException("number of objects should be 2");
|
|
||||||
|
|
||||||
|
k1.delete();
|
||||||
k1 = null;
|
k1 = null;
|
||||||
{
|
checkCount(1);
|
||||||
int countdown = 500;
|
|
||||||
int expectedCount = 1;
|
|
||||||
while (true) {
|
|
||||||
WaitForGC();
|
|
||||||
if (--countdown == 0)
|
|
||||||
break;
|
|
||||||
if (Klass.getTotal_count() == expectedCount)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
int actualCount = Klass.getTotal_count();
|
|
||||||
if (actualCount != expectedCount)
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!k2.getLabel().equals("second"))
|
if (!k2.getLabel().equals("second"))
|
||||||
throw new RuntimeException("wrong object label");
|
throw new RuntimeException("wrong object label");
|
||||||
|
|
||||||
|
k2.delete();
|
||||||
k2 = null;
|
k2 = null;
|
||||||
{
|
checkCount(0);
|
||||||
int countdown = 500;
|
|
||||||
int expectedCount = 0;
|
|
||||||
while (true) {
|
|
||||||
WaitForGC();
|
|
||||||
if (--countdown == 0)
|
|
||||||
break;
|
|
||||||
if (Klass.getTotal_count() == expectedCount)
|
|
||||||
break;
|
|
||||||
};
|
|
||||||
int actualCount = Klass.getTotal_count();
|
|
||||||
if (actualCount != expectedCount)
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,20 @@ var checkCount = function(expected_count) {
|
||||||
throw new Error("Counts incorrect, expected:" + expected_count + " actual:" + actual_count);
|
throw new Error("Counts incorrect, expected:" + expected_count + " actual:" + actual_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test raw pointer handling involving virtual inheritance
|
||||||
|
{
|
||||||
|
kini = new cpp11_std_unique_ptr.KlassInheritance("KlassInheritanceInput");
|
||||||
|
checkCount(1);
|
||||||
|
s = cpp11_std_unique_ptr.useKlassRawPtr(kini);
|
||||||
|
if (s !== "KlassInheritanceInput")
|
||||||
|
throw new Error("Incorrect string: " + s);
|
||||||
|
// delete kini;
|
||||||
|
// Above not deleting the C++ object(node v12) - can't reliably control GC
|
||||||
|
cpp11_std_unique_ptr.takeKlassUniquePtr(kini);
|
||||||
|
checkCount(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// unique_ptr as input
|
// unique_ptr as input
|
||||||
{
|
{
|
||||||
kin = new cpp11_std_unique_ptr.Klass("KlassInput");
|
kin = new cpp11_std_unique_ptr.Klass("KlassInput");
|
||||||
|
|
@ -82,14 +96,12 @@ if (k1.getLabel() !== "first")
|
||||||
throw new Error("wrong object label");
|
throw new Error("wrong object label");
|
||||||
|
|
||||||
k2 = cpp11_std_unique_ptr.makeKlassUniquePtr("second");
|
k2 = cpp11_std_unique_ptr.makeKlassUniquePtr("second");
|
||||||
if (cpp11_std_unique_ptr.Klass.getTotal_count() != 2)
|
checkCount(2);
|
||||||
throw new Error("number of objects should be 2");
|
|
||||||
|
|
||||||
// delete k1;
|
// delete k1;
|
||||||
// Above not deleting the C++ object(node v12), not sure why, use below as workaround
|
// Above not deleting the C++ object(node v12) - can't reliably control GC
|
||||||
cpp11_std_unique_ptr.takeKlassUniquePtr(k1);
|
cpp11_std_unique_ptr.takeKlassUniquePtr(k1);
|
||||||
if (cpp11_std_unique_ptr.Klass.getTotal_count() != 1)
|
checkCount(1);
|
||||||
throw new Error("number of objects should be 1");
|
|
||||||
|
|
||||||
if (k2.getLabel() !== "second")
|
if (k2.getLabel() !== "second")
|
||||||
throw new Error("wrong object label");
|
throw new Error("wrong object label");
|
||||||
|
|
@ -97,5 +109,4 @@ if (k2.getLabel() !== "second")
|
||||||
// delete k2;
|
// delete k2;
|
||||||
// Above not deleting the C++ object(node v12) - can't reliably control GC
|
// Above not deleting the C++ object(node v12) - can't reliably control GC
|
||||||
cpp11_std_unique_ptr.takeKlassUniquePtr(k2);
|
cpp11_std_unique_ptr.takeKlassUniquePtr(k2);
|
||||||
if (cpp11_std_unique_ptr.Klass.getTotal_count() != 0)
|
checkCount(0);
|
||||||
throw new Error("no objects should be left");
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,20 @@ var checkCount = function(expected_count) {
|
||||||
throw new Error("Counts incorrect, expected:" + expected_count + " actual:" + actual_count);
|
throw new Error("Counts incorrect, expected:" + expected_count + " actual:" + actual_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test raw pointer handling involving virtual inheritance
|
||||||
|
{
|
||||||
|
kini = new li_std_auto_ptr.KlassInheritance("KlassInheritanceInput");
|
||||||
|
checkCount(1);
|
||||||
|
s = li_std_auto_ptr.useKlassRawPtr(kini);
|
||||||
|
if (s !== "KlassInheritanceInput")
|
||||||
|
throw new Error("Incorrect string: " + s);
|
||||||
|
// delete kini;
|
||||||
|
// Above not deleting the C++ object(node v12) - can't reliably control GC
|
||||||
|
li_std_auto_ptr.takeKlassAutoPtr(kini);
|
||||||
|
checkCount(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// auto_ptr as input
|
// auto_ptr as input
|
||||||
{
|
{
|
||||||
kin = new li_std_auto_ptr.Klass("KlassInput");
|
kin = new li_std_auto_ptr.Klass("KlassInput");
|
||||||
|
|
@ -82,14 +96,12 @@ if (k1.getLabel() !== "first")
|
||||||
throw new Error("wrong object label");
|
throw new Error("wrong object label");
|
||||||
|
|
||||||
k2 = li_std_auto_ptr.makeKlassAutoPtr("second");
|
k2 = li_std_auto_ptr.makeKlassAutoPtr("second");
|
||||||
if (li_std_auto_ptr.Klass.getTotal_count() != 2)
|
checkCount(2);
|
||||||
throw new Error("number of objects should be 2");
|
|
||||||
|
|
||||||
// delete k1;
|
// delete k1;
|
||||||
// Above not deleting the C++ object(node v12), not sure why, use below as workaround
|
// Above not deleting the C++ object(node v12) - can't reliably control GC
|
||||||
li_std_auto_ptr.takeKlassAutoPtr(k1);
|
li_std_auto_ptr.takeKlassAutoPtr(k1);
|
||||||
if (li_std_auto_ptr.Klass.getTotal_count() != 1)
|
checkCount(1);
|
||||||
throw new Error("number of objects should be 1");
|
|
||||||
|
|
||||||
if (k2.getLabel() !== "second")
|
if (k2.getLabel() !== "second")
|
||||||
throw new Error("wrong object label");
|
throw new Error("wrong object label");
|
||||||
|
|
@ -97,5 +109,4 @@ if (k2.getLabel() !== "second")
|
||||||
// delete k2;
|
// delete k2;
|
||||||
// Above not deleting the C++ object(node v12) - can't reliably control GC
|
// Above not deleting the C++ object(node v12) - can't reliably control GC
|
||||||
li_std_auto_ptr.takeKlassAutoPtr(k2);
|
li_std_auto_ptr.takeKlassAutoPtr(k2);
|
||||||
if (li_std_auto_ptr.Klass.getTotal_count() != 0)
|
checkCount(0);
|
||||||
throw new Error("no objects should be left");
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,16 @@ function checkCount(expected_count)
|
||||||
endif
|
endif
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Test raw pointer handling involving virtual inheritance
|
||||||
|
kini = KlassInheritance("KlassInheritanceInput");
|
||||||
|
checkCount(1);
|
||||||
|
s = takeKlassUniquePtr(kini);
|
||||||
|
if (!strcmp(s, "KlassInheritanceInput"))
|
||||||
|
error("Incorrect string: %s", s);
|
||||||
|
endif
|
||||||
|
clear kini;
|
||||||
|
checkCount(0);
|
||||||
|
|
||||||
|
|
||||||
# unique_ptr as input
|
# unique_ptr as input
|
||||||
kin = Klass("KlassInput");
|
kin = Klass("KlassInput");
|
||||||
|
|
@ -91,20 +101,14 @@ if (!strcmp(k1.getLabel(), "first"))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
k2 = makeKlassUniquePtr("second");
|
k2 = makeKlassUniquePtr("second");
|
||||||
if (Klass_getTotal_count() != 2)
|
checkCount(2);
|
||||||
error("number of objects should be 2");
|
|
||||||
endif
|
|
||||||
|
|
||||||
clear k1;
|
clear k1;
|
||||||
if (Klass.getTotal_count() != 1)
|
checkCount(1);
|
||||||
error("number of objects should be 1");
|
|
||||||
endif
|
|
||||||
|
|
||||||
if (!strcmp(k2.getLabel(), "second"))
|
if (!strcmp(k2.getLabel(), "second"))
|
||||||
error("wrong object label");
|
error("wrong object label");
|
||||||
endif
|
endif
|
||||||
|
|
||||||
clear k2;
|
clear k2;
|
||||||
if (Klass.getTotal_count() != 0)
|
checkCount(0);
|
||||||
error("no objects should be left");
|
|
||||||
endif
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,17 @@ function checkCount(expected_count)
|
||||||
endif
|
endif
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Test raw pointer handling involving virtual inheritance
|
||||||
|
kini = KlassInheritance("KlassInheritanceInput");
|
||||||
|
checkCount(1);
|
||||||
|
s = takeKlassAutoPtr(kini);
|
||||||
|
if (!strcmp(s, "KlassInheritanceInput"))
|
||||||
|
error("Incorrect string: %s", s);
|
||||||
|
endif
|
||||||
|
clear kini;
|
||||||
|
checkCount(0);
|
||||||
|
|
||||||
|
|
||||||
# auto_ptr as input
|
# auto_ptr as input
|
||||||
kin = Klass("KlassInput");
|
kin = Klass("KlassInput");
|
||||||
checkCount(1);
|
checkCount(1);
|
||||||
|
|
@ -90,20 +101,14 @@ if (!strcmp(k1.getLabel(), "first"))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
k2 = makeKlassAutoPtr("second");
|
k2 = makeKlassAutoPtr("second");
|
||||||
if (Klass_getTotal_count() != 2)
|
checkCount(2);
|
||||||
error("number of objects should be 2");
|
|
||||||
endif
|
|
||||||
|
|
||||||
clear k1;
|
clear k1;
|
||||||
if (Klass.getTotal_count() != 1)
|
checkCount(1);
|
||||||
error("number of objects should be 1");
|
|
||||||
endif
|
|
||||||
|
|
||||||
if (!strcmp(k2.getLabel(), "second"))
|
if (!strcmp(k2.getLabel(), "second"))
|
||||||
error("wrong object label");
|
error("wrong object label");
|
||||||
endif
|
endif
|
||||||
|
|
||||||
clear k2;
|
clear k2;
|
||||||
if (Klass.getTotal_count() != 0)
|
checkCount(0);
|
||||||
error("no objects should be left");
|
|
||||||
endif
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Test::More tests => 25;
|
use Test::More tests => 28;
|
||||||
BEGIN { use_ok('cpp11_std_unique_ptr') }
|
BEGIN { use_ok('cpp11_std_unique_ptr') }
|
||||||
require_ok('cpp11_std_unique_ptr');
|
require_ok('cpp11_std_unique_ptr');
|
||||||
|
|
||||||
|
|
@ -12,6 +12,17 @@ sub checkCount {
|
||||||
is($actual_count, $expected_count, "Counts incorrect, expected: $expected_count actual: $actual_count");
|
is($actual_count, $expected_count, "Counts incorrect, expected: $expected_count actual: $actual_count");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Test raw pointer handling involving virtual inheritance
|
||||||
|
{
|
||||||
|
my $kini = new cpp11_std_unique_ptr::KlassInheritance("KlassInheritanceInput");
|
||||||
|
checkCount(1);
|
||||||
|
my $s = cpp11_std_unique_ptr::takeKlassUniquePtr($kini);
|
||||||
|
is($s, "KlassInheritanceInput", "Incorrect string: $s");
|
||||||
|
undef $kini;
|
||||||
|
checkCount(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# unique_ptr as input
|
# unique_ptr as input
|
||||||
{
|
{
|
||||||
my $kin = new cpp11_std_unique_ptr::Klass("KlassInput");
|
my $kin = new cpp11_std_unique_ptr::Klass("KlassInput");
|
||||||
|
|
@ -65,12 +76,12 @@ sub checkCount {
|
||||||
# unique_ptr as output
|
# unique_ptr as output
|
||||||
my $k1 = cpp11_std_unique_ptr::makeKlassUniquePtr("first");
|
my $k1 = cpp11_std_unique_ptr::makeKlassUniquePtr("first");
|
||||||
my $k2 = cpp11_std_unique_ptr::makeKlassUniquePtr("second");
|
my $k2 = cpp11_std_unique_ptr::makeKlassUniquePtr("second");
|
||||||
is(cpp11_std_unique_ptr::Klass::getTotal_count, 2, "have 2 pointers");
|
checkCount(2);
|
||||||
|
|
||||||
undef $k1;
|
undef $k1;
|
||||||
is(cpp11_std_unique_ptr::Klass::getTotal_count, 1, "left 1 pointer");
|
checkCount(1);
|
||||||
|
|
||||||
is($k2->getLabel, "second", "proper label");
|
is($k2->getLabel, "second", "proper label");
|
||||||
|
|
||||||
undef $k2;
|
undef $k2;
|
||||||
is(cpp11_std_unique_ptr::Klass::getTotal_count, 0, "remove all pointers");
|
checkCount(0);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Test::More tests => 25;
|
use Test::More tests => 28;
|
||||||
BEGIN { use_ok('li_std_auto_ptr') }
|
BEGIN { use_ok('li_std_auto_ptr') }
|
||||||
require_ok('li_std_auto_ptr');
|
require_ok('li_std_auto_ptr');
|
||||||
|
|
||||||
|
|
@ -12,6 +12,17 @@ sub checkCount {
|
||||||
is($actual_count, $expected_count, "Counts incorrect, expected: $expected_count actual: $actual_count");
|
is($actual_count, $expected_count, "Counts incorrect, expected: $expected_count actual: $actual_count");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Test raw pointer handling involving virtual inheritance
|
||||||
|
{
|
||||||
|
my $kini = new li_std_auto_ptr::KlassInheritance("KlassInheritanceInput");
|
||||||
|
checkCount(1);
|
||||||
|
my $s = li_std_auto_ptr::takeKlassAutoPtr($kini);
|
||||||
|
is($s, "KlassInheritanceInput", "Incorrect string: $s");
|
||||||
|
undef $kini;
|
||||||
|
checkCount(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# auto_ptr as input
|
# auto_ptr as input
|
||||||
{
|
{
|
||||||
my $kin = new li_std_auto_ptr::Klass("KlassInput");
|
my $kin = new li_std_auto_ptr::Klass("KlassInput");
|
||||||
|
|
@ -65,12 +76,12 @@ sub checkCount {
|
||||||
# auto_ptr as output
|
# auto_ptr as output
|
||||||
my $k1 = li_std_auto_ptr::makeKlassAutoPtr("first");
|
my $k1 = li_std_auto_ptr::makeKlassAutoPtr("first");
|
||||||
my $k2 = li_std_auto_ptr::makeKlassAutoPtr("second");
|
my $k2 = li_std_auto_ptr::makeKlassAutoPtr("second");
|
||||||
is(li_std_auto_ptr::Klass::getTotal_count, 2, "have 2 pointers");
|
checkCount(2);
|
||||||
|
|
||||||
undef $k1;
|
undef $k1;
|
||||||
is(li_std_auto_ptr::Klass::getTotal_count, 1, "left 1 pointer");
|
checkCount(1);
|
||||||
|
|
||||||
is($k2->getLabel, "second", "proper label");
|
is($k2->getLabel, "second", "proper label");
|
||||||
|
|
||||||
undef $k2;
|
undef $k2;
|
||||||
is(li_std_auto_ptr::Klass::getTotal_count, 0, "remove all pointers");
|
checkCount(0);
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,16 @@ def checkCount(expected_count):
|
||||||
if (actual_count != expected_count):
|
if (actual_count != expected_count):
|
||||||
raise RuntimeError("Counts incorrect, expected:" + expected_count + " actual:" + actual_count)
|
raise RuntimeError("Counts incorrect, expected:" + expected_count + " actual:" + actual_count)
|
||||||
|
|
||||||
|
# Test raw pointer handling involving virtual inheritance
|
||||||
|
kini = KlassInheritance("KlassInheritanceInput")
|
||||||
|
checkCount(1)
|
||||||
|
s = takeKlassUniquePtr(kini)
|
||||||
|
if s != "KlassInheritanceInput":
|
||||||
|
raise RuntimeError("Incorrect string: " + s)
|
||||||
|
del kini
|
||||||
|
checkCount(0)
|
||||||
|
|
||||||
|
|
||||||
# unique_ptr as input
|
# unique_ptr as input
|
||||||
kin = Klass("KlassInput")
|
kin = Klass("KlassInput")
|
||||||
checkCount(1)
|
checkCount(1)
|
||||||
|
|
@ -70,16 +80,13 @@ checkCount(0)
|
||||||
# unique_ptr as output
|
# unique_ptr as output
|
||||||
k1 = makeKlassUniquePtr("first")
|
k1 = makeKlassUniquePtr("first")
|
||||||
k2 = makeKlassUniquePtr("second")
|
k2 = makeKlassUniquePtr("second")
|
||||||
if Klass.getTotal_count() != 2:
|
checkCount(2)
|
||||||
raise "number of objects should be 2"
|
|
||||||
|
|
||||||
del k1
|
del k1
|
||||||
if Klass.getTotal_count() != 1:
|
checkCount(1)
|
||||||
raise "number of objects should be 1"
|
|
||||||
|
|
||||||
if k2.getLabel() != "second":
|
if k2.getLabel() != "second":
|
||||||
raise "wrong object label"
|
raise "wrong object label"
|
||||||
|
|
||||||
del k2
|
del k2
|
||||||
if Klass.getTotal_count() != 0:
|
checkCount(0)
|
||||||
raise "no objects should be left"
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,16 @@ def checkCount(expected_count):
|
||||||
if (actual_count != expected_count):
|
if (actual_count != expected_count):
|
||||||
raise RuntimeError("Counts incorrect, expected:" + expected_count + " actual:" + actual_count)
|
raise RuntimeError("Counts incorrect, expected:" + expected_count + " actual:" + actual_count)
|
||||||
|
|
||||||
|
# Test raw pointer handling involving virtual inheritance
|
||||||
|
kini = KlassInheritance("KlassInheritanceInput")
|
||||||
|
checkCount(1)
|
||||||
|
s = takeKlassAutoPtr(kini)
|
||||||
|
if s != "KlassInheritanceInput":
|
||||||
|
raise RuntimeError("Incorrect string: " + s)
|
||||||
|
del kini
|
||||||
|
checkCount(0)
|
||||||
|
|
||||||
|
|
||||||
# auto_ptr as input
|
# auto_ptr as input
|
||||||
kin = Klass("KlassInput")
|
kin = Klass("KlassInput")
|
||||||
checkCount(1)
|
checkCount(1)
|
||||||
|
|
@ -70,16 +80,13 @@ checkCount(0)
|
||||||
# auto_ptr as output
|
# auto_ptr as output
|
||||||
k1 = makeKlassAutoPtr("first")
|
k1 = makeKlassAutoPtr("first")
|
||||||
k2 = makeKlassAutoPtr("second")
|
k2 = makeKlassAutoPtr("second")
|
||||||
if Klass.getTotal_count() != 2:
|
checkCount(2)
|
||||||
raise "number of objects should be 2"
|
|
||||||
|
|
||||||
del k1
|
del k1
|
||||||
if Klass.getTotal_count() != 1:
|
checkCount(1)
|
||||||
raise "number of objects should be 1"
|
|
||||||
|
|
||||||
if k2.getLabel() != "second":
|
if k2.getLabel() != "second":
|
||||||
raise "wrong object label"
|
raise "wrong object label"
|
||||||
|
|
||||||
del k2
|
del k2
|
||||||
if Klass.getTotal_count() != 0:
|
checkCount(0)
|
||||||
raise "no objects should be left"
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,16 @@ def checkCount(expected_count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Test raw pointer handling involving virtual inheritance
|
||||||
|
kini = Cpp11_std_unique_ptr::KlassInheritance.new("KlassInheritanceInput")
|
||||||
|
checkCount(1)
|
||||||
|
s = Cpp11_std_unique_ptr.takeKlassUniquePtr(kini)
|
||||||
|
if (s != "KlassInheritanceInput")
|
||||||
|
raise RuntimeError, "Incorrect string: " + s
|
||||||
|
end
|
||||||
|
kini = nil
|
||||||
|
checkCount(0)
|
||||||
|
|
||||||
|
|
||||||
# unique_ptr as input
|
# unique_ptr as input
|
||||||
kin = Cpp11_std_unique_ptr::Klass.new("KlassInput")
|
kin = Cpp11_std_unique_ptr::Klass.new("KlassInput")
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,16 @@ def checkCount(expected_count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Test raw pointer handling involving virtual inheritance
|
||||||
|
kini = Li_std_auto_ptr::KlassInheritance.new("KlassInheritanceInput")
|
||||||
|
checkCount(1)
|
||||||
|
s = Li_std_auto_ptr.takeKlassAutoPtr(kini)
|
||||||
|
if (s != "KlassInheritanceInput")
|
||||||
|
raise RuntimeError, "Incorrect string: " + s
|
||||||
|
end
|
||||||
|
kini = nil
|
||||||
|
checkCount(0)
|
||||||
|
|
||||||
|
|
||||||
# auto_ptr as input
|
# auto_ptr as input
|
||||||
kin = Li_std_auto_ptr::Klass.new("KlassInput")
|
kin = Li_std_auto_ptr::Klass.new("KlassInput")
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,13 @@ $k4 -delete
|
||||||
checkCount 0
|
checkCount 0
|
||||||
################################# Tcl pointer recycling bug end
|
################################# Tcl pointer recycling bug end
|
||||||
|
|
||||||
|
# Test raw pointer handling involving virtual inheritance
|
||||||
|
KlassInheritance kini "KlassInheritanceInput"
|
||||||
|
checkCount 1
|
||||||
|
set s [takeKlassUniquePtr kini]
|
||||||
|
kini -delete
|
||||||
|
checkCount 0
|
||||||
|
|
||||||
|
|
||||||
# unique_ptr as input
|
# unique_ptr as input
|
||||||
Klass kin "KlassInput"
|
Klass kin "KlassInput"
|
||||||
|
|
@ -122,20 +129,14 @@ checkCount 0
|
||||||
# unique_ptr as output
|
# unique_ptr as output
|
||||||
set k1 [makeKlassUniquePtr "first"]
|
set k1 [makeKlassUniquePtr "first"]
|
||||||
set k2 [makeKlassUniquePtr "second"]
|
set k2 [makeKlassUniquePtr "second"]
|
||||||
if {[Klass_getTotal_count] != 2} {
|
checkCount 2
|
||||||
error "number of objects should be 2"
|
|
||||||
}
|
|
||||||
|
|
||||||
$k1 -delete
|
$k1 -delete
|
||||||
if {[Klass_getTotal_count] != 1} {
|
checkCount 1
|
||||||
error "number of objects should be 1"
|
|
||||||
}
|
|
||||||
|
|
||||||
if {[$k2 getLabel] != "second"} {
|
if {[$k2 getLabel] != "second"} {
|
||||||
error "wrong object label"
|
error "wrong object label"
|
||||||
}
|
}
|
||||||
|
|
||||||
$k2 -delete
|
$k2 -delete
|
||||||
if {[Klass_getTotal_count] != 0} {
|
checkCount 0
|
||||||
error "no objects should be left"
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,13 @@ proc checkCount {expected_count} {
|
||||||
# Not copied from cpp11_std_unique_ptr_runme.tcl
|
# Not copied from cpp11_std_unique_ptr_runme.tcl
|
||||||
################################# Tcl pointer recycling bug end
|
################################# Tcl pointer recycling bug end
|
||||||
|
|
||||||
|
# Test raw pointer handling involving virtual inheritance
|
||||||
|
KlassInheritance kini "KlassInheritanceInput"
|
||||||
|
checkCount 1
|
||||||
|
set s [takeKlassAutoPtr kini]
|
||||||
|
kini -delete
|
||||||
|
checkCount 0
|
||||||
|
|
||||||
|
|
||||||
# auto_ptr as input
|
# auto_ptr as input
|
||||||
Klass kin "KlassInput"
|
Klass kin "KlassInput"
|
||||||
|
|
@ -93,20 +100,14 @@ checkCount 0
|
||||||
# auto_ptr as output
|
# auto_ptr as output
|
||||||
set k1 [makeKlassAutoPtr "first"]
|
set k1 [makeKlassAutoPtr "first"]
|
||||||
set k2 [makeKlassAutoPtr "second"]
|
set k2 [makeKlassAutoPtr "second"]
|
||||||
if {[Klass_getTotal_count] != 2} {
|
checkCount 2
|
||||||
error "number of objects should be 2"
|
|
||||||
}
|
|
||||||
|
|
||||||
$k1 -delete
|
$k1 -delete
|
||||||
if {[Klass_getTotal_count] != 1} {
|
checkCount 1
|
||||||
error "number of objects should be 1"
|
|
||||||
}
|
|
||||||
|
|
||||||
if {[$k2 getLabel] != "second"} {
|
if {[$k2 getLabel] != "second"} {
|
||||||
error "wrong object label"
|
error "wrong object label"
|
||||||
}
|
}
|
||||||
|
|
||||||
$k2 -delete
|
$k2 -delete
|
||||||
if {[Klass_getTotal_count] != 0} {
|
checkCount 0
|
||||||
error "no objects should be left"
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue