File: w_dehacked_test.cpp

package info (click to toggle)
eureka 2.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,912 kB
  • sloc: cpp: 84,842; python: 495; sh: 91; makefile: 21; ansic: 3
file content (164 lines) | stat: -rw-r--r-- 4,057 bytes parent folder | download
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//------------------------------------------------------------------------
//
//  Eureka DOOM Editor
//
//  Copyright (C) 2024 Ioan Chera
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//------------------------------------------------------------------------

#include "w_dehacked.h"
#include "m_game.h"
#include "w_wad.h"
#include "WadData.h"
#include "testUtils/TempDirContext.hpp"
#include "gtest/gtest.h"

static const char *headerBoilerplate[] = {
	"Patch file for Dehacked v3.1",
	"# Here is the file",
	""
};

static const char *part1[] = {
	"Thing 2 (Imp Sarge Trooper Vanilla Shadow Ceiling Weapon)",
	"Initial frame = 442",
	"Width = 655360",
	"ID # = 2222",
	"Bits = 262400",
	"#$Editor category = Weapons",
	"",
	"Frame 442",
	"Sprite number = 31",
	"Sprite subnumber = 32769",
	"",
	"Text 4 4",
	"VILEABCD",
	""
};

static const char *part2[] = {
	"[SPRITES]",
	"30 = NEWB",
	"",
	"Thing 3 (Newbie)",
	"Bits = SPAWNCEILING+SHADOW"
};

class DehackedTest : public TempDirContext
{
protected:
	void makeFile();
};

void DehackedTest::makeFile()
{
	std::ofstream stream(getSubPath("tested.deh"));
	ASSERT_TRUE(stream.is_open());
	mDeleteList.push(getSubPath("tested.deh"));

	// Add some bogus headers
	for(const char *line : headerBoilerplate)
		stream << line << std::endl;
	for(const char *line : part1)
		stream << line << std::endl;
	for(const char *line : part2)
		stream << line << std::endl;
}

TEST_F(DehackedTest, LoadNoFile)
{
	ConfigData config;
	ASSERT_FALSE(dehacked::loadFile("bogus.deh", config));
}

static ConfigData baseConfig()
{
	ConfigData config;
	thingtype_t *type = &config.thing_types[3004];
	type->group = 'm';
	type->flags = 0;
	type->radius = 20;
	type->desc = "Trooper";
	type->sprite = "POSS";
	
	type = &config.thing_types[9];
	type->group = 'm';
	type->flags = 0;
	type->radius = 20;
	type->desc = "Sergeant";
	type->sprite = "SPOS";

	return config;
}

static void assertChangedConfig(const ConfigData &config)
{
	ASSERT_EQ(config.thing_types.find(3004), config.thing_types.end());
	auto it = config.thing_types.find(2222);
	ASSERT_NE(it, config.thing_types.end());
	
	const thingtype_t *newtype = &it->second;
	
	ASSERT_EQ(newtype->group, 'w');
	ASSERT_EQ(newtype->flags, THINGDEF_PASS | THINGDEF_CEIL | THINGDEF_INVIS | THINGDEF_LIT);
	ASSERT_EQ(newtype->radius, 10.0f);
	ASSERT_EQ(newtype->desc, "Imp Sarge Trooper Vanilla Shadow Ceiling Weapon");
	ASSERT_EQ(newtype->sprite, "ABCDB");
	
	it = config.thing_types.find(9);
	ASSERT_NE(it, config.thing_types.end());
	newtype = &it->second;
	ASSERT_EQ(newtype->group, 'm');
	ASSERT_EQ(newtype->flags, THINGDEF_CEIL | THINGDEF_INVIS);
	ASSERT_EQ(newtype->radius, 20.0f);
	ASSERT_EQ(newtype->desc, "Newbie");
	ASSERT_EQ(newtype->sprite, "NEWB");
}

TEST_F(DehackedTest, LoadFile)
{
	makeFile();
	
	ConfigData config = baseConfig();
	
	bool result = dehacked::loadFile(getSubPath("tested.deh"), config);
	ASSERT_TRUE(result);
	
	assertChangedConfig(config);
}

TEST_F(DehackedTest, LoadLumps)
{
	auto wad = Wad_file::Open("test.wad", WadOpenMode::write);
	ASSERT_TRUE(wad);
	Lump_c &dhe1 = wad->AddLump("DEHACKED");
	for(const char *line : part1)
		dhe1.Printf("%s\n", line);
	
	std::vector<std::shared_ptr<Wad_file>> resources;
	resources.push_back(wad);
	
	wad = Wad_file::Open("test2.wad", WadOpenMode::write);
	resources.push_back(wad);
	Lump_c &dhe2 = wad->AddLump("DEHACKED");
	for(const char *line : part2)
		dhe2.Printf("%s\n", line);
	
	MasterDir dir;
	dir.setResources(resources);
	
	ConfigData config = baseConfig();
	
	dehacked::loadLumps(dir, config);
	assertChangedConfig(config);
}