File: DocumentTest.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 (129 lines) | stat: -rw-r--r-- 3,801 bytes parent folder | download | duplicates (2)
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
//------------------------------------------------------------------------
//
//  Eureka DOOM Editor
//
//  Copyright (C) 2022 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 "Document.h"
#include "Instance.h"
#include "lib_adler.h"
#include "LineDef.h"
#include "Thing.h"
#include "Vertex.h"
#include "gtest/gtest.h"

class DocumentFixture : public ::testing::Test
{
protected:
	DocumentFixture() : doc(inst)
	{
	}

	Instance inst;
	Document doc;
};

TEST_F(DocumentFixture, CheckObjects)
{
	// Start with 0
	ASSERT_FALSE(doc.numThings());
	ASSERT_FALSE(doc.numVertices());
	ASSERT_FALSE(doc.numSectors());
	ASSERT_FALSE(doc.numSidedefs());
	ASSERT_FALSE(doc.numLinedefs());

	// Add some objects
	doc.things.push_back(std::make_shared<Thing>());
	doc.things.push_back(std::make_shared<Thing>());
	doc.things.push_back(std::make_shared<Thing>());
	doc.vertices.push_back(std::make_shared<Vertex>());
	doc.vertices.push_back(std::make_shared<Vertex>());
	doc.vertices.push_back(std::make_shared<Vertex>());
	doc.vertices.push_back(std::make_shared<Vertex>());
	// no sectors
	doc.sidedefs.push_back(std::make_shared<SideDef>());
	doc.sidedefs.push_back(std::make_shared<SideDef>());
	doc.linedefs.push_back(std::make_shared<LineDef>());

	ASSERT_EQ(doc.numThings(), 3);
	ASSERT_EQ(doc.numVertices(), 4);
	ASSERT_EQ(doc.numSectors(), 0);
	ASSERT_EQ(doc.numSidedefs(), 2);
	ASSERT_EQ(doc.numLinedefs(), 1);
	ASSERT_EQ(doc.numObjects(ObjType::things), 3);
	ASSERT_EQ(doc.numObjects(ObjType::vertices), 4);
	ASSERT_EQ(doc.numObjects(ObjType::sectors), 0);
	ASSERT_EQ(doc.numObjects(ObjType::sidedefs), 2);
	ASSERT_EQ(doc.numObjects(ObjType::linedefs), 1);

	ASSERT_FALSE(doc.isThing(-1));
	ASSERT_TRUE(doc.isThing(0));
	ASSERT_TRUE(doc.isThing(1));
	ASSERT_TRUE(doc.isThing(2));
	ASSERT_FALSE(doc.isThing(3));

	ASSERT_FALSE(doc.isVertex(-1));
	ASSERT_TRUE(doc.isVertex(0));
	ASSERT_TRUE(doc.isVertex(1));
	ASSERT_TRUE(doc.isVertex(2));
	ASSERT_TRUE(doc.isVertex(3));
	ASSERT_FALSE(doc.isVertex(4));

	ASSERT_FALSE(doc.isSector(-1));
	ASSERT_FALSE(doc.isSector(0));

	ASSERT_FALSE(doc.isSidedef(-1));
	ASSERT_TRUE(doc.isSidedef(0));
	ASSERT_TRUE(doc.isSidedef(1));
	ASSERT_FALSE(doc.isSidedef(2));

	ASSERT_FALSE(doc.isLinedef(-1));
	ASSERT_TRUE(doc.isLinedef(0));
	ASSERT_FALSE(doc.isLinedef(1));
}

TEST_F(DocumentFixture, CRC)
{
	// Add some objects
	doc.things.push_back(std::make_shared<Thing>());
	doc.things.push_back(std::make_shared<Thing>());
	doc.things.push_back(std::make_shared<Thing>());
	doc.vertices.push_back(std::make_shared<Vertex>());
	doc.vertices.push_back(std::make_shared<Vertex>());
	doc.vertices.push_back(std::make_shared<Vertex>());
	doc.vertices.push_back(std::make_shared<Vertex>());
	// no sectors
	doc.sidedefs.push_back(std::make_shared<SideDef>());
	doc.sidedefs.push_back(std::make_shared<SideDef>());
	doc.linedefs.push_back(std::make_shared<LineDef>());

	crc32_c crc;
	doc.getLevelChecksum(crc);

	// Now remove one thing
	doc.things.pop_back();

	crc32_c crc2;
	doc.getLevelChecksum(crc2);

	ASSERT_NE(crc.getPath(), crc2.getPath());

	// Now add back one thing
	doc.things.push_back(std::make_shared<Thing>());

	crc32_c crc3;
	doc.getLevelChecksum(crc3);
	ASSERT_EQ(crc.getPath(), crc3.getPath());
}