13#ifndef ARCANE_UNITTESTADAPTER_H
14#define ARCANE_UNITTESTADAPTER_H
18#include "arcane/IUnitTest.h"
19#include "arcane/ArcaneException.h"
20#include "arcane/Assertion.h"
21#include "arcane/XmlNode.h"
47 : m_service(service) {}
51 void setClassSetUpFunction(
FuncPtr f) { m_class_set_up_function = f; }
52 void setTestSetUpFunction(
FuncPtr f) { m_set_up_function = f; }
53 void setClassTearDownFunction(
FuncPtr f) { m_class_tear_down_function = f; }
54 void setTestTearDownFunction(
FuncPtr f) { m_tear_down_function = f; }
55 void addTestFunction(
FuncPtr f, String name, String method_name)
57 TestFuncInfo info(f, name, method_name);
58 m_test_functions.
add(info);
66 if (m_class_set_up_function)
67 (m_service->*m_class_set_up_function)();
74 report.
setAttrValue(
"name", m_service->serviceInfo()->localName());
75 for ( TestFuncInfo func_info : m_test_functions ) {
76 XmlNode xunittest = report.createAndAppendElement(
"unit-test");
79 xunittest.
setAttrValue(
"method-name", func_info.m_method_name);
80 if (m_set_up_function)
81 (m_service->*m_set_up_function)();
82 (m_service->*func_info.m_test_func)();
83 if (m_tear_down_function)
84 (m_service->*m_tear_down_function)();
86 m_service->info() <<
"[OK ] " << func_info.m_name;
90 XmlNode xexception = xunittest.createAndAppendElement(
"exception");
95 m_service->info() <<
"[ECHEC] " << func_info.m_name <<
" (line " << e.
line() <<
" in " << e.
where() <<
")";
96 m_service->info() <<
" " << e.
message();
106 if (m_class_tear_down_function)
107 (m_service->*m_class_tear_down_function)();
115 : m_test_func(test_func), m_name(name), m_method_name(method_name) {}
119 String m_method_name;
125 FuncPtr m_class_set_up_function =
nullptr;
127 FuncPtr m_set_up_function =
nullptr;
129 FuncPtr m_class_tear_down_function =
nullptr;
131 FuncPtr m_tear_down_function =
nullptr;
133 UniqueArray<TestFuncInfo> m_test_functions;
const String & where() const
Localisation de l'exception.
const char * file() const
Fichier de l'exception.
const String & message() const
Message de l'exception.
int line() const
Ligne de l'exception.
Classe de base pour assertions dans les tests unitaires.
Interface d'un service de test unitaire fournissant un rapport de test sous forme d'un noeud XML.
Adapte un service qui déclare des tests a l'interface IUnitTest.
void initializeTest() override
Implémentation de l'interface IUnitTest.
bool executeTest(XmlNode &report) override
Implémentation de l'interface IUnitTest.
void finalizeTest() override
Implémentation de l'interface IUnitTest.
void(T::* FuncPtr)()
Type du pointeur sur les méthodes de test.
void setAttrValue(const String &name, const String &value)
Positionne l'attribut name à la valeur value.
void add(ConstReferenceType val)
Ajoute l'élément val à la fin du tableau.
Chaîne de caractères unicode.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-