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:
William S Fulton 2022-08-05 20:36:29 +01:00
commit d4b1152d4b
20 changed files with 236 additions and 224 deletions

View file

@ -18,6 +18,15 @@ public class cpp11_std_unique_ptr_runme {
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
using (Klass kin = new Klass("KlassInput")) {
checkCount(1);
@ -63,7 +72,7 @@ public class cpp11_std_unique_ptr_runme {
}
if (!exception_thrown)
throw new ApplicationException("Should have thrown 'Cannot release ownership as memory is not owned' error");
checkCount(1);
checkCount(1);
}
checkCount(0);
@ -84,49 +93,22 @@ public class cpp11_std_unique_ptr_runme {
throw new Exception("wrong object label");
Klass k2 = cpp11_std_unique_ptr.makeKlassUniquePtr("second");
if (Klass.getTotal_count() != 2)
throw new Exception("number of objects should be 2");
checkCount(2);
using (Klass k3 = cpp11_std_unique_ptr.makeKlassUniquePtr("second")) {
if (Klass.getTotal_count() != 3)
throw new Exception("number of objects should be 3");
checkCount(3);
}
if (Klass.getTotal_count() != 2)
throw new Exception("number of objects should be 2");
checkCount(2);
k1.Dispose();
k1 = null;
{
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
}
checkCount(1);
if (k2.getLabel() != "second")
throw new Exception("wrong object label");
k2.Dispose();
k2 = null;
{
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
}
checkCount(0);
}
}

View file

@ -18,6 +18,15 @@ public class li_std_auto_ptr_runme {
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
using (Klass kin = new Klass("KlassInput")) {
checkCount(1);
@ -84,49 +93,22 @@ public class li_std_auto_ptr_runme {
throw new Exception("wrong object label");
Klass k2 = li_std_auto_ptr.makeKlassAutoPtr("second");
if (Klass.getTotal_count() != 2)
throw new Exception("number of objects should be 2");
checkCount(2);
using (Klass k3 = li_std_auto_ptr.makeKlassAutoPtr("second")) {
if (Klass.getTotal_count() != 3)
throw new Exception("number of objects should be 3");
checkCount(3);
}
if (Klass.getTotal_count() != 2)
throw new Exception("number of objects should be 2");
checkCount(2);
k1.Dispose();
k1 = null;
{
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
}
checkCount(1);
if (k2.getLabel() != "second")
throw new Exception("wrong object label");
k2.Dispose();
k2 = null;
{
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
}
checkCount(0);
}
}