Fix possible problems with "intend to add" staged files
[TortoiseGit.git] / test / UnitTests / PathUtilsTest.cpp
blobe5b05a0d9b2156b6b34c0a738d933dc7355cbe79
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2015 - TortoiseGit
4 // Copyright (C) 2003-2008, 2013-2014 - TortoiseSVN
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.
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.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "stdafx.h"
22 #include "PathUtils.h"
24 TEST(CPathUtils, UnescapeTest)
26 CString test(_T("file:///d:/REpos1/uCOS-100/Trunk/name%20with%20spaces/NewTest%20%%20NewTest"));
27 CString test2 = CPathUtils::PathUnescape(test);
28 EXPECT_TRUE(test2.Compare(_T("file:///d:/REpos1/uCOS-100/Trunk/name with spaces/NewTest % NewTest")) == 0);
29 CStringA test3 = CPathUtils::PathEscape("file:///d:/REpos1/uCOS-100/Trunk/name with spaces/NewTest % NewTest");
30 EXPECT_TRUE(test3.Compare("file:///d:/REpos1/uCOS-100/Trunk/name%20with%20spaces/NewTest%20%%20NewTest") == 0);
33 TEST(CPathUtils, ExtTest)
35 CString test(_T("d:\\test\filename.ext"));
36 EXPECT_TRUE(CPathUtils::GetFileExtFromPath(test).Compare(_T(".ext")) == 0);
37 test = _T("filename.ext");
38 EXPECT_TRUE(CPathUtils::GetFileExtFromPath(test).Compare(_T(".ext")) == 0);
39 test = _T("d:\\test\filename");
40 EXPECT_TRUE(CPathUtils::GetFileExtFromPath(test).IsEmpty());
41 test = _T("filename");
42 EXPECT_TRUE(CPathUtils::GetFileExtFromPath(test).IsEmpty());
45 TEST(CPathUtils, ParseTests)
47 CString test(_T("test 'd:\\testpath with spaces' test"));
48 EXPECT_TRUE(CPathUtils::ParsePathInString(test).Compare(_T("d:\\testpath with spaces")) == 0);
49 test = _T("d:\\testpath with spaces");
50 EXPECT_TRUE(CPathUtils::ParsePathInString(test).Compare(_T("d:\\testpath with spaces")) == 0);
53 TEST(CPathUtils, MakeSureDirectoryPathExists)
55 CAutoTempDir tmpDir;
56 EXPECT_TRUE(PathIsDirectory(tmpDir.GetTempDir()));
57 EXPECT_FALSE(PathFileExists(tmpDir.GetTempDir() + L"\\sub"));
58 EXPECT_FALSE(PathIsDirectory(tmpDir.GetTempDir() + L"\\sub"));
60 EXPECT_TRUE(CPathUtils::MakeSureDirectoryPathExists(tmpDir.GetTempDir() + L"\\sub\\sub\\dir"));
61 EXPECT_TRUE(PathIsDirectory(tmpDir.GetTempDir() + L"\\sub"));
62 EXPECT_TRUE(PathIsDirectory(tmpDir.GetTempDir() + L"\\sub\\sub"));
63 EXPECT_TRUE(PathIsDirectory(tmpDir.GetTempDir() + L"\\sub\\sub\\dir"));
65 EXPECT_TRUE(CPathUtils::MakeSureDirectoryPathExists(tmpDir.GetTempDir() + L"\\sub/asub/adir"));
66 EXPECT_TRUE(PathIsDirectory(tmpDir.GetTempDir() + L"\\sub"));
67 EXPECT_TRUE(PathIsDirectory(tmpDir.GetTempDir() + L"\\sub\\asub"));
68 EXPECT_TRUE(PathIsDirectory(tmpDir.GetTempDir() + L"\\sub\\asub\\adir"));