TextHandler.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 "../../src/core/TextHandler.h"
  16. #include <boost/test/unit_test.hpp>
  17. #include <tinyxml.h>
  18. #pragma message("Unimplemented test file: " __FILE__)
  19. BOOST_AUTO_TEST_CASE(TestTextManager){
  20. // TODO
  21. BOOST_WARN_MESSAGE(false, "Unimplemented test file: TextManager");
  22. BOOST_CHECK(0 == 0);
  23. }
  24. namespace{
  25. std::string TextOf(const char* xml){
  26. TiXmlDocument document;
  27. document.Parse(xml);
  28. return TextHandler::ExtractText(
  29. document.RootElement(), [](int id){return std::string("Name") + std::to_string(id);}
  30. );
  31. }
  32. }
  33. BOOST_AUTO_TEST_CASE(TestTextHandlerExtractTextPlain){
  34. BOOST_CHECK_EQUAL(TextOf("<dialog>Sector 5</dialog>"), "Sector 5");
  35. BOOST_CHECK_EQUAL(TextOf("<dialog></dialog>"), "");
  36. }
  37. BOOST_AUTO_TEST_CASE(TestTextHandlerExtractTextStartsWithACharacterName){
  38. // The map name of the house of Tifa. It starts with a tag, which crashed the game.
  39. BOOST_CHECK_EQUAL(TextOf("<dialog><character id=\"3\" />&apos;s House</dialog>"), "Name3's House");
  40. }
  41. BOOST_AUTO_TEST_CASE(TestTextHandlerExtractTextKeepsTheContentOfOtherTags){
  42. BOOST_CHECK_EQUAL(
  43. TextOf("<dialog>A<colour value=\"1 0 0\">[SAVE]</colour>B</dialog>"), "A[SAVE]B"
  44. );
  45. }