-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestCharacters.cpp
76 lines (63 loc) · 1.98 KB
/
testCharacters.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// //////////////////////////////////////////////////////////////////////
// Import section
// //////////////////////////////////////////////////////////////////////
// STL
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <iostream>
#include <memory>
#include <cassert>
// Boost
#include <boost/filesystem.hpp>
// Boost Unit Test Framework (UTF)
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#define BOOST_TEST_MODULE TestCharacters
#include <boost/test/unit_test.hpp>
// Characters
#include <Character.hpp>
namespace boost_utf = boost::unit_test;
// (Boost) Unit Test XML Report
std::ofstream utfReportStream ("TestCharacters_utfresults.xml");
/**
* Configuration for the Boost Unit Test Framework (UTF)
*/
struct UnitTestConfig {
/** Constructor. */
UnitTestConfig() {
boost_utf::unit_test_log.set_stream (utfReportStream);
boost_utf::unit_test_log.set_format (boost_utf::OF_XML);
boost_utf::unit_test_log.set_threshold_level (boost_utf::log_test_units);
}
/** Destructor. */
~UnitTestConfig() {
}
};
// /////////////// Main: Unit Test Suite //////////////
// Set the UTF configuration (re-direct the output to a specific file)
BOOST_GLOBAL_FIXTURE (UnitTestConfig);
// Start the test suite
BOOST_AUTO_TEST_SUITE (master_test_suite)
/**
* Test various ways to build Character objects
*/
BOOST_AUTO_TEST_CASE (characters1) {
// Perso 1
Character* p1_ptr = new Character ("Perceval", 35);
assert (p1_ptr != nullptr);
std::cout << "Perceval just built: " << *p1_ptr << std::endl;
BOOST_CHECK_MESSAGE (p1_ptr->getAge() == 35,
"The age of this character should be 35");
// Amend Perso 1
assert (p1_ptr!=nullptr);
p1_ptr->setAge(38);
std::cout << "Perceval after age change: " << *p1_ptr << std::endl;
BOOST_CHECK_MESSAGE (p1_ptr->getAge() == 38,
"The age of this character should be 38");
// Cleaning
delete p1_ptr; p1_ptr = nullptr;
}
// End the test suite
BOOST_AUTO_TEST_SUITE_END()