7#include <gtest/gtest.h>
9#include "arccore/base/ReferenceCounter.h"
21 bool is_destroyed =
false;
26 bool checkValid(
int 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";
53 Simple1(StatInfo* stat_info) : m_nb_ref(0), m_stat_info(stat_info){}
54 ~Simple1(){ m_stat_info->is_destroyed =
true; }
59 ++m_stat_info->nb_add;
60 std::cout <<
"ADD REFERENCE r=" << m_nb_ref <<
"\n";
62 void removeReference()
65 ++m_stat_info->nb_remove;
66 std::cout <<
"REMOVE REFERENCE r=" << m_nb_ref <<
"\n";
68 std::cout <<
"DESTROY!\n";
73 StatInfo* m_stat_info;
79 Simple2(StatInfo* stat_info) : m_stat_info(stat_info){}
80 ~Simple2(){ m_stat_info->is_destroyed =
true; }
82 StatInfo* m_stat_info;
88template<
typename RefType>
void
89_doTest1(
const RefType& ref_type)
112 _doTest1(Simple1Reference(
new Simple1(&stat_info)));
113 ASSERT_TRUE(stat_info.checkValid(4)) <<
"Bad destroy1";
125 ASSERT_TRUE(stat_info.checkValid(4)) <<
"Bad destroy2";
130 ASSERT_TRUE(stat_info.checkValid(0)) <<
"Bad destroy3";
143 ARCCORE_DECLARE_REFERENCE_COUNTED_INCLASS_METHODS();
148 virtual bool func1() = 0;
149 virtual void func2() = 0;
158 ARCCORE_DEFINE_REFERENCE_COUNTED_INCLASS_METHODS();
162 bool func1()
override {
return true; }
163 void func2()
override {}
167 Int32 m_padding4 = 0;
168 Int64 m_padding3 = 0;
179 using namespace Test1;
209 catch(
const std::exception& ex){
210 std::cerr <<
"Exception ex=" << ex.what() <<
"\n";
#define ASSERT_FALSE(condition)
Vérifie que condition est faux.
#define ASSERT_TRUE(condition)
Vérifie que condition est vrai.
#define ARCCORE_DECLARE_REFERENCE_COUNTED_CLASS(class_name)
Macro pour déclarer qu'une classe utilise un compteur de référence.
Gestion des références à une classe C++.
Gestion des références sur un objet externe.
void reset()
Positionne l'instance au pointeur nul.
Référence à une instance.
static ThatClass createWithHandle(InstanceType *t, Internal::ExternalRef handle)
Créé une référence à partir d'une instance ayant une référence externe.
Implémentation thread-safe d'un compteur de référence.
Encapsulation d'un pointeur avec compteur de référence.
Espace de nom de Arccore.
Ref< TrueType > createRef(Args &&... args)
Créé une instance de type TrueType avec les arguments Args et retourne une référence dessus.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Créé une référence sur un pointeur.
Structure servant à tagger les interfaces/classes qui utilisent un compteur de référence interne.