You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.1 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2019 KiCad Developers, see CHANGELOG.TXT for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. /**
  24. * @file
  25. * Test suite for WX_FILNAME
  26. */
  27. #include <unit_test_utils/unit_test_utils.h>
  28. // Code under test
  29. #include <common.h>
  30. /**
  31. * Declare the test suite
  32. */
  33. BOOST_AUTO_TEST_SUITE( WxFilename )
  34. struct WX_FILENAME_SPLIT_CASE
  35. {
  36. // Ctor params
  37. std::string m_path;
  38. std::string m_name;
  39. // Split results
  40. std::string m_exp_name;
  41. std::string m_exp_full_name;
  42. std::string m_exp_path;
  43. std::string m_exp_full_path;
  44. };
  45. // clang-format off
  46. static const std::vector<WX_FILENAME_SPLIT_CASE> split_cases = {
  47. {
  48. "",
  49. "",
  50. "",
  51. "",
  52. "",
  53. "/", // This doesn't look right...
  54. },
  55. {
  56. "",
  57. "name.ext",
  58. "name",
  59. "name.ext",
  60. "",
  61. "/name.ext", // This doesn't look right...
  62. },
  63. {
  64. "/tmp/example",
  65. "",
  66. "",
  67. "",
  68. "/tmp/example",
  69. "/tmp/example/",
  70. },
  71. {
  72. "/tmp/example",
  73. "name.ext",
  74. "name",
  75. "name.ext",
  76. "/tmp/example",
  77. "/tmp/example/name.ext",
  78. },
  79. {
  80. "/tmp/example",
  81. "name", // no extension
  82. "name",
  83. "name",
  84. "/tmp/example",
  85. "/tmp/example/name",
  86. },
  87. {
  88. "/tmp/example",
  89. "name.ext1.ext2", // two extensions
  90. "name.ext1", // remove the first one
  91. "name.ext1.ext2",
  92. "/tmp/example",
  93. "/tmp/example/name.ext1.ext2",
  94. },
  95. };
  96. // clang-format on
  97. /**
  98. * Check the various split cases work correctly
  99. */
  100. BOOST_AUTO_TEST_CASE( Split )
  101. {
  102. for( const auto& c : split_cases )
  103. {
  104. std::stringstream ss;
  105. ss << c.m_path << ", " << c.m_name;
  106. BOOST_TEST_CONTEXT( ss.str() )
  107. {
  108. // Const: all methods called must be const
  109. const WX_FILENAME wx_fn( c.m_path, c.m_name );
  110. BOOST_CHECK_EQUAL( c.m_exp_name, wx_fn.GetName() );
  111. BOOST_CHECK_EQUAL( c.m_exp_full_name, wx_fn.GetFullName() );
  112. BOOST_CHECK_EQUAL( c.m_exp_path, wx_fn.GetPath() );
  113. BOOST_CHECK_EQUAL( c.m_exp_full_path, wx_fn.GetFullPath() );
  114. }
  115. }
  116. }
  117. BOOST_AUTO_TEST_SUITE_END()