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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
|
//------------------------------------------------------------------------
//
// 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 "gtest/gtest.h"
#include "Instance.h"
#include "w_rawdef.h"
class ECutPasteFixture : public ::testing::Test
{
protected:
~ECutPasteFixture()
{
inst.level.clear();
}
void addArea();
void addSecondArea();
void moveMouse(const v2double_t &pos);
Instance inst;
};
void ECutPasteFixture::addArea()
{
Vertex *vertex;
vertex = new Vertex;
vertex->raw_x = FFixedPoint(0);
vertex->raw_y = FFixedPoint(0);
inst.level.vertices.push_back(std::shared_ptr<Vertex>(vertex));
vertex = new Vertex;
vertex->raw_x = FFixedPoint(0);
vertex->raw_y = FFixedPoint(256);
inst.level.vertices.push_back(std::shared_ptr<Vertex>(vertex));
vertex = new Vertex;
vertex->raw_x = FFixedPoint(256);
vertex->raw_y = FFixedPoint(256);
inst.level.vertices.push_back(std::shared_ptr<Vertex>(vertex));
vertex = new Vertex;
vertex->raw_x = FFixedPoint(256);
vertex->raw_y = FFixedPoint(0);
inst.level.vertices.push_back(std::shared_ptr<Vertex>(vertex));
Sector *sector;
sector = new Sector;
sector->floorh = 0;
sector->ceilh = 128;
inst.level.sectors.push_back(std::shared_ptr<Sector>(sector));
inst.level.sidedefs.push_back(std::shared_ptr<SideDef>(new SideDef));
inst.level.sidedefs.push_back(std::shared_ptr<SideDef>(new SideDef));
inst.level.sidedefs.push_back(std::shared_ptr<SideDef>(new SideDef));
inst.level.sidedefs.push_back(std::shared_ptr<SideDef>(new SideDef));
LineDef *line;
line = new LineDef;
line->start = 0;
line->end = 1;
line->right = 0;
line->left = -1;
inst.level.linedefs.push_back(std::shared_ptr<LineDef>(line));
line = new LineDef;
line->start = 1;
line->end = 2;
line->right = 1;
line->left = -1;
inst.level.linedefs.push_back(std::shared_ptr<LineDef>(line));
line = new LineDef;
line->start = 2;
line->end = 3;
line->right = 2;
line->left = -1;
inst.level.linedefs.push_back(std::shared_ptr<LineDef>(line));
line = new LineDef;
line->start = 3;
line->end = 0;
line->right = 3;
line->left = -1;
inst.level.linedefs.push_back(std::shared_ptr<LineDef>(line));
Thing *thing;
thing = new Thing;
thing->raw_x = FFixedPoint(192);
thing->raw_y = FFixedPoint(128);
thing->type = 1;
thing->angle = 0;
inst.level.things.push_back(std::shared_ptr<Thing>(thing));
thing = new Thing;
thing->raw_x = FFixedPoint(128);
thing->raw_y = FFixedPoint(192);
thing->type = 2;
thing->angle = 90;
inst.level.things.push_back(std::shared_ptr<Thing>(thing));
thing = new Thing;
thing->raw_x = FFixedPoint(64);
thing->raw_y = FFixedPoint(128);
thing->type = 3;
thing->angle = 180;
inst.level.things.push_back(std::shared_ptr<Thing>(thing));
thing = new Thing;
thing->raw_x = FFixedPoint(128);
thing->raw_y = FFixedPoint(64);
thing->type = 4;
thing->angle = 270;
inst.level.things.push_back(std::shared_ptr<Thing>(thing));
}
void ECutPasteFixture::addSecondArea()
{
Vertex *vertex;
vertex = new Vertex;
vertex->raw_x = FFixedPoint(320);
vertex->raw_y = FFixedPoint(192);
inst.level.vertices.push_back(std::shared_ptr<Vertex>(vertex));
vertex = new Vertex;
vertex->raw_x = FFixedPoint(320);
vertex->raw_y = FFixedPoint(256);
inst.level.vertices.push_back(std::shared_ptr<Vertex>(vertex));
vertex = new Vertex;
vertex->raw_x = FFixedPoint(384);
vertex->raw_y = FFixedPoint(256);
inst.level.vertices.push_back(std::shared_ptr<Vertex>(vertex));
vertex = new Vertex;
vertex->raw_x = FFixedPoint(384);
vertex->raw_y = FFixedPoint(192);
inst.level.vertices.push_back(std::shared_ptr<Vertex>(vertex));
Sector *sector;
sector = new Sector;
sector->floorh = 0;
sector->ceilh = 128;
inst.level.sectors.push_back(std::shared_ptr<Sector>(sector));
SideDef *side;
side = new SideDef;
side->sector = 1;
inst.level.sidedefs.push_back(std::shared_ptr<SideDef>(side));
side = new SideDef;
side->sector = 1;
inst.level.sidedefs.push_back(std::shared_ptr<SideDef>(side));
side = new SideDef;
side->sector = 1;
inst.level.sidedefs.push_back(std::shared_ptr<SideDef>(side));
side = new SideDef;
side->sector = 1;
inst.level.sidedefs.push_back(std::shared_ptr<SideDef>(side));
LineDef *line;
line = new LineDef;
line->start = 4;
line->end = 5;
line->right = 4;
line->left = -1;
inst.level.linedefs.push_back(std::shared_ptr<LineDef>(line));
line = new LineDef;
line->start = 5;
line->end = 6;
line->right = 5;
line->left = -1;
inst.level.linedefs.push_back(std::shared_ptr<LineDef>(line));
line = new LineDef;
line->start = 6;
line->end = 7;
line->right = 6;
line->left = -1;
inst.level.linedefs.push_back(std::shared_ptr<LineDef>(line));
line = new LineDef;
line->start = 7;
line->end = 4;
line->right = 7;
line->left = -1;
inst.level.linedefs.push_back(std::shared_ptr<LineDef>(line));
}
void ECutPasteFixture::moveMouse(const v2double_t &pos)
{
inst.edit.map.xy = pos;
inst.UpdateHighlight();
}
TEST_F(ECutPasteFixture, DeletingAllPlayersWillNotCrash)
{
addArea();
inst.edit.Selected = selection_c(); // things
inst.edit.Selected->set(0);
inst.edit.Selected->set(1);
inst.edit.Selected->set(2);
inst.edit.Selected->set(3);
inst.CMD_Delete();
ASSERT_TRUE(inst.level.things.empty());
}
TEST_F(ECutPasteFixture, DeletingAllLinesFromAnotherSectorWillNotCrash)
{
addArea();
addSecondArea();
ASSERT_EQ(inst.level.linedefs.size(), 8);
ASSERT_EQ(inst.level.vertices.size(), 8);
ASSERT_EQ(inst.level.sidedefs.size(), 8);
ASSERT_EQ(inst.level.sectors.size(), 2);
ASSERT_EQ(inst.level.things.size(), 4);
inst.edit.mode = ObjType::linedefs;
inst.edit.Selected = selection_c(ObjType::linedefs);
inst.edit.Selected->set(4);
inst.edit.Selected->set(5);
inst.edit.Selected->set(6);
inst.edit.Selected->set(7);
inst.CMD_Delete();
ASSERT_EQ(inst.level.linedefs.size(), 4);
ASSERT_EQ(inst.level.vertices.size(), 4);
ASSERT_EQ(inst.level.sidedefs.size(), 4);
ASSERT_EQ(inst.level.sectors.size(), 1);
ASSERT_EQ(inst.level.things.size(), 4);
}
TEST_F(ECutPasteFixture, DeletingAllLinesWillNotCrash)
{
addArea();
inst.edit.mode = ObjType::linedefs;
inst.edit.Selected = selection_c(ObjType::linedefs);
inst.edit.Selected->set(0);
inst.edit.Selected->set(1);
inst.edit.Selected->set(2);
inst.edit.Selected->set(3);
inst.CMD_Delete();
ASSERT_TRUE(inst.level.linedefs.empty());
ASSERT_TRUE(inst.level.vertices.empty());
ASSERT_TRUE(inst.level.sidedefs.empty());
ASSERT_TRUE(inst.level.sectors.empty());
ASSERT_TRUE(inst.level.things.empty());
}
TEST_F(ECutPasteFixture, LCDSevenSegmentEightLayoutUsingCommands)
{
// LCD 8-shaped layout using editor commands to simulate user drawing
inst.edit.mode = ObjType::vertices;
inst.edit.action = EditorAction::nothing;
inst.edit.pointer_in_window = true;
// Draw bottom-left square: (0,0) -> (0,128) -> (128,128) -> (128,0) -> close
const v2double_t coords[] =
{
{0, 0}, {0, 128}, {128, 128}, {256, 128}, {256, 0}, {128, 0}, {0, 0}, {128, 0}, {128, 128}
};
for (v2double_t xy : coords)
{
moveMouse(xy);
inst.CMD_ObjectInsert();
}
// Make right sector taller
inst.edit.mode = ObjType::sectors;
inst.Selection_Clear();
moveMouse({192, 64});
ASSERT_TRUE(inst.edit.highlight.valid());
ASSERT_EQ(inst.edit.highlight.type, ObjType::sectors);
const auto §or = inst.level.sectors[inst.edit.highlight.num];
sector->floorh = 64;
sector->ceilh = 192;
// Put different textures on the middle line
inst.edit.mode = ObjType::linedefs;
inst.Selection_Clear();
moveMouse({128, 64});
ASSERT_TRUE(inst.edit.highlight.valid());
ASSERT_EQ(inst.edit.highlight.type, ObjType::linedefs);
auto linedef = inst.level.linedefs[inst.edit.highlight.num];
auto sidedef = inst.level.getRight(*linedef);
ASSERT_TRUE(sidedef);
sidedef->upper_tex = BA_InternaliseString("UPPER");
sidedef = inst.level.getLeft(*linedef);
ASSERT_TRUE(sidedef);
sidedef->lower_tex = BA_InternaliseString("LOWER");
// Do copy
inst.edit.mode = ObjType::sectors;
inst.Selection_Clear();
moveMouse({192, 64});
inst.CMD_Clipboard_Copy();
size_t linedefCountBeforePaste = inst.level.linedefs.size();
size_t sidedefCountBeforePaste = inst.level.sidedefs.size();
// Do paste
moveMouse({384, 64});
inst.CMD_Clipboard_Paste();
// We have a new sector
ASSERT_EQ(inst.level.sectors.size(), 3);
// Only four lines get added
ASSERT_EQ(inst.level.linedefs.size(), linedefCountBeforePaste + 4);
// More important: only four sidedefs
ASSERT_EQ(inst.level.sidedefs.size(), sidedefCountBeforePaste + 4);
// Now check the linedef
inst.edit.mode = ObjType::linedefs;
inst.Selection_Clear();
moveMouse({320, 64});
ASSERT_TRUE(inst.edit.highlight.valid());
ASSERT_EQ(inst.edit.highlight.type, ObjType::linedefs);
linedef = inst.level.linedefs[inst.edit.highlight.num];
ASSERT_TRUE(linedef->OneSided());
ASSERT_TRUE(linedef->flags & MLF_Blocking);
ASSERT_FALSE(linedef->flags & MLF_TwoSided);
sidedef = inst.level.getRight(*linedef);
ASSERT_TRUE(sidedef);
ASSERT_EQ(sidedef->MidTex(), "UPPER");
// Now paste the left sector
inst.edit.mode = ObjType::sectors;
inst.Selection_Clear();
moveMouse({64, 64});
inst.CMD_Clipboard_Copy();
linedefCountBeforePaste = inst.level.linedefs.size();
sidedefCountBeforePaste = inst.level.sidedefs.size();
// Paste to a clear area
moveMouse({384, 256});
inst.CMD_Clipboard_Paste();
// Only four lines get added
ASSERT_EQ(inst.level.linedefs.size(), linedefCountBeforePaste + 4);
// More important: only four sidedefs
ASSERT_EQ(inst.level.sidedefs.size(), sidedefCountBeforePaste + 4);
// Check the east linedef of the pasted sector
inst.edit.mode = ObjType::linedefs;
inst.Selection_Clear();
moveMouse({448, 256});
ASSERT_TRUE(inst.edit.highlight.valid());
ASSERT_EQ(inst.edit.highlight.type, ObjType::linedefs);
linedef = inst.level.linedefs[inst.edit.highlight.num];
ASSERT_TRUE(linedef->OneSided());
ASSERT_TRUE(linedef->flags & MLF_Blocking);
ASSERT_FALSE(linedef->flags & MLF_TwoSided);
sidedef = inst.level.getRight(*linedef);
ASSERT_TRUE(sidedef);
ASSERT_EQ(sidedef->MidTex(), "LOWER");
}
|