Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

65 строки
1.6 KiB

  1. //
  2. // Lol Engine — Unit tests
  3. //
  4. // Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
  5. //
  6. // Lol Engine is free software. It comes without any warranty, to
  7. // the extent permitted by applicable law. You can redistribute it
  8. // and/or modify it under the terms of the Do What the Fuck You Want
  9. // to Public License, Version 2, as published by the WTFPL Task Force.
  10. // See http://www.wtfpl.net/ for more details.
  11. //
  12. #include <lol/engine-internal.h>
  13. #include <lolunit.h>
  14. #include <string>
  15. #include <map>
  16. namespace lol
  17. {
  18. lolunit_declare_fixture(enum_test)
  19. {
  20. lolunit_declare_test(enum_to_string)
  21. {
  22. struct my_enum_base : public StructSafeEnum
  23. {
  24. enum Type
  25. {
  26. first = -10,
  27. second,
  28. third = 5,
  29. };
  30. protected:
  31. virtual bool BuildEnumMap(std::map<int64_t, std::string>& enum_map)
  32. {
  33. enum_map[first] = "first";
  34. enum_map[second] = "second";
  35. enum_map[third] = "third";
  36. return true;
  37. }
  38. };
  39. typedef SafeEnum<my_enum_base> my_enum;
  40. my_enum e = my_enum::first;
  41. lolunit_assert(e.tostring() == "first");
  42. e = my_enum::second;
  43. lolunit_assert(e.tostring() == "second");
  44. e = my_enum::third;
  45. lolunit_assert(e.tostring() == "third");
  46. e = my_enum(42);
  47. lolunit_assert(e.tostring() != "first");
  48. lolunit_assert(e.tostring() != "second");
  49. lolunit_assert(e.tostring() != "third");
  50. }
  51. };
  52. } /* namespace lol */