optional-selftests.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /* Self tests for optional for GDB, the GNU debugger.
  2. Copyright (C) 2017-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  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. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #include "defs.h"
  15. #include "gdbsupport/selftest.h"
  16. #include "gdbsupport/gdb_optional.h"
  17. /* Used by the included .cc files below. Included here because the
  18. included test files are wrapped in a namespace. */
  19. #include <vector>
  20. #include <string>
  21. #include <memory>
  22. /* libstdc++'s testsuite uses VERIFY. */
  23. #define VERIFY SELF_CHECK
  24. /* Used to disable testing features not supported by
  25. gdb::optional. */
  26. #define GDB_OPTIONAL
  27. namespace selftests {
  28. namespace optional {
  29. /* The actual tests live in separate files, which were originally
  30. copied over from libstdc++'s testsuite. To preserve the structure
  31. and help with comparison with the original tests, the file names
  32. have been preserved, and only minimal modification was done to have
  33. them compile against gdb::optional instead of std::optional:
  34. - std::optional->gdb:optional, etc.
  35. - ATTRIBUTE_UNUSED in a few places
  36. - wrap each file in a namespace so they can all be compiled as a
  37. single unit.
  38. - libstdc++'s license and formatting style was preserved.
  39. */
  40. #include "optional/assignment/1.cc"
  41. #include "optional/assignment/2.cc"
  42. #include "optional/assignment/3.cc"
  43. #include "optional/assignment/4.cc"
  44. #include "optional/assignment/5.cc"
  45. #include "optional/assignment/6.cc"
  46. #include "optional/assignment/7.cc"
  47. #include "optional/cons/copy.cc"
  48. #include "optional/cons/default.cc"
  49. #include "optional/cons/move.cc"
  50. #include "optional/cons/value.cc"
  51. #include "optional/in_place.cc"
  52. #include "optional/observers/1.cc"
  53. #include "optional/observers/2.cc"
  54. static void
  55. run_tests ()
  56. {
  57. assign_1::test ();
  58. assign_2::test ();
  59. assign_3::test ();
  60. assign_4::test ();
  61. assign_5::test ();
  62. assign_6::test ();
  63. assign_7::test ();
  64. cons_copy::test ();
  65. cons_default::test ();
  66. cons_move::test ();
  67. cons_value::test ();
  68. in_place::test ();
  69. observers_1::test ();
  70. observers_2::test ();
  71. }
  72. } /* namespace optional */
  73. } /* namespace selftests */
  74. void _initialize_optional_selftests ();
  75. void
  76. _initialize_optional_selftests ()
  77. {
  78. selftests::register_test ("optional", selftests::optional::run_tests);
  79. }