Question

In a recent AdaCore Gem there's a statement

The implementation of Finalize is slightly more complicated: the Ada reference manual indicates that a Finalize procedure should always be idempotent. An Ada compiler is free to call Finalize multiple times on the same object, in particular when exceptions occur.

I need to test a privately controlled type,

   type T is private;
private
   type T is new Ada.Finalization.Controlled with ...

I can change the source to make the type visibly controlled

   type T is new Ada.Finalization.Controlled with private;

and then just call Finalize (My_T); (or even My_T.Finalize?); but is there any way I can cause multiple finalizations without this change to the software-under-test?

Was it helpful?

Solution

For the purpose of testing, I use a child package. It allows to tests the private part. Assuming your package is:

package A is
   type T is private;
private
   type T is new Ada.Finalization.Controlled with ...
end A;

I would test with something like:

package body A.Test is
   procedure Test_Finalize is
       My_T : T;
   begin
       My_T.Finalize;
   end Test_Finalize;
end A.Test;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top