-
Notifications
You must be signed in to change notification settings - Fork 280
/
event_test.cpp
60 lines (51 loc) · 1.87 KB
/
event_test.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
#include "catch/catch.hpp"
#include <algorithm>
#include <string>
#include <vector>
#include "calendar.h"
#include "cata_variant.h"
#include "character_id.h"
#include "event.h"
#include "event_bus.h"
#include "string_id.h"
#include "type_id.h"
TEST_CASE( "construct_event", "[event]" )
{
cata::event e = cata::event::make<event_type::character_kills_monster>(
character_id( 7 ), mtype_id( "zombie" ) );
CHECK( e.type() == event_type::character_kills_monster );
CHECK( e.time() == calendar::turn );
CHECK( e.get<cata_variant_type::character_id>( "killer" ) == character_id( 7 ) );
CHECK( e.get<cata_variant_type::mtype_id>( "victim_type" ) == mtype_id( "zombie" ) );
CHECK( e.get<character_id>( "killer" ) == character_id( 7 ) );
CHECK( e.get<mtype_id>( "victim_type" ) == mtype_id( "zombie" ) );
}
struct test_subscriber : public event_subscriber {
void notify( const cata::event &e ) override {
events.push_back( e );
}
std::vector<cata::event> events;
};
TEST_CASE( "send_event_through_bus", "[event]" )
{
event_bus bus;
test_subscriber sub;
bus.subscribe( &sub );
bus.send( cata::event::make<event_type::character_kills_monster>(
character_id( 5 ), mtype_id( "zombie" ) ) );
REQUIRE( sub.events.size() == 1 );
const cata::event &e = sub.events[0];
CHECK( e.type() == event_type::character_kills_monster );
CHECK( e.time() == calendar::turn );
CHECK( e.get<character_id>( "killer" ) == character_id( 5 ) );
CHECK( e.get<mtype_id>( "victim_type" ) == mtype_id( "zombie" ) );
}
TEST_CASE( "destroy_bus_before_subscriber", "[event]" )
{
test_subscriber sub;
event_bus bus;
bus.subscribe( &sub );
bus.send( cata::event::make<event_type::character_kills_monster>(
character_id( 5 ), mtype_id( "zombie" ) ) );
CHECK( sub.events.size() == 1 );
}