testlongwinpath.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * libcsync -- a library to sync a directory with another
  3. *
  4. * Copyright (c) 2013 by Klaas Freitag <freitag@owncloud.com>
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library 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 GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "common/filesystembase.h"
  21. #include <QTest>
  22. class TestLongWindowsPath : public QObject
  23. {
  24. Q_OBJECT
  25. private Q_SLOTS:
  26. void check_long_win_path()
  27. {
  28. {
  29. const auto path = QStringLiteral("C://DATA/FILES/MUSIC/MY_MUSIC.mp3"); // check a short path
  30. const auto exp_path = QStringLiteral("\\\\?\\C:\\\\DATA\\FILES\\MUSIC\\MY_MUSIC.mp3");
  31. QString new_short = OCC::FileSystem::pathtoUNC(path);
  32. QCOMPARE(new_short, exp_path);
  33. }
  34. {
  35. const auto path = QStringLiteral("\\\\foo\\bar/MY_MUSIC.mp3");
  36. const auto exp_path = QStringLiteral("\\\\foo\\bar\\MY_MUSIC.mp3");
  37. QString new_short = OCC::FileSystem::pathtoUNC(path);
  38. QCOMPARE(new_short, exp_path);
  39. }
  40. {
  41. const auto path = QStringLiteral("//foo\\bar/MY_MUSIC.mp3");
  42. const auto exp_path = QStringLiteral("\\\\foo\\bar\\MY_MUSIC.mp3");
  43. QString new_short = OCC::FileSystem::pathtoUNC(path);
  44. QCOMPARE(new_short, exp_path);
  45. }
  46. {
  47. const auto path = QStringLiteral("\\foo\\bar");
  48. const auto exp_path = QStringLiteral("\\\\?\\foo\\bar");
  49. QString new_short = OCC::FileSystem::pathtoUNC(path);
  50. QCOMPARE(new_short, exp_path);
  51. }
  52. {
  53. const auto path = QStringLiteral("/foo/bar");
  54. const auto exp_path = QStringLiteral("\\\\?\\foo\\bar");
  55. QString new_short = OCC::FileSystem::pathtoUNC(path);
  56. QCOMPARE(new_short, exp_path);
  57. }
  58. const auto longPath = QStringLiteral("D://alonglonglonglong/blonglonglonglong/clonglonglonglong/dlonglonglonglong/"
  59. "elonglonglonglong/flonglonglonglong/glonglonglonglong/hlonglonglonglong/ilonglonglonglong/"
  60. "jlonglonglonglong/klonglonglonglong/llonglonglonglong/mlonglonglonglong/nlonglonglonglong/"
  61. "olonglonglonglong/file.txt");
  62. const auto longPathConv = QStringLiteral("\\\\?\\D:\\\\alonglonglonglong\\blonglonglonglong\\clonglonglonglong\\dlonglonglonglong\\"
  63. "elonglonglonglong\\flonglonglonglong\\glonglonglonglong\\hlonglonglonglong\\ilonglonglonglong\\"
  64. "jlonglonglonglong\\klonglonglonglong\\llonglonglonglong\\mlonglonglonglong\\nlonglonglonglong\\"
  65. "olonglonglonglong\\file.txt");
  66. QString new_long = OCC::FileSystem::pathtoUNC(longPath);
  67. // printf( "XXXXXXXXXXXX %s %d\n", new_long, mem_reserved);
  68. QCOMPARE(new_long, longPathConv);
  69. // printf( "YYYYYYYYYYYY %ld\n", strlen(new_long));
  70. QCOMPARE(new_long.length(), 286);
  71. }
  72. };
  73. QTEST_GUILESS_MAIN(TestLongWindowsPath)
  74. #include "testlongwinpath.moc"