object_option_test.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. ObjectOption textfield(MN_TEXTFIELD, "test", &mystring);
  28. ASSERT_EQ(mystring, textfield.to_string());
  29. }
  30. {
  31. int myint = 73258;
  32. ObjectOption intfield(MN_INTFIELD, "test", &myint);
  33. ASSERT_EQ("73258", intfield.to_string());
  34. }
  35. {
  36. float myfloat = 2.125;
  37. ObjectOption numfield(MN_NUMFIELD, "test", &myfloat);
  38. ASSERT_EQ("2.125000", numfield.to_string());
  39. }
  40. {
  41. std::vector<std::string> select;
  42. select.push_back("foo");
  43. select.push_back("bar");
  44. enum FooBar {
  45. FOO, BAR
  46. };
  47. FooBar fb1 = FOO;
  48. FooBar fb2 = BAR;
  49. ObjectOption stringselect1(MN_STRINGSELECT, "test", &fb1);
  50. stringselect1.select = select;
  51. ObjectOption stringselect2(MN_STRINGSELECT, "test", &fb2);
  52. stringselect2.select = select;
  53. ASSERT_EQ("foo", stringselect1.to_string());
  54. ASSERT_EQ("bar", stringselect2.to_string());
  55. }
  56. {
  57. std::vector<std::string> select;
  58. select.push_back("foo");
  59. select.push_back("bar");
  60. select.push_back("blb");
  61. ObjectOption badguyselect(MN_BADGUYSELECT, "test", &select);
  62. ASSERT_EQ("3", badguyselect.to_string());
  63. }
  64. {
  65. Color mycolor = Color::YELLOW;
  66. ObjectOption color(MN_COLOR, "test", &mycolor);
  67. ASSERT_EQ("1.000000 1.000000 0.000000", color.to_string());
  68. }
  69. {
  70. std::string myscript = "sector.set_trolling_mode(true)";
  71. ObjectOption script(MN_SCRIPT, "text", &myscript);
  72. ASSERT_EQ("...", script.to_string());
  73. }
  74. }
  75. /* EOF */