object_option_test.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 <memory>
  22. #include "editor/object_option.hpp"
  23. #include "supertux/game_object.hpp"
  24. #include "video/color.hpp"
  25. TEST(ObjectOption, to_string)
  26. {
  27. {
  28. std::string mystring = "field";
  29. StringObjectOption textfield("test", &mystring, {}, std::nullopt, 0);
  30. ASSERT_EQ(mystring, textfield.to_string());
  31. }
  32. {
  33. bool mybool = true;
  34. BoolObjectOption field("test", &mybool, {}, {}, 0);
  35. ASSERT_EQ("true", field.to_string());
  36. }
  37. {
  38. int myint = 73258;
  39. IntObjectOption intfield("test", &myint, {}, {}, 0);
  40. ASSERT_EQ("73258", intfield.to_string());
  41. }
  42. {
  43. float myfloat = 2.125;
  44. FloatObjectOption numfield("test", &myfloat, {}, {}, 0);
  45. ASSERT_EQ("2.125", numfield.to_string());
  46. }
  47. {
  48. std::vector<std::string> select = {"foo", "bar"};
  49. enum FooBar {
  50. FOO, BAR
  51. };
  52. FooBar fb1 = FOO;
  53. FooBar fb2 = BAR;
  54. StringSelectObjectOption stringselect1("test", reinterpret_cast<int*>(&fb1), select, {}, {}, 0);
  55. StringSelectObjectOption stringselect2("test", reinterpret_cast<int*>(&fb2), select, {}, {}, 0);
  56. ASSERT_EQ("foo", stringselect1.to_string());
  57. ASSERT_EQ("bar", stringselect2.to_string());
  58. }
  59. {
  60. class TestObject : public GameObject
  61. {
  62. public:
  63. TestObject() : GameObject() {}
  64. void draw(DrawingContext&) override {}
  65. void update(float) override {}
  66. };
  67. std::vector<std::unique_ptr<GameObject>> select;
  68. select.push_back(std::make_unique<TestObject>());
  69. select.push_back(std::make_unique<TestObject>());
  70. select.push_back(std::make_unique<TestObject>());
  71. ObjectSelectObjectOption objectselect("test", &select, 0, {}, {}, 0);
  72. ASSERT_EQ("3", objectselect.to_string());
  73. }
  74. {
  75. Color mycolor = Color::YELLOW;
  76. ColorObjectOption color("test", &mycolor, {}, {}, false, 0);
  77. ASSERT_EQ("1.000000 1.000000 0.000000", color.to_string());
  78. }
  79. {
  80. std::string myscript = "sector.set_trolling_mode(true)";
  81. ScriptObjectOption script("text", &myscript, {}, 0);
  82. ASSERT_EQ("...", script.to_string());
  83. }
  84. }
  85. /* EOF */