child-path-selftests.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* Self tests for child_path for GDB, the GNU debugger.
  2. Copyright (C) 2019-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/pathstuff.h"
  16. #include "gdbsupport/selftest.h"
  17. namespace selftests {
  18. namespace child_path {
  19. /* Verify the result of a single child_path test. */
  20. static bool
  21. child_path_check (const char *parent, const char *child, const char *expected)
  22. {
  23. const char *result = ::child_path (parent, child);
  24. if (result == NULL || expected == NULL)
  25. return result == expected;
  26. return strcmp (result, expected) == 0;
  27. }
  28. /* Test child_path. */
  29. static void
  30. test ()
  31. {
  32. SELF_CHECK (child_path_check ("/one", "/two", NULL));
  33. SELF_CHECK (child_path_check ("/one", "/one", NULL));
  34. SELF_CHECK (child_path_check ("/one", "/one/", NULL));
  35. SELF_CHECK (child_path_check ("/one", "/one//", NULL));
  36. SELF_CHECK (child_path_check ("/one", "/one/two", "two"));
  37. SELF_CHECK (child_path_check ("/one/", "/two", NULL));
  38. SELF_CHECK (child_path_check ("/one/", "/one", NULL));
  39. SELF_CHECK (child_path_check ("/one/", "/one/", NULL));
  40. SELF_CHECK (child_path_check ("/one/", "/one//", NULL));
  41. SELF_CHECK (child_path_check ("/one/", "/one/two", "two"));
  42. SELF_CHECK (child_path_check ("/one/", "/one//two", "two"));
  43. SELF_CHECK (child_path_check ("/one/", "/one//two/", "two/"));
  44. SELF_CHECK (child_path_check ("/one", "/onetwo", NULL));
  45. SELF_CHECK (child_path_check ("/one", "/onetwo/three", NULL));
  46. }
  47. }
  48. }
  49. void _initialize_child_path_selftests ();
  50. void
  51. _initialize_child_path_selftests ()
  52. {
  53. selftests::register_test ("child_path",
  54. selftests::child_path::test);
  55. }