From b5facb5bfef35ddd3020b249411d0fa4395f1e4e Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Fri, 5 Aug 2016 15:12:23 -0400 Subject: [PATCH] Add test case for loading legacy scenario header data --- src/BoE.xcodeproj/project.pbxproj | 4 + test/catch.cpp | 1 + test/scen_legacy.cpp | 131 ++++++++++++++++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 test/scen_legacy.cpp diff --git a/src/BoE.xcodeproj/project.pbxproj b/src/BoE.xcodeproj/project.pbxproj index 37e0d563..600ddea4 100755 --- a/src/BoE.xcodeproj/project.pbxproj +++ b/src/BoE.xcodeproj/project.pbxproj @@ -105,6 +105,7 @@ 9169C3211B3B23530041002B /* libboost_thread.dylib in Copy Libraries and Frameworks */ = {isa = PBXBuildFile; fileRef = 910D9CA31B36439100414B17 /* libboost_thread.dylib */; }; 9169C3231B3B235A0041002B /* libboost_thread.dylib in Copy Libraries and Frameworks */ = {isa = PBXBuildFile; fileRef = 910D9CA31B36439100414B17 /* libboost_thread.dylib */; }; 9169C3241B3B23610041002B /* libboost_thread.dylib in Copy Libraries and Frameworks */ = {isa = PBXBuildFile; fileRef = 910D9CA31B36439100414B17 /* libboost_thread.dylib */; }; + 9176FEC81D550EFE006EF694 /* scen_legacy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9176FEC11D550EFC006EF694 /* scen_legacy.cpp */; }; 9178235D1B2EA0C5007F3444 /* vorbisenc.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9178235C1B2EA0C5007F3444 /* vorbisenc.framework */; }; 9178235E1B2EA0C5007F3444 /* vorbisenc.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9178235C1B2EA0C5007F3444 /* vorbisenc.framework */; }; 9178235F1B2EA0C5007F3444 /* vorbisenc.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9178235C1B2EA0C5007F3444 /* vorbisenc.framework */; }; @@ -649,6 +650,7 @@ 9169C31B1B37A5D50041002B /* Blades of Exile.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Blades of Exile.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 9169C31D1B37A5D50041002B /* BoE Character Editor.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "BoE Character Editor.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 9169C31F1B37A5D50041002B /* BoE Scenario Editor.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "BoE Scenario Editor.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 9176FEC11D550EFC006EF694 /* scen_legacy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = scen_legacy.cpp; sourceTree = ""; }; 9178235C1B2EA0C5007F3444 /* vorbisenc.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = vorbisenc.framework; path = ../../../../../../Library/Frameworks/vorbisenc.framework; sourceTree = ""; }; 917823671B2F32DD007F3444 /* vorbisfile.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = vorbisfile.framework; path = ../../../../../../Library/Frameworks/vorbisfile.framework; sourceTree = ""; }; 9178236E1B2F331D007F3444 /* vorbis.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = vorbis.framework; path = ../../../../../../Library/Frameworks/vorbis.framework; sourceTree = ""; }; @@ -1360,6 +1362,7 @@ 91EF277C1B693D7D00666469 /* monst_write.cpp */, 91C2A6ED1B8FA9FB00346948 /* out_read.cpp */, 91E381491B97678D00F69B81 /* out_write.cpp */, + 9176FEC11D550EFC006EF694 /* scen_legacy.cpp */, 91CC173A1B421CA0003D9A69 /* scen_read.cpp */, 91CC173B1B421CA0003D9A69 /* scen_write.cpp */, 919B13A51BBDE985009905A4 /* spec_legacy.cpp */, @@ -1902,6 +1905,7 @@ 919B13A61BBDE986009905A4 /* spec_legacy.cpp in Sources */, 91E128E41BC1624700C8BE1D /* ter_legacy.cpp in Sources */, 91E128E61BC19DA400C8BE1D /* init.cpp in Sources */, + 9176FEC81D550EFE006EF694 /* scen_legacy.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/test/catch.cpp b/test/catch.cpp index ae04b821..612d2f78 100644 --- a/test/catch.cpp +++ b/test/catch.cpp @@ -13,3 +13,4 @@ cCustomGraphics spec_scen_g; location cur_out; short cur_town; cScenario scenario; +bool change_made; diff --git a/test/scen_legacy.cpp b/test/scen_legacy.cpp new file mode 100644 index 00000000..32d04fec --- /dev/null +++ b/test/scen_legacy.cpp @@ -0,0 +1,131 @@ +// +// scen_legacy.cpp +// BoE +// +// Created by Celtic Minstrel on 16-08-05. +// +// + +#include "catch.hpp" +#include "scenario.hpp" +#include "oldstructs.hpp" + +TEST_CASE("Converting legacy scenario data") { + legacy::scenario_data_type old_scen = { + 2, 2, 1, 27, 0, + {1, 1}, // town sizes + {false, true}, // town hidden + 0x0B0E, // password flag A + 28, 8, + 0, // padding + {3,3}, + {4,4}, {1,1}, + 3, + 0x0B0E, // password flag B + {{0}}, // town data size; not relevant for loading just the header + {1}, {{2,7}}, + 0x0B0E, // password flag C + {0}, // out data size; not relevant for loading just the header + {{1,2,3,4}, {2,4,6,8}, {1,8,2,9}}, + {0, 1, 2}, + 0x0B0E, // password flag E + {5, 9}, {12, -1}, // special items + 2, false, + 0x0B0E, // password flag F + {0}, // monsters; tested separately + { // boats + { + {33,33}, {22,22}, {1,1}, + 2, true, true + } + }, + {0}, // horses; same as boats, so not tested + 0x0B0E, // password flag G + {0}, // terrains; tested separately + {100, 1200}, {3, 88, -1}, // timers + 0x0B0E, // password flag H + {0}, // specials; tested separately + { // item placement shortcuts + {12, {1,2,3,4,5,6,7,8,9,10}, {10,15,20,25,30,35,40,45,50,55}, true} + }, + 0x0B0E, // password flag D + {0}, // string lengths; not relevant for loading just the header + 0x0B0E, // password flag I + {1,1}, + 2 + }; + cScenario scen; + scen.append(old_scen); + + SECTION("Basic header data") { + CHECK(scen.adjust_diff); + CHECK(scen.bg_dungeon == 9); + CHECK(scen.bg_fight == 4); + CHECK(scen.bg_out == 10); + CHECK(scen.bg_town == 13); + CHECK(scen.campaign_id.empty()); + CHECK(scen.custom_graphics.empty()); + CHECK(scen.default_ground == 0); + CHECK(scen.difficulty == 1); + CHECK(scen.init_spec == -1); + CHECK(scen.intro_mess_pic == 27); + CHECK(scen.intro_pic == 27); + CHECK(scen.is_legacy); + CHECK(scen.journal_strs.empty()); + CHECK(scen.last_out_edited == loc(1,1)); + CHECK(scen.last_town_edited == 2); + CHECK(scen.out_sec_start == loc(4,4)); + CHECK(scen.out_start == loc(1,1)); + CHECK(scen.rating == eContentRating::R); + CHECK(scen.shops.empty()); + CHECK_FALSE(scen.uses_custom_graphics); + CHECK(scen.where_start == loc(3,3)); + CHECK(scen.which_town_start == 3); + } + SECTION("With boats") { + REQUIRE(scen.boats.size() >= 1); + CHECK(scen.boats[0].exists); + CHECK(scen.boats[0].loc == loc(33,33)); + CHECK(scen.boats[0].loc_in_sec == loc(22,22)); + CHECK(scen.boats[0].property); + CHECK(scen.boats[0].sector == loc(1,1)); + CHECK(scen.boats[0].which_town == 2); + } + SECTION("With special items") { + REQUIRE(scen.special_items.size() >= 2); + CHECK(scen.special_items[0].flags == 5); + CHECK(scen.special_items[0].special == 12); + CHECK(scen.special_items[1].flags == 9); + CHECK(scen.special_items[1].special == -1); + } + SECTION("With item storage rects") { + REQUIRE(scen.store_item_rects.size() >= 3); + REQUIRE(scen.store_item_towns.size() >= 3); + CHECK(scen.store_item_rects[0] == rect(1,2,3,4)); + CHECK(scen.store_item_towns[0] == 0); + CHECK(scen.store_item_rects[1] == rect(2,4,6,8)); + CHECK(scen.store_item_towns[1] == 1); + CHECK(scen.store_item_rects[2] == rect(1,8,2,9)); + CHECK(scen.store_item_towns[2] == 2); + } + SECTION("With item storage shortcuts") { + REQUIRE(scen.storage_shortcuts.size() >= 1); + CHECK(scen.storage_shortcuts[0].ter_type == 12); + CHECK(scen.storage_shortcuts[0].property); + for(int i = 0; i < 10; i++) { + int item_num = old_scen.storage_shortcuts[0].item_num[i]; + CAPTURE(i); + CAPTURE(item_num); + CHECK(scen.storage_shortcuts[0].item_num[i] == item_num); + int item_odds = old_scen.storage_shortcuts[0].item_odds[i]; + CAPTURE(i); + CAPTURE(item_odds); + CHECK(scen.storage_shortcuts[0].item_odds[i] == item_odds); + } + } + SECTION("With town mods") { + REQUIRE(scen.town_mods.size() >= 1); + CHECK(scen.town_mods[0].spec == 1); + CHECK(scen.town_mods[0] == loc(2,7)); + } +}