aboutsummaryrefslogtreecommitdiff
path: root/src/libs/dutil/test/DUtilUnitTest
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2022-06-03 17:47:31 -0500
committerSean Hall <r.sean.hall@gmail.com>2022-06-07 19:44:36 -0500
commit8a4d03207633e9fdc364aaed82bd167f844679f9 (patch)
tree9ca862bb51fd3507fc5867c292aef236e3411867 /src/libs/dutil/test/DUtilUnitTest
parent5d35ff01e33b8ffdab04a49ddc5927185309391a (diff)
downloadwix-8a4d03207633e9fdc364aaed82bd167f844679f9.tar.gz
wix-8a4d03207633e9fdc364aaed82bd167f844679f9.tar.bz2
wix-8a4d03207633e9fdc364aaed82bd167f844679f9.zip
Resolve paths while parsing them from the command line.
The current directory is a process wide setting that can potentially be changed by any thread. Remove fileutil methods that had equivalent pathutil methods.
Diffstat (limited to 'src/libs/dutil/test/DUtilUnitTest')
-rw-r--r--src/libs/dutil/test/DUtilUnitTest/DirUtilTests.cpp2
-rw-r--r--src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp129
2 files changed, 130 insertions, 1 deletions
diff --git a/src/libs/dutil/test/DUtilUnitTest/DirUtilTests.cpp b/src/libs/dutil/test/DUtilUnitTest/DirUtilTests.cpp
index 7643366f..14ed7807 100644
--- a/src/libs/dutil/test/DUtilUnitTest/DirUtilTests.cpp
+++ b/src/libs/dutil/test/DUtilUnitTest/DirUtilTests.cpp
@@ -25,7 +25,7 @@ namespace DutilTests
25 hr = GuidCreate(&sczGuid); 25 hr = GuidCreate(&sczGuid);
26 NativeAssert::Succeeded(hr, "Failed to create guid."); 26 NativeAssert::Succeeded(hr, "Failed to create guid.");
27 27
28 hr = DirGetCurrent(&sczCurrentDir); 28 hr = DirGetCurrent(&sczCurrentDir, NULL);
29 NativeAssert::Succeeded(hr, "Failed to get current directory."); 29 NativeAssert::Succeeded(hr, "Failed to get current directory.");
30 30
31 hr = PathConcat(sczCurrentDir, sczGuid, &sczFolder); 31 hr = PathConcat(sczCurrentDir, sczGuid, &sczFolder);
diff --git a/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp b/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp
index 52698b98..554c6f00 100644
--- a/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp
+++ b/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp
@@ -3,6 +3,7 @@
3#include "precomp.h" 3#include "precomp.h"
4 4
5using namespace System; 5using namespace System;
6using namespace System::IO;
6using namespace Xunit; 7using namespace Xunit;
7using namespace WixBuildTools::TestSupport; 8using namespace WixBuildTools::TestSupport;
8 9
@@ -403,6 +404,70 @@ namespace DutilTests
403 } 404 }
404 405
405 [Fact] 406 [Fact]
407 void PathExpandEnvironmentVariablesTest()
408 {
409 HRESULT hr = S_OK;
410 LPWSTR sczExpanded = NULL;
411 LPCWSTR rgwzPaths[4] =
412 {
413 L"", L"",
414 L"\\\\?\\", L"%TEMP%;%PATH%;C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789",
415 };
416
417 try
418 {
419 for (DWORD i = 0; i < countof(rgwzPaths); i += 2)
420 {
421 hr = PathExpand(&sczExpanded, rgwzPaths[i + 1], PATH_EXPAND_ENVIRONMENT);
422 NativeAssert::Succeeded(hr, "PathExpand: {0}", rgwzPaths[i + 1]);
423 WixAssert::StringEqual((gcnew String(rgwzPaths[i])) + Environment::ExpandEnvironmentVariables(gcnew String(rgwzPaths[i + 1])), gcnew String(sczExpanded), false);
424 }
425 }
426 finally
427 {
428 ReleaseStr(sczExpanded);
429 }
430 }
431
432 [Fact]
433 void PathExpandFullPathTest()
434 {
435 HRESULT hr = S_OK;
436 LPWSTR sczExpanded = NULL;
437 LPCWSTR wzGreaterThanMaxPathString = L"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\\a.txt";
438
439 try
440 {
441 hr = PathExpand(&sczExpanded, wzGreaterThanMaxPathString, PATH_EXPAND_FULLPATH);
442 NativeAssert::Succeeded(hr, "Failed to expand greater than MAX_PATH string.");
443 WixAssert::StringEqual((gcnew String("\\\\?\\")) + Path::Combine(Environment::CurrentDirectory, gcnew String(wzGreaterThanMaxPathString)), gcnew String(sczExpanded), false);
444 }
445 finally
446 {
447 ReleaseStr(sczExpanded);
448 }
449 }
450
451 [Fact]
452 void PathExpandAllTest()
453 {
454 HRESULT hr = S_OK;
455 LPWSTR sczExpanded = NULL;
456 LPCWSTR wzRelativeEnvironmentVariableString = L"%USERNAME%\\abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\\a.txt";
457
458 try
459 {
460 hr = PathExpand(&sczExpanded, wzRelativeEnvironmentVariableString, PATH_EXPAND_ENVIRONMENT | PATH_EXPAND_FULLPATH);
461 NativeAssert::Succeeded(hr, "Failed to expand path.");
462 WixAssert::StringEqual((gcnew String("\\\\?\\")) + Path::Combine(Environment::CurrentDirectory, Environment::ExpandEnvironmentVariables(gcnew String(wzRelativeEnvironmentVariableString))), gcnew String(sczExpanded), false);
463 }
464 finally
465 {
466 ReleaseStr(sczExpanded);
467 }
468 }
469
470 [Fact]
406 void PathGetDirectoryTest() 471 void PathGetDirectoryTest()
407 { 472 {
408 HRESULT hr = S_OK; 473 HRESULT hr = S_OK;
@@ -436,6 +501,70 @@ namespace DutilTests
436 } 501 }
437 502
438 [Fact] 503 [Fact]
504 void PathGetFullPathNameTest()
505 {
506 HRESULT hr = S_OK;
507 LPWSTR sczPath = NULL;
508 LPCWSTR wzFileName = NULL;
509 LPCWSTR rgwzPaths[33] =
510 {
511 L"C:\\", L"C:\\", NULL,
512 L"C:\\file", L"C:\\file", L"file",
513 L"C:\\..\\file", L"C:\\file", L"file",
514 L"C:\\dir\\..\\file.txt", L"C:\\file.txt", L"file.txt",
515 L"C:\\dir\\\\file.txt.txt", L"C:\\dir\\file.txt.txt", L"file.txt.txt",
516 L"C:\\dir/.file", L"C:\\dir\\.file", L".file",
517 L"\\\\?\\C:\\file", L"\\\\?\\C:\\file", L"file",
518 L"\\\\server\\share\\file", L"\\\\server\\share\\file", L"file",
519 L"\\\\server\\share\\..\\file", L"\\\\server\\share\\file", L"file",
520 L"\\\\?\\UNC\\server\\share\\file", L"\\\\?\\UNC\\server\\share\\file", L"file",
521 L"C:\\abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\\a.txt", L"C:\\abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\\a.txt", L"a.txt",
522 };
523
524 try
525 {
526 for (DWORD i = 0; i < countof(rgwzPaths); i += 3)
527 {
528 hr = PathGetFullPathName(rgwzPaths[i], &sczPath, &wzFileName, NULL);
529 NativeAssert::Succeeded(hr, "PathGetFullPathName: {0}", rgwzPaths[i]);
530 NativeAssert::StringEqual(rgwzPaths[i + 1], sczPath);
531 NativeAssert::StringEqual(rgwzPaths[i + 2], wzFileName);
532 }
533 }
534 finally
535 {
536 ReleaseStr(sczPath);
537 }
538 }
539
540 [Fact]
541 void PathGetFullPathNameRelativeTest()
542 {
543 HRESULT hr = S_OK;
544 LPWSTR sczPath = NULL;
545 LPCWSTR rgwzPaths[4] =
546 {
547 L"",
548 L"a.txt",
549 L"abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz\\a.txt",
550 };
551
552 try
553 {
554 for (DWORD i = 0; i < countof(rgwzPaths); ++i)
555 {
556 hr = PathGetFullPathName(rgwzPaths[i], &sczPath, NULL, NULL);
557 NativeAssert::Succeeded(hr, "PathGetFullPathName: {0}", rgwzPaths[i]);
558 WixAssert::StringEqual(Path::Combine(Environment::CurrentDirectory, gcnew String(rgwzPaths[i])), gcnew String(sczPath), false);
559 }
560 }
561 finally
562 {
563 ReleaseStr(sczPath);
564 }
565 }
566
567 [Fact]
439 void PathGetHierarchyArrayTest() 568 void PathGetHierarchyArrayTest()
440 { 569 {
441 HRESULT hr = S_OK; 570 HRESULT hr = S_OK;