From ac5cbe3a609d87b9d9cd34261d59ed44f1042ab9 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Fri, 6 Jan 2023 01:20:38 -0700 Subject: [PATCH] Test case for dialog XMLs in-engine --- src/fileio/resmgr/res_dialog.cpp | 22 +++++++++++++--------- src/fileio/resmgr/res_dialog.hpp | 2 ++ test/dialogs.cpp | 30 ++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 test/dialogs.cpp diff --git a/src/fileio/resmgr/res_dialog.cpp b/src/fileio/resmgr/res_dialog.cpp index 245250d2..49a36603 100644 --- a/src/fileio/resmgr/res_dialog.cpp +++ b/src/fileio/resmgr/res_dialog.cpp @@ -16,15 +16,7 @@ extern std::ostream& std_fmterr(std::ostream& out); class DialogLoader : public ResMgr::cLoader { /// Load a dialog definition from an XML file. DialogDefn* operator() (const fs::path& fpath) const override { - TiXmlBase::SetCondenseWhiteSpace(false); - ticpp::Document xml(fpath.string().c_str()); - try { - xml.LoadFile(); - } catch(ticpp::Exception& e) { - std::cerr << "Error reading XML file: " << e.what(); - throw ResMgr::xError(ResMgr::ERR_LOAD, "Failed to load dialog: " + fpath.string()); - } - return new DialogDefn{fpath.stem().string(), std::move(xml)}; + return load_dialog_defn(fpath); } ResourceList expand(const std::string& name) const override { @@ -36,6 +28,18 @@ class DialogLoader : public ResMgr::cLoader { } }; +DialogDefn* load_dialog_defn(const fs::path& fpath) { + TiXmlBase::SetCondenseWhiteSpace(false); + ticpp::Document xml(fpath.string().c_str()); + try { + xml.LoadFile(); + } catch(ticpp::Exception& e) { + std::cerr << "Error reading XML file: " << e.what(); + throw ResMgr::xError(ResMgr::ERR_LOAD, "Failed to load dialog: " + fpath.string()); + } + return new DialogDefn{fpath.stem().string(), std::move(xml)}; +} + // TODO: What's a good max dialogs count? static DialogLoader loader; ResMgr::cPool ResMgr::dialogs(loader, 80); diff --git a/src/fileio/resmgr/res_dialog.hpp b/src/fileio/resmgr/res_dialog.hpp index c1a4723c..eeec7100 100644 --- a/src/fileio/resmgr/res_dialog.hpp +++ b/src/fileio/resmgr/res_dialog.hpp @@ -19,6 +19,8 @@ struct DialogDefn { /// The XML definition of the dialog. ticpp::Document defn; }; +/// Load a dialog definition from an XML file. +DialogDefn* load_dialog_defn(const fs::path& fpath); using DialogRsrc = ResMgr::cPointer; diff --git a/test/dialogs.cpp b/test/dialogs.cpp new file mode 100644 index 00000000..26219d7b --- /dev/null +++ b/test/dialogs.cpp @@ -0,0 +1,30 @@ +// +// dialogs.cpp +// BoE +// +// Created by Nat Nelson on 2023-01-06 +// + +#include "catch.hpp" +#include +#include "fileio/resmgr/res_dialog.hpp" +#include "dialogxml/dialogs/dialog.hpp" + +TEST_CASE("Construct each type of dialog in the engine") { + fs::path dialogsPath = fs::current_path()/".."/"Blades of Exile"/"data"/"dialogs"; + fs::directory_iterator it{dialogsPath}; + auto end = fs::directory_iterator{}; + + while (it != end) { + fs::path path = it->path(); + std::string filename = path.stem().string(); + CAPTURE(filename); + CHECK_NOTHROW({ + DialogDefn* defn = load_dialog_defn(path); + cDialog dialog(*defn); + delete defn; + }); + + ++it; + } +} \ No newline at end of file