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

@ -6,6 +6,20 @@ var checkCount = function(expected_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
{
kin = new cpp11_std_unique_ptr.Klass("KlassInput");
@ -82,14 +96,12 @@ if (k1.getLabel() !== "first")
throw new Error("wrong object label");
k2 = cpp11_std_unique_ptr.makeKlassUniquePtr("second");
if (cpp11_std_unique_ptr.Klass.getTotal_count() != 2)
throw new Error("number of objects should be 2");
checkCount(2);
// 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);
if (cpp11_std_unique_ptr.Klass.getTotal_count() != 1)
throw new Error("number of objects should be 1");
checkCount(1);
if (k2.getLabel() !== "second")
throw new Error("wrong object label");
@ -97,5 +109,4 @@ if (k2.getLabel() !== "second")
// delete k2;
// Above not deleting the C++ object(node v12) - can't reliably control GC
cpp11_std_unique_ptr.takeKlassUniquePtr(k2);
if (cpp11_std_unique_ptr.Klass.getTotal_count() != 0)
throw new Error("no objects should be left");
checkCount(0);