PathTest.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include <boost/test/unit_test.hpp>
  2. #include "../Path.h"
  3. using namespace std;
  4. using namespace vconnect;
  5. BOOST_AUTO_TEST_SUITE(PathTest)
  6. BOOST_AUTO_TEST_CASE(getFullPath)
  7. {
  8. #ifdef _MSC_VER
  9. string expected = "C:\\Windows";
  10. string actual = Path::getFullPath("C:\\Windows\\..\\Windows\\..\\Windows");
  11. #else
  12. string expected = "/bin/sh";
  13. string actual = Path::getFullPath( "/bin/../bin/../bin/sh" );
  14. #endif
  15. BOOST_CHECK_EQUAL( expected, actual );
  16. expected = "";
  17. actual = Path::getFullPath( "/bin/ajsfsajfkjfiuehafuakhfakejshfjkafnjk" );
  18. BOOST_CHECK_EQUAL( expected, actual );
  19. };
  20. BOOST_AUTO_TEST_CASE(combine)
  21. {
  22. string separator = Path::getDirectorySeparator();
  23. string actual = Path::combine( "abc" + separator, separator + "def" );
  24. string expected = "abc" + separator + "def";
  25. BOOST_CHECK_EQUAL( expected, actual );
  26. }
  27. BOOST_AUTO_TEST_CASE(getDirectoryName)
  28. {
  29. string separator = Path::getDirectorySeparator();
  30. string actual = Path::getDirectoryName( "aaa" + separator + "bbb" + separator );
  31. string expected = "aaa" + separator + "bbb";
  32. BOOST_CHECK_EQUAL( expected, actual );
  33. actual = Path::getDirectoryName( "aaa" + separator + "bbb" );
  34. expected = "aaa";
  35. BOOST_CHECK_EQUAL( expected, actual );
  36. }
  37. BOOST_AUTO_TEST_CASE(exists)
  38. {
  39. BOOST_CHECK_EQUAL( false, Path::exists( "/bin/sladfjskajfsajfaeiuwfhajkrsfds" ) );
  40. #ifdef _MSC_VER
  41. BOOST_CHECK_EQUAL(true, Path::exists("C:\\Windows"));
  42. #else
  43. BOOST_CHECK_EQUAL( true, Path::exists( "/bin/sh" ) );
  44. #endif
  45. }
  46. BOOST_AUTO_TEST_CASE(testNormalize)
  47. {
  48. #ifdef _MSC_VER
  49. string fixture = "abc/def\\ghi\\jkl/mno";
  50. #else
  51. string fixture = "abc/def\\ghi¥jkl₩mno";
  52. #endif
  53. string separator = Path::getDirectorySeparator();
  54. string expected = "abc" + separator + "def" + separator + "ghi" + separator + "jkl" + separator + "mno";
  55. string actual = Path::normalize( fixture );
  56. BOOST_CHECK_EQUAL( expected, actual );
  57. }
  58. BOOST_AUTO_TEST_CASE(getExtension)
  59. {
  60. string fixture = "A/bcd.hoge";
  61. string expected = ".hoge";
  62. string actual = Path::getExtension(fixture);
  63. BOOST_CHECK_EQUAL(expected, actual);
  64. }
  65. BOOST_AUTO_TEST_SUITE_END()