TextHandler.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include "engine/ui/TextHandler.h"
  16. #include <boost/test/unit_test.hpp>
  17. #include <tinyxml.h>
  18. namespace{
  19. std::string TextOf(const char* xml){
  20. TiXmlDocument document;
  21. document.Parse(xml);
  22. return TextHandler::ExtractText(
  23. document.RootElement(), [](int id){return std::string("Name") + std::to_string(id);}
  24. );
  25. }
  26. }
  27. BOOST_AUTO_TEST_CASE(TestTextHandlerExtractTextPlain){
  28. BOOST_CHECK_EQUAL(TextOf("<dialog>Sector 5</dialog>"), "Sector 5");
  29. BOOST_CHECK_EQUAL(TextOf("<dialog></dialog>"), "");
  30. }
  31. BOOST_AUTO_TEST_CASE(TestTextHandlerExtractTextStartsWithACharacterName){
  32. // The map name of the house of Tifa. It starts with a tag, which crashed the game.
  33. BOOST_CHECK_EQUAL(TextOf("<dialog><character id=\"3\" />&apos;s House</dialog>"), "Name3's House");
  34. }
  35. BOOST_AUTO_TEST_CASE(TestTextHandlerExtractTextKeepsTheContentOfOtherTags){
  36. BOOST_CHECK_EQUAL(
  37. TextOf("<dialog>A<colour value=\"1 0 0\">[SAVE]</colour>B</dialog>"), "A[SAVE]B"
  38. );
  39. }