Debian Codegraph @

src/test_brain_text.cxx

raw
1 /**
2 * Test suite for text "brain"
3
4 * Copyright (C) 2015 Sylvain Beucler
5
6 * This file is part of GNU FreeDink
7
8 * GNU FreeDink is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 3 of the
11 * License, or (at your option) any later version.
12
13 * GNU FreeDink is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include "brains.h"
28 #include "live_sprites_manager.h"
29 #include "game_engine.h"
30
31 class TestBrainText : public CxxTest::TestSuite {
32 public:
33 void setUp() {
34 live_sprites_manager_init();
35 }
36 void tearDown() {
37 }
38
39 void test_brain_text() {
40 TS_ASSERT_EQUALS(add_sprite(0, 0, 0, 0, 0), 1);
41 TS_ASSERT_EQUALS(add_sprite(0, 0, 0, 0, 0), 2);
42 spr[2].x = 500;
43 TS_ASSERT_EQUALS(add_sprite(0, 0, 0, 0, 0), 3);
44 spr[3].brain = 8;
45 spr[3].damage = -1;
46
47 // Follows its owner
48 spr[3].text_owner = 2;
49 spr[3].x = 0;
50 TS_ASSERT_EQUALS(spr[2].active, 1);
51 text_brain(3);
52 TS_ASSERT_EQUALS(spr[3].x, 500);
53
54 // Killed with its owner
55 spr[3].text_owner = 10;
56 TS_ASSERT_EQUALS(spr[10].active, 0);
57 spr[3].x = 0;
58 TS_ASSERT_EQUALS(spr[3].active, 1);
59 text_brain(3);
60 TS_ASSERT_EQUALS(spr[3].x, 0);
61 TS_ASSERT_EQUALS(spr[3].active, 0);
62
63 // Can move on its own
64 // reproducibly
65 spr[3].active = true;
66 spr[3].move_active = 1;
67 spr[3].move_dir = 6;
68 spr[3].move_num = 1;
69 spr[3].speed = 1;
70 base_timing = 4;
71
72 spr[3].x = 0;
73 spr[3].text_owner = 1000;
74 text_brain(3);
75 TS_ASSERT_EQUALS(spr[3].x, 1);
76
77 spr[3].x = 0;
78 spr[3].text_owner = 1000;
79 text_brain(3);
80 TS_ASSERT_EQUALS(spr[3].x, 1);
81
82 // Shouldn't crash
83 spr[3].active = true;
84 spr[3].x = 0;
85 spr[3].text_owner = 1200;
86 TS_ASSERT_EQUALS(spr[3].active, 1);
87 text_brain(3);
88 TS_ASSERT_EQUALS(spr[3].x, 0);
89 TS_ASSERT_EQUALS(spr[3].active, 0);
90
91 // Shouldn't crash
92 spr[3].active = true;
93 spr[3].x = 0;
94 spr[3].text_owner = 100000;
95 TS_ASSERT_EQUALS(spr[3].active, 1);
96 text_brain(3);
97 TS_ASSERT_EQUALS(spr[3].x, 0);
98 TS_ASSERT_EQUALS(spr[3].active, 0);
99 }
100
101 void test_damage_experience() {
102 TS_ASSERT_EQUALS(add_sprite(0, 0, 0, 0, 0), 1);
103 TS_ASSERT_EQUALS(add_sprite(100,100,8,0,0), 2);
104 spr[2].speed = 1;
105 spr[2].hard = 1;
106 spr[2].brain_parm = 1;
107 spr[2].my = -1;
108 spr[2].kill_ttl = 1000;
109 spr[2].dir = 8;
110 spr[2].damage = 10;
111 text_brain(2);
112 TS_ASSERT_EQUALS(spr[2].y, 99);
113 }
114 };