From 25e0bc83d0d8b2cdb10d576df91b4ea5f1c4da4a Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Thu, 1 Oct 2015 18:59:55 -0400 Subject: [PATCH] Start on test cases for conversion of legacy special nodes --- src/BoE.xcodeproj/project.pbxproj | 4 + test/spec_legacy.cpp | 247 ++++++++++++++++++++++++++++++ 2 files changed, 251 insertions(+) create mode 100644 test/spec_legacy.cpp diff --git a/src/BoE.xcodeproj/project.pbxproj b/src/BoE.xcodeproj/project.pbxproj index 8c6e4125..332a01bb 100755 --- a/src/BoE.xcodeproj/project.pbxproj +++ b/src/BoE.xcodeproj/project.pbxproj @@ -140,6 +140,7 @@ 91960ED41BB6157A008AF8F4 /* restypes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91960ED31BB613E5008AF8F4 /* restypes.cpp */; }; 919B13A21BBCDF14009905A4 /* monst_legacy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 919B13A11BBCDE18009905A4 /* monst_legacy.cpp */; }; 919B13A41BBD8854009905A4 /* item_legacy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 919B13A31BBD8849009905A4 /* item_legacy.cpp */; }; + 919B13A61BBDE986009905A4 /* spec_legacy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 919B13A51BBDE985009905A4 /* spec_legacy.cpp */; }; 919CC2481B3772F300273FDA /* creatlist.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91AC620A0FA2853700EEAE67 /* creatlist.cpp */; }; 919CC2491B3772FB00273FDA /* creature.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 914698FE1A747C4500F20F5E /* creature.cpp */; }; 919CC24B1B37730300273FDA /* item.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 91279D3D0F9D1D6A007B0D52 /* item.cpp */; }; @@ -663,6 +664,7 @@ 91960ED31BB613E5008AF8F4 /* restypes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = restypes.cpp; sourceTree = ""; }; 919B13A11BBCDE18009905A4 /* monst_legacy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = monst_legacy.cpp; sourceTree = ""; }; 919B13A31BBD8849009905A4 /* item_legacy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = item_legacy.cpp; sourceTree = ""; }; + 919B13A51BBDE985009905A4 /* spec_legacy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = spec_legacy.cpp; sourceTree = ""; }; 919DDBFA19006CC9003E7FED /* libboost_filesystem.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libboost_filesystem.dylib; path = /usr/local/lib/libboost_filesystem.dylib; sourceTree = ""; }; 919DDBFB19006CC9003E7FED /* libboost_system.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libboost_system.dylib; path = /usr/local/lib/libboost_system.dylib; sourceTree = ""; }; 919DDC091900750D003E7FED /* freetype.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = freetype.framework; path = ../../../../../../Library/Frameworks/freetype.framework; sourceTree = ""; }; @@ -1327,6 +1329,7 @@ 91E381491B97678D00F69B81 /* out_write.cpp */, 91CC173A1B421CA0003D9A69 /* scen_read.cpp */, 91CC173B1B421CA0003D9A69 /* scen_write.cpp */, + 919B13A51BBDE985009905A4 /* spec_legacy.cpp */, 91C2A6EE1B8FAA8E00346948 /* talk_read.cpp */, 91E381471B97675900F69B81 /* talk_write.cpp */, 91EF27721B693D3800666469 /* ter_read.cpp */, @@ -1856,6 +1859,7 @@ 91E3814A1B97679800F69B81 /* out_write.cpp in Sources */, 919B13A21BBCDF14009905A4 /* monst_legacy.cpp in Sources */, 919B13A41BBD8854009905A4 /* item_legacy.cpp in Sources */, + 919B13A61BBDE986009905A4 /* spec_legacy.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/test/spec_legacy.cpp b/test/spec_legacy.cpp new file mode 100644 index 00000000..b89519f3 --- /dev/null +++ b/test/spec_legacy.cpp @@ -0,0 +1,247 @@ +// +// spec_legacy.cpp +// BoE +// +// Created by Celtic Minstrel on 15-07-11. +// +// + +#include "catch.hpp" +#include "oldstructs.hpp" +#include "special.hpp" +#include "restypes.hpp" + +using namespace std; + +ostream& operator<< (ostream& out, eSpecType spec); + +TEST_CASE("When converting legacy special nodes (general)") { + cSpecial newSpec; + legacy::special_node_type oldSpec = {0,-1,-1,0,-1,-1,-1,-1,-1,-1,-1}; + // Fetching opcodes requires strings to be available + // Here we fetch them from the rsrc dir, rather than the data dir + ResMgr::pushPath("../rsrc/strings"); + + oldSpec.jumpto = 12; + SECTION("Set Flag") { + oldSpec.type = 1; + oldSpec.m1 = 2; oldSpec.m2 = 3; + oldSpec.sd1 = 4; oldSpec.sd2 = 5; + oldSpec.ex1a = 6; + newSpec.append(oldSpec); + CHECK(newSpec.type == eSpecType::SET_SDF); + CHECK(newSpec.m1 == 2); CHECK(newSpec.m2 == 3); + CHECK(newSpec.sd1 == 4); CHECK(newSpec.sd2 == 5); + CHECK(newSpec.ex1a == 6); + CHECK(newSpec.jumpto == 12); + } + SECTION("Secret Passage") { + oldSpec.type = 4; + newSpec.append(oldSpec); + CHECK(newSpec.type == eSpecType::CANT_ENTER); + CHECK(newSpec.ex1a == 0); + CHECK(newSpec.ex2a == 1); + CHECK(newSpec.jumpto == 12); + } + SECTION("Out Block") { + oldSpec.type = 7; + oldSpec.m1 = 4; oldSpec.m2 = 5; + oldSpec.ex1a = 1; + newSpec.append(oldSpec); + CHECK(newSpec.type == eSpecType::IF_CONTEXT); + CHECK(newSpec.m1 == 4); CHECK(newSpec.m2 == 5); + CHECK(newSpec.ex1a == int(eSpecCtx::OUT_MOVE)); + CHECK(newSpec.ex1b == 1); + CHECK(newSpec.jumpto == 12); + } + SECTION("Town Block") { + oldSpec.type = 8; + oldSpec.m1 = 4; oldSpec.m2 = 5; + oldSpec.ex1a = 1; + newSpec.append(oldSpec); + CHECK(newSpec.type == eSpecType::IF_CONTEXT); + CHECK(newSpec.m1 == 4); CHECK(newSpec.m2 == 5); + CHECK(newSpec.ex1a == int(eSpecCtx::TOWN_MOVE)); + CHECK(newSpec.ex1b == 1); + CHECK(newSpec.jumpto == 12); + } + SECTION("Combat Block") { + oldSpec.type = 9; + oldSpec.m1 = 4; oldSpec.m2 = 5; + oldSpec.ex1a = 1; + newSpec.append(oldSpec); + CHECK(newSpec.type == eSpecType::IF_CONTEXT); + CHECK(newSpec.m1 == 4); CHECK(newSpec.m2 == 5); + CHECK(newSpec.ex1a == int(eSpecCtx::COMBAT_MOVE)); + CHECK(newSpec.ex1b == 1); + CHECK(newSpec.jumpto == 12); + } + SECTION("Looking Block") { + oldSpec.type = 10; + oldSpec.m1 = 4; oldSpec.m2 = 5; + newSpec.append(oldSpec); + CHECK(newSpec.type == eSpecType::IF_LOOKING); + CHECK(newSpec.m1 == 4); CHECK(newSpec.m2 == 5); + CHECK(newSpec.jumpto == 12); + } + // Clean up after ourselves + ResMgr::popPath(); +} + +TEST_CASE("When converting legacy special nodes (one-shot)") { + cSpecial newSpec; + legacy::special_node_type oldSpec = {0,-1,-1,0,-1,-1,-1,-1,-1,-1,-1}; + // Fetching opcodes requires strings to be available + // Here we fetch them from the rsrc dir, rather than the data dir + ResMgr::pushPath("../rsrc/strings"); + + oldSpec.sd1 = 8; oldSpec.sd2 = 7; + oldSpec.m1 = 4; oldSpec.m2 = 5; + oldSpec.jumpto = 12; + SECTION("Give Item") { + oldSpec.type = 50; + oldSpec.ex1a = 9; + oldSpec.ex1b = 2500; + oldSpec.ex2a = 1500; + oldSpec.ex2b = 10; + newSpec.append(oldSpec); + CHECK(newSpec.type == eSpecType::ONCE_GIVE_ITEM); + CHECK(newSpec.sd1 == 8); CHECK(newSpec.sd2 == 7); + CHECK(newSpec.m1 == 4); CHECK(newSpec.m2 == 5); + CHECK(newSpec.ex1a == 9); + CHECK(newSpec.ex1b == 2500); + CHECK(newSpec.ex2a == 1500); + CHECK(newSpec.ex2b == 10); + CHECK(newSpec.jumpto == 12); + } + // Clean up after ourselves + ResMgr::popPath(); +} + +TEST_CASE("When converting legacy special nodes (affect)") { + cSpecial newSpec; + legacy::special_node_type oldSpec = {0,-1,-1,0,-1,-1,-1,-1,-1,-1,-1}; + // Fetching opcodes requires strings to be available + // Here we fetch them from the rsrc dir, rather than the data dir + ResMgr::pushPath("../rsrc/strings"); + + oldSpec.m1 = 4; oldSpec.m2 = 5; + oldSpec.jumpto = 12; + SECTION("Select a PC") { + oldSpec.type = 80; + oldSpec.ex1a = 1; + oldSpec.ex1b = 10; + newSpec.append(oldSpec); + CHECK(newSpec.type == eSpecType::SELECT_TARGET); + CHECK(newSpec.m1 == 4); CHECK(newSpec.m2 == 5); + CHECK(newSpec.ex1a == 1); + CHECK(newSpec.ex1b == 10); + CHECK(newSpec.jumpto == 12); + } + // Clean up after ourselves + ResMgr::popPath(); +} + +TEST_CASE("When converting legacy special nodes (if-then)") { + cSpecial newSpec; + legacy::special_node_type oldSpec = {0,-1,-1,0,-1,-1,-1,-1,-1,-1,-1}; + // Fetching opcodes requires strings to be available + // Here we fetch them from the rsrc dir, rather than the data dir + ResMgr::pushPath("../rsrc/strings"); + + oldSpec.jumpto = 12; + SECTION("Stuff Done Flag?") { + oldSpec.type = 130; + oldSpec.sd1 = 8; oldSpec.sd2 = 7; + oldSpec.ex1a = 1; + oldSpec.ex1b = 10; + oldSpec.ex2a = 9; + oldSpec.ex2b = 13; + newSpec.append(oldSpec); + CHECK(newSpec.type == eSpecType::IF_SDF); + CHECK(newSpec.sd1 == 8); CHECK(newSpec.sd2 == 7); + CHECK(newSpec.ex1a == 1); + CHECK(newSpec.ex1b == 10); + CHECK(newSpec.ex2a == 9); + CHECK(newSpec.ex2b == 13); + CHECK(newSpec.jumpto == 12); + } + // Clean up after ourselves + ResMgr::popPath(); +} + +TEST_CASE("When converting legacy special nodes (town)") { + cSpecial newSpec; + legacy::special_node_type oldSpec = {0,-1,-1,0,-1,-1,-1,-1,-1,-1,-1}; + // Fetching opcodes requires strings to be available + // Here we fetch them from the rsrc dir, rather than the data dir + ResMgr::pushPath("../rsrc/strings"); + + oldSpec.m1 = 4; oldSpec.m2 = 5; + SECTION("Town Hostile") { + oldSpec.type = 170; + oldSpec.jumpto = 12; + newSpec.append(oldSpec); + CHECK(newSpec.type == eSpecType::MAKE_TOWN_HOSTILE); + CHECK(newSpec.m1 == 4); CHECK(newSpec.m2 == 5); + CHECK(newSpec.jumpto == 12); + } + // Clean up after ourselves + ResMgr::popPath(); +} + +TEST_CASE("When converting legacy special nodes (rect)") { + cSpecial newSpec; + legacy::special_node_type oldSpec = {0,-1,-1,0,-1,-1,-1,-1,-1,-1,-1}; + // Fetching opcodes requires strings to be available + // Here we fetch them from the rsrc dir, rather than the data dir + ResMgr::pushPath("../rsrc/strings"); + + oldSpec.ex1a = 2; + oldSpec.ex1b = 10; + oldSpec.ex2a = 4; + oldSpec.ex2b = 20; + oldSpec.jumpto = 12; + SECTION("Place Fire Wall") { + oldSpec.type = 200; + oldSpec.m1 = 4; oldSpec.m2 = 5; + oldSpec.pic = 1; + oldSpec.sd1 = 75; + newSpec.append(oldSpec); + CHECK(newSpec.type == eSpecType::RECT_PLACE_FIELD); + CHECK(newSpec.m1 == 4); CHECK(newSpec.m2 == 5); + CHECK(newSpec.pic == 1); + CHECK(newSpec.sd1 == 75); + CHECK(newSpec.sd2 == WALL_FIRE); + CHECK(newSpec.ex1a == 2); + CHECK(newSpec.ex1b == 10); + CHECK(newSpec.ex2a == 4); + CHECK(newSpec.ex2b == 20); + CHECK(newSpec.jumpto == 12); + } + // Clean up after ourselves + ResMgr::popPath(); +} + +TEST_CASE("When converting legacy special nodes (outdoors)") { + cSpecial newSpec; + legacy::special_node_type oldSpec = {0,-1,-1,0,-1,-1,-1,-1,-1,-1,-1}; + // Fetching opcodes requires strings to be available + // Here we fetch them from the rsrc dir, rather than the data dir + ResMgr::pushPath("../rsrc/strings"); + + oldSpec.jumpto = 12; + SECTION("Make Outdoor Wandering") { + oldSpec.type = 225; + newSpec.append(oldSpec); + CHECK(newSpec.type == eSpecType::OUT_MAKE_WANDER); + CHECK(newSpec.jumpto == 12); + } + // Clean up after ourselves + ResMgr::popPath(); +} + +ostream& operator<< (ostream& out, eSpecType spec) { + out << (*spec).opcode(); + return out; +}