7#include <gtest/gtest.h>
9#include "arccore/base/ReferenceCounter.h"
21 bool is_destroyed =
false;
26 bool checkValid(
int nb_call)
28 if (nb_add != nb_call) {
29 std::cout <<
"Bad nb_add n=" << nb_add <<
" expected=" << nb_call <<
"\n";
32 if (nb_remove != nb_call) {
33 std::cout <<
"Bad nb_remove n=" << nb_remove <<
" expected=" << nb_call <<
"\n";
56 Simple1(StatInfo* stat_info)
58 , m_stat_info(stat_info)
60 ~Simple1() { m_stat_info->is_destroyed =
true; }
67 ++m_stat_info->nb_add;
68 std::cout <<
"ADD REFERENCE r=" << m_nb_ref <<
"\n";
70 void removeReference()
73 ++m_stat_info->nb_remove;
74 std::cout <<
"REMOVE REFERENCE r=" << m_nb_ref <<
"\n";
76 std::cout <<
"DESTROY!\n";
81 StatInfo* m_stat_info;
88 Simple2(StatInfo* stat_info)
89 : m_stat_info(stat_info)
91 ~Simple2() { m_stat_info->is_destroyed =
true; }
95 StatInfo* m_stat_info;
101template <
typename RefType>
void
102_doTest1(
const RefType& ref_type)
107 RefType s1(ref_type);
125 _doTest1(Simple1Reference(
new Simple1(&stat_info)));
126 ASSERT_TRUE(stat_info.checkValid(4)) <<
"Bad destroy1";
139 ASSERT_TRUE(stat_info.checkValid(4)) <<
"Bad destroy2";
144 ASSERT_TRUE(stat_info.checkValid(0)) <<
"Bad destroy3";
162 virtual bool func1() = 0;
163 virtual void func2() = 0;
176 bool func1()
override {
return true; }
177 void func2()
override {}
181 Int32 m_padding4 = 0;
182 Int64 m_padding3 = 0;
193 using namespace Test1;
223 catch (
const std::exception& ex) {
224 std::cerr <<
"Exception ex=" << ex.what() <<
"\n";
#define ASSERT_FALSE(condition)
Checks that condition is false.
#define ASSERT_TRUE(condition)
Checks that condition is true.
#define ARCCORE_DECLARE_REFERENCE_COUNTED_INCLASS_METHODS()
Macro to declare the virtual methods managing reference counters.
#define ARCCORE_DECLARE_REFERENCE_COUNTED_CLASS(class_name)
Macro to declare that a class uses a reference counter.
#define ARCCORE_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS()
Macro to define methods managing counters of references.
Management of references to a C++ class.
Management of references to an external object.
void reset()
Positions the instance to the null pointer.
Reference to an instance.
static ThatClass createWithHandle(InstanceType *t, Internal::ExternalRef handle)
Creates a reference from an instance having an external reference.
Thread-safe implementation of a reference counter.
Encapsulation of a pointer with a reference counter.
Ref< TrueType > createRef(Args &&... args)
Creates an instance of type TrueType with arguments Args and returns a reference to it.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.
Structure used to tag interfaces/classes that use an internal reference counter.