object_option_test.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // SuperTux
  2. // Copyright (C) 2016 Hume2 <teratux.mail@gmail.com>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #include <gtest/gtest.h>
  17. #include <iostream>
  18. #include <errno.h>
  19. #include <string.h>
  20. #include <vector>
  21. #include "editor/object_option.hpp"
  22. #include "video/color.hpp"
  23. TEST(ObjectOption, to_string)
  24. {
  25. {
  26. std::string mystring = "field";
  27. StringObjectOption textfield("test", &mystring, {}, boost::none, 0);
  28. ASSERT_EQ(mystring, textfield.to_string());
  29. }
  30. {
  31. bool mybool = true;
  32. BoolObjectOption field("test", &mybool, {}, {}, 0);
  33. ASSERT_EQ("true", field.to_string());
  34. }
  35. {
  36. int myint = 73258;
  37. IntObjectOption intfield("test", &myint, {}, {}, 0);
  38. ASSERT_EQ("73258", intfield.to_string());
  39. }
  40. {
  41. float myfloat = 2.125;
  42. FloatObjectOption numfield("test", &myfloat, {}, {}, 0);
  43. ASSERT_EQ("2.125", numfield.to_string());
  44. }
  45. {
  46. std::vector<std::string> select = {"foo", "bar"};
  47. enum FooBar {
  48. FOO, BAR
  49. };
  50. FooBar fb1 = FOO;
  51. FooBar fb2 = BAR;
  52. StringSelectObjectOption stringselect1("test", reinterpret_cast<int*>(&fb1), select, {}, {}, 0);
  53. StringSelectObjectOption stringselect2("test", reinterpret_cast<int*>(&fb2), select, {}, {}, 0);
  54. ASSERT_EQ("foo", stringselect1.to_string());
  55. ASSERT_EQ("bar", stringselect2.to_string());
  56. }
  57. {
  58. std::vector<std::string> select = {"foo", "bar", "blb"};
  59. BadGuySelectObjectOption badguyselect("test", &select, {}, 0);
  60. ASSERT_EQ("3", badguyselect.to_string());
  61. }
  62. {
  63. Color mycolor = Color::YELLOW;
  64. ColorObjectOption color("test", &mycolor, {}, {}, false, 0);
  65. ASSERT_EQ("1.000000 1.000000 0.000000", color.to_string());
  66. }
  67. {
  68. std::string myscript = "sector.set_trolling_mode(true)";
  69. ScriptObjectOption script("text", &myscript, {}, 0);
  70. ASSERT_EQ("...", script.to_string());
  71. }
  72. }
  73. /* EOF */