aboutsummaryrefslogtreecommitdiff
path: root/src/libs/dutil/test/DUtilUnitTest
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/dutil/test/DUtilUnitTest')
-rw-r--r--src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj2
-rw-r--r--src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters4
-rw-r--r--src/libs/dutil/test/DUtilUnitTest/FileUtilTest.cpp74
-rw-r--r--src/libs/dutil/test/DUtilUnitTest/LocControlsUtilTests.cpp11
-rw-r--r--src/libs/dutil/test/DUtilUnitTest/LocStringsUtilTests.cpp11
-rw-r--r--src/libs/dutil/test/DUtilUnitTest/MonUtilTest.cpp896
-rw-r--r--src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp76
-rw-r--r--src/libs/dutil/test/DUtilUnitTest/StrUtilTest.cpp210
8 files changed, 754 insertions, 530 deletions
diff --git a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj
index fccb73c4..e12eac00 100644
--- a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj
+++ b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj
@@ -1,7 +1,7 @@
1<?xml version="1.0" encoding="utf-8"?> 1<?xml version="1.0" encoding="utf-8"?>
2<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. --> 2<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. -->
3 3
4<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 4<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
5 <Import Project="..\..\..\..\internal\WixInternal.TestSupport.Native\build\WixInternal.TestSupport.Native.props" /> 5 <Import Project="..\..\..\..\internal\WixInternal.TestSupport.Native\build\WixInternal.TestSupport.Native.props" />
6 6
7 <ItemGroup Label="ProjectConfigurations"> 7 <ItemGroup Label="ProjectConfigurations">
diff --git a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters
index e4972c1a..b236ed80 100644
--- a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters
+++ b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters
@@ -1,5 +1,5 @@
1<?xml version="1.0" encoding="utf-8"?> 1<?xml version="1.0" encoding="utf-8"?>
2<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 2<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <ItemGroup> 3 <ItemGroup>
4 <Filter Include="Source Files"> 4 <Filter Include="Source Files">
5 <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier> 5 <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
@@ -102,4 +102,4 @@
102 <None Include="TestData\LocUtilTests\strings.wxl" /> 102 <None Include="TestData\LocUtilTests\strings.wxl" />
103 <None Include="TestData\LocUtilTests\controls.wxl" /> 103 <None Include="TestData\LocUtilTests\controls.wxl" />
104 </ItemGroup> 104 </ItemGroup>
105</Project> \ No newline at end of file 105</Project>
diff --git a/src/libs/dutil/test/DUtilUnitTest/FileUtilTest.cpp b/src/libs/dutil/test/DUtilUnitTest/FileUtilTest.cpp
index 8ea045f5..80fe2f1a 100644
--- a/src/libs/dutil/test/DUtilUnitTest/FileUtilTest.cpp
+++ b/src/libs/dutil/test/DUtilUnitTest/FileUtilTest.cpp
@@ -11,43 +11,43 @@ namespace DutilTests
11 public ref class FileUtil 11 public ref class FileUtil
12 { 12 {
13 public: 13 public:
14 [Fact(Skip="Skipped until we have a good way to reference ANSI.txt.")] 14 // [Fact(Skip="Skipped until we have a good way to reference ANSI.txt.")]
15 void FileUtilTest() 15 // void FileUtilTest()
16 { 16 // {
17 HRESULT hr = S_OK; 17 // HRESULT hr = S_OK;
18 LPWSTR sczTempDir = NULL; 18 // LPWSTR sczTempDir = NULL;
19 LPWSTR sczFileDir = NULL; 19 // LPWSTR sczFileDir = NULL;
20 20
21 DutilInitialize(&DutilTestTraceError); 21 // DutilInitialize(&DutilTestTraceError);
22 22
23 try 23 // try
24 { 24 // {
25 hr = PathExpand(&sczTempDir, L"%TEMP%\\FileUtilTest\\", PATH_EXPAND_ENVIRONMENT); 25 // hr = PathExpand(&sczTempDir, L"%TEMP%\\FileUtilTest\\", PATH_EXPAND_ENVIRONMENT);
26 NativeAssert::Succeeded(hr, "Failed to get temp dir"); 26 // NativeAssert::Succeeded(hr, "Failed to get temp dir");
27 27
28 hr = PathExpand(&sczFileDir, L"%WIX_ROOT%\\examples\\data\\TextEncodings\\", PATH_EXPAND_ENVIRONMENT); 28 // hr = PathExpand(&sczFileDir, L"%WIX_ROOT%\\examples\\data\\TextEncodings\\", PATH_EXPAND_ENVIRONMENT);
29 NativeAssert::Succeeded(hr, "Failed to get path to encodings file dir"); 29 // NativeAssert::Succeeded(hr, "Failed to get path to encodings file dir");
30 30
31 hr = DirEnsureExists(sczTempDir, NULL); 31 // hr = DirEnsureExists(sczTempDir, NULL);
32 NativeAssert::Succeeded(hr, "Failed to ensure directory exists: {0}", sczTempDir); 32 // NativeAssert::Succeeded(hr, "Failed to ensure directory exists: {0}", sczTempDir);
33 33
34 TestFile(sczFileDir, sczTempDir, L"ANSI.txt", 32, FILE_ENCODING_UTF8); 34 // TestFile(sczFileDir, sczTempDir, L"ANSI.txt", 32, FILE_ENCODING_UTF8);
35 // Big endian not supported today! 35 // // Big endian not supported today!
36 //TestFile(sczFileDir, L"UnicodeBENoBOM.txt", 34); 36 // //TestFile(sczFileDir, L"UnicodeBENoBOM.txt", 34);
37 //TestFile(sczFileDir, L"UnicodeBEWithBOM.txt", 34); 37 // //TestFile(sczFileDir, L"UnicodeBEWithBOM.txt", 34);
38 TestFile(sczFileDir, sczTempDir, L"UnicodeLENoBOM.txt", 34, FILE_ENCODING_UTF16); 38 // TestFile(sczFileDir, sczTempDir, L"UnicodeLENoBOM.txt", 34, FILE_ENCODING_UTF16);
39 TestFile(sczFileDir, sczTempDir, L"UnicodeLEWithBOM.txt", 34, FILE_ENCODING_UTF16_WITH_BOM); 39 // TestFile(sczFileDir, sczTempDir, L"UnicodeLEWithBOM.txt", 34, FILE_ENCODING_UTF16_WITH_BOM);
40 TestFile(sczFileDir, sczTempDir, L"UTF8WithSignature.txt", 34, FILE_ENCODING_UTF8_WITH_BOM); 40 // TestFile(sczFileDir, sczTempDir, L"UTF8WithSignature.txt", 34, FILE_ENCODING_UTF8_WITH_BOM);
41 41
42 hr = DirEnsureDelete(sczTempDir, TRUE, TRUE); 42 // hr = DirEnsureDelete(sczTempDir, TRUE, TRUE);
43 } 43 // }
44 finally 44 // finally
45 { 45 // {
46 ReleaseStr(sczTempDir); 46 // ReleaseStr(sczTempDir);
47 ReleaseStr(sczFileDir); 47 // ReleaseStr(sczFileDir);
48 DutilUninitialize(); 48 // DutilUninitialize();
49 } 49 // }
50 } 50 // }
51 51
52 private: 52 private:
53 void TestFile(LPWSTR wzDir, LPCWSTR wzTempDir, LPWSTR wzFileName, size_t cbExpectedStringLength, FILE_ENCODING feExpectedEncoding) 53 void TestFile(LPWSTR wzDir, LPCWSTR wzTempDir, LPWSTR wzFileName, size_t cbExpectedStringLength, FILE_ENCODING feExpectedEncoding)
diff --git a/src/libs/dutil/test/DUtilUnitTest/LocControlsUtilTests.cpp b/src/libs/dutil/test/DUtilUnitTest/LocControlsUtilTests.cpp
index a558c0c5..fd8679cb 100644
--- a/src/libs/dutil/test/DUtilUnitTest/LocControlsUtilTests.cpp
+++ b/src/libs/dutil/test/DUtilUnitTest/LocControlsUtilTests.cpp
@@ -15,6 +15,7 @@ namespace DutilTests
15 void CanLoadControlsWxl() 15 void CanLoadControlsWxl()
16 { 16 {
17 HRESULT hr = S_OK; 17 HRESULT hr = S_OK;
18 DWORD dwRetry = 0;
18 WIX_LOCALIZATION* pLoc = NULL; 19 WIX_LOCALIZATION* pLoc = NULL;
19 LOC_CONTROL* pLocControl = NULL; 20 LOC_CONTROL* pLocControl = NULL;
20 21
@@ -26,7 +27,15 @@ namespace DutilTests
26 NativeAssert::Succeeded(hr, "Failed to initialize Xml."); 27 NativeAssert::Succeeded(hr, "Failed to initialize Xml.");
27 28
28 pin_ptr<const wchar_t> wxlFilePath = PtrToStringChars(TestData::Get("TestData", "LocUtilTests", "controls.wxl")); 29 pin_ptr<const wchar_t> wxlFilePath = PtrToStringChars(TestData::Get("TestData", "LocUtilTests", "controls.wxl"));
29 hr = LocLoadFromFile(wxlFilePath, &pLoc); 30 do
31 {
32 if (FAILED(hr))
33 {
34 ::Sleep(500);
35 }
36
37 hr = LocLoadFromFile(wxlFilePath, &pLoc);
38 } while (FAILED(hr) && ++dwRetry < 5);
30 NativeAssert::Succeeded(hr, "Failed to parse controls.wxl: {0}", wxlFilePath); 39 NativeAssert::Succeeded(hr, "Failed to parse controls.wxl: {0}", wxlFilePath);
31 40
32 Assert::Equal(3ul, pLoc->cLocControls); 41 Assert::Equal(3ul, pLoc->cLocControls);
diff --git a/src/libs/dutil/test/DUtilUnitTest/LocStringsUtilTests.cpp b/src/libs/dutil/test/DUtilUnitTest/LocStringsUtilTests.cpp
index 1bfc4bb4..04130098 100644
--- a/src/libs/dutil/test/DUtilUnitTest/LocStringsUtilTests.cpp
+++ b/src/libs/dutil/test/DUtilUnitTest/LocStringsUtilTests.cpp
@@ -15,6 +15,7 @@ namespace DutilTests
15 void CanLoadStringsWxl() 15 void CanLoadStringsWxl()
16 { 16 {
17 HRESULT hr = S_OK; 17 HRESULT hr = S_OK;
18 DWORD dwRetry = 0;
18 WIX_LOCALIZATION* pLoc = NULL; 19 WIX_LOCALIZATION* pLoc = NULL;
19 LOC_STRING* pLocString = NULL; 20 LOC_STRING* pLocString = NULL;
20 LPWSTR sczValue = NULL; 21 LPWSTR sczValue = NULL;
@@ -27,7 +28,15 @@ namespace DutilTests
27 NativeAssert::Succeeded(hr, "Failed to initialize Xml."); 28 NativeAssert::Succeeded(hr, "Failed to initialize Xml.");
28 29
29 pin_ptr<const wchar_t> wxlFilePath = PtrToStringChars(TestData::Get("TestData", "LocUtilTests", "strings.wxl")); 30 pin_ptr<const wchar_t> wxlFilePath = PtrToStringChars(TestData::Get("TestData", "LocUtilTests", "strings.wxl"));
30 hr = LocLoadFromFile(wxlFilePath, &pLoc); 31 do
32 {
33 if (FAILED(hr))
34 {
35 ::Sleep(500);
36 }
37
38 hr = LocLoadFromFile(wxlFilePath, &pLoc);
39 } while (FAILED(hr) && ++dwRetry < 5);
31 NativeAssert::Succeeded(hr, "Failed to parse strings.wxl: {0}", wxlFilePath); 40 NativeAssert::Succeeded(hr, "Failed to parse strings.wxl: {0}", wxlFilePath);
32 41
33 Assert::Equal(4ul, pLoc->cLocStrings); 42 Assert::Equal(4ul, pLoc->cLocStrings);
diff --git a/src/libs/dutil/test/DUtilUnitTest/MonUtilTest.cpp b/src/libs/dutil/test/DUtilUnitTest/MonUtilTest.cpp
index d9c75bf6..f10673fa 100644
--- a/src/libs/dutil/test/DUtilUnitTest/MonUtilTest.cpp
+++ b/src/libs/dutil/test/DUtilUnitTest/MonUtilTest.cpp
@@ -38,452 +38,452 @@ namespace DutilTests
38 DWORD cDirectories; 38 DWORD cDirectories;
39 }; 39 };
40 40
41 public delegate void MonGeneralDelegate(HRESULT, LPVOID); 41 // public delegate void MonGeneralDelegate(HRESULT, LPVOID);
42 42
43 public delegate void MonDriveStatusDelegate(WCHAR, BOOL, LPVOID); 43 // public delegate void MonDriveStatusDelegate(WCHAR, BOOL, LPVOID);
44 44
45 public delegate void MonDirectoryDelegate(HRESULT, LPCWSTR, BOOL, LPVOID, LPVOID); 45 // public delegate void MonDirectoryDelegate(HRESULT, LPCWSTR, BOOL, LPVOID, LPVOID);
46 46
47 public delegate void MonRegKeyDelegate(HRESULT, HKEY, LPCWSTR, REG_KEY_BITNESS, BOOL, LPVOID, LPVOID); 47 // public delegate void MonRegKeyDelegate(HRESULT, HKEY, LPCWSTR, REG_KEY_BITNESS, BOOL, LPVOID, LPVOID);
48 48
49 static void MonGeneral( 49 // static void MonGeneral(
50 __in HRESULT /*hrResult*/, 50 // __in HRESULT /*hrResult*/,
51 __in_opt LPVOID /*pvContext*/ 51 // __in_opt LPVOID /*pvContext*/
52 ) 52 // )
53 { 53 // {
54 Assert::True(false); 54 // Assert::True(false);
55 } 55 // }
56 56
57 static void MonDriveStatus( 57 // static void MonDriveStatus(
58 __in WCHAR /*chDrive*/, 58 // __in WCHAR /*chDrive*/,
59 __in BOOL /*fArriving*/, 59 // __in BOOL /*fArriving*/,
60 __in_opt LPVOID /*pvContext*/ 60 // __in_opt LPVOID /*pvContext*/
61 ) 61 // )
62 { 62 // {
63 } 63 // }
64 64
65 static void MonDirectory( 65 // static void MonDirectory(
66 __in HRESULT hrResult, 66 // __in HRESULT hrResult,
67 __in_z LPCWSTR wzPath, 67 // __in_z LPCWSTR wzPath,
68 __in_z BOOL fRecursive, 68 // __in_z BOOL fRecursive,
69 __in_opt LPVOID pvContext, 69 // __in_opt LPVOID pvContext,
70 __in_opt LPVOID pvDirectoryContext 70 // __in_opt LPVOID pvDirectoryContext
71 ) 71 // )
72 { 72 // {
73 Assert::Equal(S_OK, hrResult); 73 // Assert::Equal(S_OK, hrResult);
74 Assert::Equal<DWORD_PTR>(0, reinterpret_cast<DWORD_PTR>(pvDirectoryContext)); 74 // Assert::Equal<DWORD_PTR>(0, reinterpret_cast<DWORD_PTR>(pvDirectoryContext));
75 75
76 HRESULT hr = S_OK; 76 // HRESULT hr = S_OK;
77 Results *pResults = reinterpret_cast<Results *>(pvContext); 77 // Results *pResults = reinterpret_cast<Results *>(pvContext);
78 78
79 hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&pResults->rgDirectories), pResults->cDirectories + 1, sizeof(Directory), 5); 79 // hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&pResults->rgDirectories), pResults->cDirectories + 1, sizeof(Directory), 5);
80 NativeAssert::ValidReturnCode(hr, S_OK); 80 // NativeAssert::ValidReturnCode(hr, S_OK);
81 ++pResults->cDirectories; 81 // ++pResults->cDirectories;
82 82
83 pResults->rgDirectories[pResults->cDirectories - 1].hr = hrResult; 83 // pResults->rgDirectories[pResults->cDirectories - 1].hr = hrResult;
84 pResults->rgDirectories[pResults->cDirectories - 1].wzPath = wzPath; 84 // pResults->rgDirectories[pResults->cDirectories - 1].wzPath = wzPath;
85 pResults->rgDirectories[pResults->cDirectories - 1].fRecursive = fRecursive; 85 // pResults->rgDirectories[pResults->cDirectories - 1].fRecursive = fRecursive;
86 } 86 // }
87 87
88 static void MonRegKey( 88 // static void MonRegKey(
89 __in HRESULT hrResult, 89 // __in HRESULT hrResult,
90 __in HKEY hkRoot, 90 // __in HKEY hkRoot,
91 __in_z LPCWSTR wzSubKey, 91 // __in_z LPCWSTR wzSubKey,
92 __in REG_KEY_BITNESS kbKeyBitness, 92 // __in REG_KEY_BITNESS kbKeyBitness,
93 __in_z BOOL fRecursive, 93 // __in_z BOOL fRecursive,
94 __in_opt LPVOID pvContext, 94 // __in_opt LPVOID pvContext,
95 __in_opt LPVOID pvRegKeyContext 95 // __in_opt LPVOID pvRegKeyContext
96 ) 96 // )
97 { 97 // {
98 Assert::Equal<HRESULT>(S_OK, hrResult); 98 // Assert::Equal<HRESULT>(S_OK, hrResult);
99 Assert::Equal<DWORD_PTR>(0, reinterpret_cast<DWORD_PTR>(pvRegKeyContext)); 99 // Assert::Equal<DWORD_PTR>(0, reinterpret_cast<DWORD_PTR>(pvRegKeyContext));
100 100
101 HRESULT hr = S_OK; 101 // HRESULT hr = S_OK;
102 Results *pResults = reinterpret_cast<Results *>(pvContext); 102 // Results *pResults = reinterpret_cast<Results *>(pvContext);
103 103
104 hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&pResults->rgRegKeys), pResults->cRegKeys + 1, sizeof(RegKey), 5); 104 // hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&pResults->rgRegKeys), pResults->cRegKeys + 1, sizeof(RegKey), 5);
105 NativeAssert::ValidReturnCode(hr, S_OK); 105 // NativeAssert::ValidReturnCode(hr, S_OK);
106 ++pResults->cRegKeys; 106 // ++pResults->cRegKeys;
107 107
108 pResults->rgRegKeys[pResults->cRegKeys - 1].hr = hrResult; 108 // pResults->rgRegKeys[pResults->cRegKeys - 1].hr = hrResult;
109 pResults->rgRegKeys[pResults->cRegKeys - 1].hkRoot = hkRoot; 109 // pResults->rgRegKeys[pResults->cRegKeys - 1].hkRoot = hkRoot;
110 pResults->rgRegKeys[pResults->cRegKeys - 1].wzSubKey = wzSubKey; 110 // pResults->rgRegKeys[pResults->cRegKeys - 1].wzSubKey = wzSubKey;
111 pResults->rgRegKeys[pResults->cRegKeys - 1].kbKeyBitness = kbKeyBitness; 111 // pResults->rgRegKeys[pResults->cRegKeys - 1].kbKeyBitness = kbKeyBitness;
112 pResults->rgRegKeys[pResults->cRegKeys - 1].fRecursive = fRecursive; 112 // pResults->rgRegKeys[pResults->cRegKeys - 1].fRecursive = fRecursive;
113 } 113 // }
114 114
115 public ref class MonUtil 115 // public ref class MonUtil
116 { 116 // {
117 public: 117 // public:
118 void ClearResults(Results *pResults) 118 // void ClearResults(Results *pResults)
119 { 119 // {
120 ReleaseNullMem(pResults->rgDirectories); 120 // ReleaseNullMem(pResults->rgDirectories);
121 pResults->cDirectories = 0; 121 // pResults->cDirectories = 0;
122 ReleaseNullMem(pResults->rgRegKeys); 122 // ReleaseNullMem(pResults->rgRegKeys);
123 pResults->cRegKeys = 0; 123 // pResults->cRegKeys = 0;
124 } 124 // }
125 125
126 void RemoveDirectory(LPCWSTR wzPath) 126 // void RemoveDirectory(LPCWSTR wzPath)
127 { 127 // {
128 DWORD dwRetryCount = 0; 128 // DWORD dwRetryCount = 0;
129 const DWORD c_dwMaxRetryCount = 100; 129 // const DWORD c_dwMaxRetryCount = 100;
130 const DWORD c_dwRetryInterval = 50; 130 // const DWORD c_dwRetryInterval = 50;
131 131
132 HRESULT hr = DirEnsureDelete(wzPath, TRUE, TRUE); 132 // HRESULT hr = DirEnsureDelete(wzPath, TRUE, TRUE);
133 133
134 // Monitoring a directory opens a handle to that directory, which means delete requests for that directory will succeed 134 // // Monitoring a directory opens a handle to that directory, which means delete requests for that directory will succeed
135 // (and deletion will be "pending" until our monitor handle is closed) 135 // // (and deletion will be "pending" until our monitor handle is closed)
136 // but deletion of the directory containing that directory cannot complete until the handle is closed. This means DirEnsureDelete() 136 // // but deletion of the directory containing that directory cannot complete until the handle is closed. This means DirEnsureDelete()
137 // can sometimes encounter HRESULT_FROM_WIN32(ERROR_DIR_NOT_EMPTY) failures, which just means it needs to retry a bit later 137 // // can sometimes encounter HRESULT_FROM_WIN32(ERROR_DIR_NOT_EMPTY) failures, which just means it needs to retry a bit later
138 // (after the waiter thread wakes up, it will release the handle) 138 // // (after the waiter thread wakes up, it will release the handle)
139 while (HRESULT_FROM_WIN32(ERROR_DIR_NOT_EMPTY) == hr && c_dwMaxRetryCount > dwRetryCount) 139 // while (HRESULT_FROM_WIN32(ERROR_DIR_NOT_EMPTY) == hr && c_dwMaxRetryCount > dwRetryCount)
140 { 140 // {
141 ::Sleep(c_dwRetryInterval); 141 // ::Sleep(c_dwRetryInterval);
142 ++dwRetryCount; 142 // ++dwRetryCount;
143 hr = DirEnsureDelete(wzPath, TRUE, TRUE); 143 // hr = DirEnsureDelete(wzPath, TRUE, TRUE);
144 } 144 // }
145 145
146 NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE, E_PATHNOTFOUND); 146 // NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE, E_PATHNOTFOUND);
147 } 147 // }
148 148
149 void TestDirectory(MON_HANDLE handle, Results *pResults) 149 // void TestDirectory(MON_HANDLE handle, Results *pResults)
150 { 150 // {
151 HRESULT hr = S_OK; 151 // HRESULT hr = S_OK;
152 LPWSTR sczShallowPath = NULL; 152 // LPWSTR sczShallowPath = NULL;
153 LPWSTR sczParentPath = NULL; 153 // LPWSTR sczParentPath = NULL;
154 LPWSTR sczDeepPath = NULL; 154 // LPWSTR sczDeepPath = NULL;
155 LPWSTR sczChildPath = NULL; 155 // LPWSTR sczChildPath = NULL;
156 LPWSTR sczChildFilePath = NULL; 156 // LPWSTR sczChildFilePath = NULL;
157 157
158 try 158 // try
159 { 159 // {
160 hr = PathExpand(&sczShallowPath, L"%TEMP%\\MonUtilTest\\", PATH_EXPAND_ENVIRONMENT); 160 // hr = PathExpand(&sczShallowPath, L"%TEMP%\\MonUtilTest\\", PATH_EXPAND_ENVIRONMENT);
161 NativeAssert::ValidReturnCode(hr, S_OK); 161 // NativeAssert::ValidReturnCode(hr, S_OK);
162 162
163 hr = PathExpand(&sczParentPath, L"%TEMP%\\MonUtilTest\\sub\\folder\\that\\might\\not\\", PATH_EXPAND_ENVIRONMENT); 163 // hr = PathExpand(&sczParentPath, L"%TEMP%\\MonUtilTest\\sub\\folder\\that\\might\\not\\", PATH_EXPAND_ENVIRONMENT);
164 NativeAssert::ValidReturnCode(hr, S_OK); 164 // NativeAssert::ValidReturnCode(hr, S_OK);
165 165
166 hr = PathExpand(&sczDeepPath, L"%TEMP%\\MonUtilTest\\sub\\folder\\that\\might\\not\\exist\\", PATH_EXPAND_ENVIRONMENT); 166 // hr = PathExpand(&sczDeepPath, L"%TEMP%\\MonUtilTest\\sub\\folder\\that\\might\\not\\exist\\", PATH_EXPAND_ENVIRONMENT);
167 NativeAssert::ValidReturnCode(hr, S_OK); 167 // NativeAssert::ValidReturnCode(hr, S_OK);
168 168
169 hr = PathExpand(&sczChildPath, L"%TEMP%\\MonUtilTest\\sub\\folder\\that\\might\\not\\exist\\some\\sub\\folder\\", PATH_EXPAND_ENVIRONMENT); 169 // hr = PathExpand(&sczChildPath, L"%TEMP%\\MonUtilTest\\sub\\folder\\that\\might\\not\\exist\\some\\sub\\folder\\", PATH_EXPAND_ENVIRONMENT);
170 NativeAssert::ValidReturnCode(hr, S_OK); 170 // NativeAssert::ValidReturnCode(hr, S_OK);
171 171
172 hr = PathExpand(&sczChildFilePath, L"%TEMP%\\MonUtilTest\\sub\\folder\\that\\might\\not\\exist\\some\\sub\\folder\\file.txt", PATH_EXPAND_ENVIRONMENT); 172 // hr = PathExpand(&sczChildFilePath, L"%TEMP%\\MonUtilTest\\sub\\folder\\that\\might\\not\\exist\\some\\sub\\folder\\file.txt", PATH_EXPAND_ENVIRONMENT);
173 NativeAssert::ValidReturnCode(hr, S_OK); 173 // NativeAssert::ValidReturnCode(hr, S_OK);
174 174
175 RemoveDirectory(sczShallowPath); 175 // RemoveDirectory(sczShallowPath);
176 176
177 hr = MonAddDirectory(handle, sczDeepPath, TRUE, SILENCEPERIOD, NULL); 177 // hr = MonAddDirectory(handle, sczDeepPath, TRUE, SILENCEPERIOD, NULL);
178 NativeAssert::ValidReturnCode(hr, S_OK); 178 // NativeAssert::ValidReturnCode(hr, S_OK);
179 179
180 hr = DirEnsureExists(sczParentPath, NULL); 180 // hr = DirEnsureExists(sczParentPath, NULL);
181 NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE); 181 // NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE);
182 // Make sure creating the parent directory does nothing, even after silence period 182 // // Make sure creating the parent directory does nothing, even after silence period
183 ::Sleep(FULLWAIT); 183 // ::Sleep(FULLWAIT);
184 Assert::Equal<DWORD>(0, pResults->cDirectories); 184 // Assert::Equal<DWORD>(0, pResults->cDirectories);
185 185
186 // Now create the target path, no notification until after the silence period 186 // // Now create the target path, no notification until after the silence period
187 hr = DirEnsureExists(sczDeepPath, NULL); 187 // hr = DirEnsureExists(sczDeepPath, NULL);
188 NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE); 188 // NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE);
189 ::Sleep(PREWAIT); 189 // ::Sleep(PREWAIT);
190 Assert::Equal<DWORD>(0, pResults->cDirectories); 190 // Assert::Equal<DWORD>(0, pResults->cDirectories);
191 191
192 // Now after the full silence period, it should have triggered 192 // // Now after the full silence period, it should have triggered
193 ::Sleep(POSTWAIT); 193 // ::Sleep(POSTWAIT);
194 Assert::Equal<DWORD>(1, pResults->cDirectories); 194 // Assert::Equal<DWORD>(1, pResults->cDirectories);
195 NativeAssert::ValidReturnCode(pResults->rgDirectories[0].hr, S_OK); 195 // NativeAssert::ValidReturnCode(pResults->rgDirectories[0].hr, S_OK);
196 196
197 // Now delete the directory, along with a ton of parents. This verifies MonUtil will keep watching the closest parent that still exists. 197 // // Now delete the directory, along with a ton of parents. This verifies MonUtil will keep watching the closest parent that still exists.
198 RemoveDirectory(sczShallowPath); 198 // RemoveDirectory(sczShallowPath);
199 199
200 ::Sleep(FULLWAIT); 200 // ::Sleep(FULLWAIT);
201 Assert::Equal<DWORD>(2, pResults->cDirectories); 201 // Assert::Equal<DWORD>(2, pResults->cDirectories);
202 NativeAssert::ValidReturnCode(pResults->rgDirectories[1].hr, S_OK); 202 // NativeAssert::ValidReturnCode(pResults->rgDirectories[1].hr, S_OK);
203 203
204 // Create the parent directory again, still should be nothing even after full silence period 204 // // Create the parent directory again, still should be nothing even after full silence period
205 hr = DirEnsureExists(sczParentPath, NULL); 205 // hr = DirEnsureExists(sczParentPath, NULL);
206 NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE); 206 // NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE);
207 ::Sleep(FULLWAIT); 207 // ::Sleep(FULLWAIT);
208 Assert::Equal<DWORD>(2, pResults->cDirectories); 208 // Assert::Equal<DWORD>(2, pResults->cDirectories);
209 209
210 hr = DirEnsureExists(sczChildPath, NULL); 210 // hr = DirEnsureExists(sczChildPath, NULL);
211 NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE); 211 // NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE);
212 ::Sleep(PREWAIT); 212 // ::Sleep(PREWAIT);
213 Assert::Equal<DWORD>(2, pResults->cDirectories); 213 // Assert::Equal<DWORD>(2, pResults->cDirectories);
214 214
215 ::Sleep(POSTWAIT); 215 // ::Sleep(POSTWAIT);
216 Assert::Equal<DWORD>(3, pResults->cDirectories); 216 // Assert::Equal<DWORD>(3, pResults->cDirectories);
217 NativeAssert::ValidReturnCode(pResults->rgDirectories[2].hr, S_OK); 217 // NativeAssert::ValidReturnCode(pResults->rgDirectories[2].hr, S_OK);
218 218
219 // Write a file to a deep child subfolder, and make sure it's detected 219 // // Write a file to a deep child subfolder, and make sure it's detected
220 hr = FileFromString(sczChildFilePath, 0, L"contents", FILE_ENCODING_UTF16_WITH_BOM); 220 // hr = FileFromString(sczChildFilePath, 0, L"contents", FILE_ENCODING_UTF16_WITH_BOM);
221 NativeAssert::ValidReturnCode(hr, S_OK); 221 // NativeAssert::ValidReturnCode(hr, S_OK);
222 ::Sleep(PREWAIT); 222 // ::Sleep(PREWAIT);
223 Assert::Equal<DWORD>(3, pResults->cDirectories); 223 // Assert::Equal<DWORD>(3, pResults->cDirectories);
224 224
225 ::Sleep(POSTWAIT); 225 // ::Sleep(POSTWAIT);
226 Assert::Equal<DWORD>(4, pResults->cDirectories); 226 // Assert::Equal<DWORD>(4, pResults->cDirectories);
227 NativeAssert::ValidReturnCode(pResults->rgDirectories[2].hr, S_OK); 227 // NativeAssert::ValidReturnCode(pResults->rgDirectories[2].hr, S_OK);
228 228
229 RemoveDirectory(sczParentPath); 229 // RemoveDirectory(sczParentPath);
230 230
231 ::Sleep(FULLWAIT); 231 // ::Sleep(FULLWAIT);
232 Assert::Equal<DWORD>(5, pResults->cDirectories); 232 // Assert::Equal<DWORD>(5, pResults->cDirectories);
233 NativeAssert::ValidReturnCode(pResults->rgDirectories[3].hr, S_OK); 233 // NativeAssert::ValidReturnCode(pResults->rgDirectories[3].hr, S_OK);
234 234
235 // Now remove the directory from the list of things to monitor, and confirm changes are no longer tracked 235 // // Now remove the directory from the list of things to monitor, and confirm changes are no longer tracked
236 hr = MonRemoveDirectory(handle, sczDeepPath, TRUE); 236 // hr = MonRemoveDirectory(handle, sczDeepPath, TRUE);
237 NativeAssert::ValidReturnCode(hr, S_OK); 237 // NativeAssert::ValidReturnCode(hr, S_OK);
238 ::Sleep(PREWAIT); 238 // ::Sleep(PREWAIT);
239 239
240 hr = DirEnsureExists(sczDeepPath, NULL); 240 // hr = DirEnsureExists(sczDeepPath, NULL);
241 NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE); 241 // NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE);
242 ::Sleep(FULLWAIT); 242 // ::Sleep(FULLWAIT);
243 Assert::Equal<DWORD>(5, pResults->cDirectories); 243 // Assert::Equal<DWORD>(5, pResults->cDirectories);
244 NativeAssert::ValidReturnCode(pResults->rgDirectories[3].hr, S_OK); 244 // NativeAssert::ValidReturnCode(pResults->rgDirectories[3].hr, S_OK);
245 245
246 // Finally, add it back so we can test multiple things to monitor at once 246 // // Finally, add it back so we can test multiple things to monitor at once
247 hr = MonAddDirectory(handle, sczDeepPath, TRUE, SILENCEPERIOD, NULL); 247 // hr = MonAddDirectory(handle, sczDeepPath, TRUE, SILENCEPERIOD, NULL);
248 NativeAssert::ValidReturnCode(hr, S_OK); 248 // NativeAssert::ValidReturnCode(hr, S_OK);
249 } 249 // }
250 finally 250 // finally
251 { 251 // {
252 ReleaseStr(sczShallowPath); 252 // ReleaseStr(sczShallowPath);
253 ReleaseStr(sczDeepPath); 253 // ReleaseStr(sczDeepPath);
254 ReleaseStr(sczParentPath); 254 // ReleaseStr(sczParentPath);
255 } 255 // }
256 } 256 // }
257 257
258 void TestRegKey(MON_HANDLE handle, Results *pResults) 258 // void TestRegKey(MON_HANDLE handle, Results *pResults)
259 { 259 // {
260 HRESULT hr = S_OK; 260 // HRESULT hr = S_OK;
261 LPCWSTR wzShallowRegKey = L"Software\\MonUtilTest\\"; 261 // LPCWSTR wzShallowRegKey = L"Software\\MonUtilTest\\";
262 LPCWSTR wzParentRegKey = L"Software\\MonUtilTest\\sub\\folder\\that\\might\\not\\"; 262 // LPCWSTR wzParentRegKey = L"Software\\MonUtilTest\\sub\\folder\\that\\might\\not\\";
263 LPCWSTR wzDeepRegKey = L"Software\\MonUtilTest\\sub\\folder\\that\\might\\not\\exist\\"; 263 // LPCWSTR wzDeepRegKey = L"Software\\MonUtilTest\\sub\\folder\\that\\might\\not\\exist\\";
264 LPCWSTR wzChildRegKey = L"Software\\MonUtilTest\\sub\\folder\\that\\might\\not\\exist\\some\\sub\\folder\\"; 264 // LPCWSTR wzChildRegKey = L"Software\\MonUtilTest\\sub\\folder\\that\\might\\not\\exist\\some\\sub\\folder\\";
265 HKEY hk = NULL; 265 // HKEY hk = NULL;
266 266
267 try 267 // try
268 { 268 // {
269 hr = RegDelete(HKEY_CURRENT_USER, wzShallowRegKey, REG_KEY_32BIT, TRUE); 269 // hr = RegDelete(HKEY_CURRENT_USER, wzShallowRegKey, REG_KEY_32BIT, TRUE);
270 NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE, E_PATHNOTFOUND); 270 // NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE, E_PATHNOTFOUND);
271 271
272 hr = MonAddRegKey(handle, HKEY_CURRENT_USER, wzDeepRegKey, REG_KEY_DEFAULT, TRUE, SILENCEPERIOD, NULL); 272 // hr = MonAddRegKey(handle, HKEY_CURRENT_USER, wzDeepRegKey, REG_KEY_DEFAULT, TRUE, SILENCEPERIOD, NULL);
273 NativeAssert::ValidReturnCode(hr, S_OK); 273 // NativeAssert::ValidReturnCode(hr, S_OK);
274 274
275 hr = RegCreate(HKEY_CURRENT_USER, wzParentRegKey, KEY_SET_VALUE | KEY_QUERY_VALUE | KEY_WOW64_32KEY, &hk); 275 // hr = RegCreate(HKEY_CURRENT_USER, wzParentRegKey, KEY_SET_VALUE | KEY_QUERY_VALUE | KEY_WOW64_32KEY, &hk);
276 ReleaseRegKey(hk); 276 // ReleaseRegKey(hk);
277 // Make sure creating the parent key does nothing, even after silence period 277 // // Make sure creating the parent key does nothing, even after silence period
278 ::Sleep(FULLWAIT); 278 // ::Sleep(FULLWAIT);
279 NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE); 279 // NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE);
280 Assert::Equal<DWORD>(0, pResults->cRegKeys); 280 // Assert::Equal<DWORD>(0, pResults->cRegKeys);
281 281
282 // Now create the target path, no notification until after the silence period 282 // // Now create the target path, no notification until after the silence period
283 hr = RegCreate(HKEY_CURRENT_USER, wzDeepRegKey, KEY_SET_VALUE | KEY_QUERY_VALUE | KEY_WOW64_32KEY, &hk); 283 // hr = RegCreate(HKEY_CURRENT_USER, wzDeepRegKey, KEY_SET_VALUE | KEY_QUERY_VALUE | KEY_WOW64_32KEY, &hk);
284 NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE); 284 // NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE);
285 ReleaseRegKey(hk); 285 // ReleaseRegKey(hk);
286 ::Sleep(PREWAIT); 286 // ::Sleep(PREWAIT);
287 Assert::Equal<DWORD>(0, pResults->cRegKeys); 287 // Assert::Equal<DWORD>(0, pResults->cRegKeys);
288 288
289 // Now after the full silence period, it should have triggered 289 // // Now after the full silence period, it should have triggered
290 ::Sleep(POSTWAIT); 290 // ::Sleep(POSTWAIT);
291 Assert::Equal<DWORD>(1, pResults->cRegKeys); 291 // Assert::Equal<DWORD>(1, pResults->cRegKeys);
292 NativeAssert::ValidReturnCode(pResults->rgRegKeys[0].hr, S_OK); 292 // NativeAssert::ValidReturnCode(pResults->rgRegKeys[0].hr, S_OK);
293 293
294 // Now delete the directory, along with a ton of parents. This verifies MonUtil will keep watching the closest parent that still exists. 294 // // Now delete the directory, along with a ton of parents. This verifies MonUtil will keep watching the closest parent that still exists.
295 hr = RegDelete(HKEY_CURRENT_USER, wzShallowRegKey, REG_KEY_32BIT, TRUE); 295 // hr = RegDelete(HKEY_CURRENT_USER, wzShallowRegKey, REG_KEY_32BIT, TRUE);
296 NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE, E_PATHNOTFOUND); 296 // NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE, E_PATHNOTFOUND);
297 ::Sleep(PREWAIT); 297 // ::Sleep(PREWAIT);
298 Assert::Equal<DWORD>(1, pResults->cRegKeys); 298 // Assert::Equal<DWORD>(1, pResults->cRegKeys);
299 299
300 ::Sleep(FULLWAIT); 300 // ::Sleep(FULLWAIT);
301 Assert::Equal<DWORD>(2, pResults->cRegKeys); 301 // Assert::Equal<DWORD>(2, pResults->cRegKeys);
302 NativeAssert::ValidReturnCode(pResults->rgRegKeys[1].hr, S_OK); 302 // NativeAssert::ValidReturnCode(pResults->rgRegKeys[1].hr, S_OK);
303 303
304 // Create the parent directory again, still should be nothing even after full silence period 304 // // Create the parent directory again, still should be nothing even after full silence period
305 hr = RegCreate(HKEY_CURRENT_USER, wzParentRegKey, KEY_SET_VALUE | KEY_QUERY_VALUE | KEY_WOW64_32KEY, &hk); 305 // hr = RegCreate(HKEY_CURRENT_USER, wzParentRegKey, KEY_SET_VALUE | KEY_QUERY_VALUE | KEY_WOW64_32KEY, &hk);
306 NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE); 306 // NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE);
307 ReleaseRegKey(hk); 307 // ReleaseRegKey(hk);
308 ::Sleep(FULLWAIT); 308 // ::Sleep(FULLWAIT);
309 Assert::Equal<DWORD>(2, pResults->cRegKeys); 309 // Assert::Equal<DWORD>(2, pResults->cRegKeys);
310 310
311 hr = RegCreate(HKEY_CURRENT_USER, wzChildRegKey, KEY_SET_VALUE | KEY_QUERY_VALUE | KEY_WOW64_32KEY, &hk); 311 // hr = RegCreate(HKEY_CURRENT_USER, wzChildRegKey, KEY_SET_VALUE | KEY_QUERY_VALUE | KEY_WOW64_32KEY, &hk);
312 NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE); 312 // NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE);
313 ::Sleep(PREWAIT); 313 // ::Sleep(PREWAIT);
314 Assert::Equal<DWORD>(2, pResults->cRegKeys); 314 // Assert::Equal<DWORD>(2, pResults->cRegKeys);
315 315
316 ::Sleep(FULLWAIT); 316 // ::Sleep(FULLWAIT);
317 Assert::Equal<DWORD>(3, pResults->cRegKeys); 317 // Assert::Equal<DWORD>(3, pResults->cRegKeys);
318 NativeAssert::ValidReturnCode(pResults->rgRegKeys[2].hr, S_OK); 318 // NativeAssert::ValidReturnCode(pResults->rgRegKeys[2].hr, S_OK);
319 319
320 // Write a registry value to some deep child subkey, and make sure it's detected 320 // // Write a registry value to some deep child subkey, and make sure it's detected
321 hr = RegWriteString(hk, L"valuename", L"testvalue"); 321 // hr = RegWriteString(hk, L"valuename", L"testvalue");
322 NativeAssert::ValidReturnCode(hr, S_OK); 322 // NativeAssert::ValidReturnCode(hr, S_OK);
323 ReleaseRegKey(hk); 323 // ReleaseRegKey(hk);
324 ::Sleep(PREWAIT); 324 // ::Sleep(PREWAIT);
325 Assert::Equal<DWORD>(3, pResults->cRegKeys); 325 // Assert::Equal<DWORD>(3, pResults->cRegKeys);
326 326
327 ::Sleep(FULLWAIT); 327 // ::Sleep(FULLWAIT);
328 Assert::Equal<DWORD>(4, pResults->cRegKeys); 328 // Assert::Equal<DWORD>(4, pResults->cRegKeys);
329 NativeAssert::ValidReturnCode(pResults->rgRegKeys[2].hr, S_OK); 329 // NativeAssert::ValidReturnCode(pResults->rgRegKeys[2].hr, S_OK);
330 330
331 hr = RegDelete(HKEY_CURRENT_USER, wzDeepRegKey, REG_KEY_32BIT, TRUE); 331 // hr = RegDelete(HKEY_CURRENT_USER, wzDeepRegKey, REG_KEY_32BIT, TRUE);
332 NativeAssert::ValidReturnCode(hr, S_OK); 332 // NativeAssert::ValidReturnCode(hr, S_OK);
333 333
334 ::Sleep(FULLWAIT); 334 // ::Sleep(FULLWAIT);
335 Assert::Equal<DWORD>(5, pResults->cRegKeys); 335 // Assert::Equal<DWORD>(5, pResults->cRegKeys);
336 336
337 // Now remove the regkey from the list of things to monitor, and confirm changes are no longer tracked 337 // // Now remove the regkey from the list of things to monitor, and confirm changes are no longer tracked
338 hr = MonRemoveRegKey(handle, HKEY_CURRENT_USER, wzDeepRegKey, REG_KEY_DEFAULT, TRUE); 338 // hr = MonRemoveRegKey(handle, HKEY_CURRENT_USER, wzDeepRegKey, REG_KEY_DEFAULT, TRUE);
339 NativeAssert::ValidReturnCode(hr, S_OK); 339 // NativeAssert::ValidReturnCode(hr, S_OK);
340 340
341 hr = RegCreate(HKEY_CURRENT_USER, wzDeepRegKey, KEY_SET_VALUE | KEY_QUERY_VALUE | KEY_WOW64_32KEY, &hk); 341 // hr = RegCreate(HKEY_CURRENT_USER, wzDeepRegKey, KEY_SET_VALUE | KEY_QUERY_VALUE | KEY_WOW64_32KEY, &hk);
342 NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE); 342 // NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE);
343 ReleaseRegKey(hk); 343 // ReleaseRegKey(hk);
344 ::Sleep(FULLWAIT); 344 // ::Sleep(FULLWAIT);
345 Assert::Equal<DWORD>(5, pResults->cRegKeys); 345 // Assert::Equal<DWORD>(5, pResults->cRegKeys);
346 } 346 // }
347 finally 347 // finally
348 { 348 // {
349 ReleaseRegKey(hk); 349 // ReleaseRegKey(hk);
350 } 350 // }
351 } 351 // }
352 352
353 void TestMoreThan64(MON_HANDLE handle, Results *pResults) 353 // void TestMoreThan64(MON_HANDLE handle, Results *pResults)
354 { 354 // {
355 HRESULT hr = S_OK; 355 // HRESULT hr = S_OK;
356 LPWSTR sczBaseDir = NULL; 356 // LPWSTR sczBaseDir = NULL;
357 LPWSTR sczDir = NULL; 357 // LPWSTR sczDir = NULL;
358 LPWSTR sczFile = NULL; 358 // LPWSTR sczFile = NULL;
359 359
360 try 360 // try
361 { 361 // {
362 hr = PathExpand(&sczBaseDir, L"%TEMP%\\ScalabilityTest\\", PATH_EXPAND_ENVIRONMENT); 362 // hr = PathExpand(&sczBaseDir, L"%TEMP%\\ScalabilityTest\\", PATH_EXPAND_ENVIRONMENT);
363 NativeAssert::ValidReturnCode(hr, S_OK); 363 // NativeAssert::ValidReturnCode(hr, S_OK);
364 364
365 for (DWORD i = 0; i < 200; ++i) 365 // for (DWORD i = 0; i < 200; ++i)
366 { 366 // {
367 hr = StrAllocFormatted(&sczDir, L"%ls%u\\", sczBaseDir, i); 367 // hr = StrAllocFormatted(&sczDir, L"%ls%u\\", sczBaseDir, i);
368 NativeAssert::ValidReturnCode(hr, S_OK); 368 // NativeAssert::ValidReturnCode(hr, S_OK);
369 369
370 hr = DirEnsureExists(sczDir, NULL); 370 // hr = DirEnsureExists(sczDir, NULL);
371 NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE); 371 // NativeAssert::ValidReturnCode(hr, S_OK, S_FALSE);
372 372
373 hr = MonAddDirectory(handle, sczDir, FALSE, SILENCEPERIOD, NULL); 373 // hr = MonAddDirectory(handle, sczDir, FALSE, SILENCEPERIOD, NULL);
374 NativeAssert::ValidReturnCode(hr, S_OK); 374 // NativeAssert::ValidReturnCode(hr, S_OK);
375 } 375 // }
376 376
377 hr = PathConcat(sczDir, L"file.txt", &sczFile); 377 // hr = PathConcat(sczDir, L"file.txt", &sczFile);
378 NativeAssert::ValidReturnCode(hr, S_OK); 378 // NativeAssert::ValidReturnCode(hr, S_OK);
379 379
380 hr = FileFromString(sczFile, 0, L"contents", FILE_ENCODING_UTF16_WITH_BOM); 380 // hr = FileFromString(sczFile, 0, L"contents", FILE_ENCODING_UTF16_WITH_BOM);
381 NativeAssert::ValidReturnCode(hr, S_OK); 381 // NativeAssert::ValidReturnCode(hr, S_OK);
382 382
383 ::Sleep(FULLWAIT); 383 // ::Sleep(FULLWAIT);
384 Assert::Equal<DWORD>(1, pResults->cDirectories); 384 // Assert::Equal<DWORD>(1, pResults->cDirectories);
385 385
386 for (DWORD i = 0; i < 199; ++i) 386 // for (DWORD i = 0; i < 199; ++i)
387 { 387 // {
388 hr = StrAllocFormatted(&sczDir, L"%ls%u\\", sczBaseDir, i); 388 // hr = StrAllocFormatted(&sczDir, L"%ls%u\\", sczBaseDir, i);
389 NativeAssert::ValidReturnCode(hr, S_OK); 389 // NativeAssert::ValidReturnCode(hr, S_OK);
390 390
391 hr = MonRemoveDirectory(handle, sczDir, FALSE); 391 // hr = MonRemoveDirectory(handle, sczDir, FALSE);
392 NativeAssert::ValidReturnCode(hr, S_OK); 392 // NativeAssert::ValidReturnCode(hr, S_OK);
393 } 393 // }
394 ::Sleep(FULLWAIT); 394 // ::Sleep(FULLWAIT);
395 395
396 hr = FileFromString(sczFile, 0, L"contents2", FILE_ENCODING_UTF16_WITH_BOM); 396 // hr = FileFromString(sczFile, 0, L"contents2", FILE_ENCODING_UTF16_WITH_BOM);
397 NativeAssert::ValidReturnCode(hr, S_OK); 397 // NativeAssert::ValidReturnCode(hr, S_OK);
398 398
399 ::Sleep(FULLWAIT); 399 // ::Sleep(FULLWAIT);
400 Assert::Equal<DWORD>(2, pResults->cDirectories); 400 // Assert::Equal<DWORD>(2, pResults->cDirectories);
401 401
402 for (DWORD i = 0; i < 199; ++i) 402 // for (DWORD i = 0; i < 199; ++i)
403 { 403 // {
404 hr = StrAllocFormatted(&sczDir, L"%ls%u\\", sczBaseDir, i); 404 // hr = StrAllocFormatted(&sczDir, L"%ls%u\\", sczBaseDir, i);
405 NativeAssert::ValidReturnCode(hr, S_OK); 405 // NativeAssert::ValidReturnCode(hr, S_OK);
406 406
407 hr = MonAddDirectory(handle, sczDir, FALSE, SILENCEPERIOD, NULL); 407 // hr = MonAddDirectory(handle, sczDir, FALSE, SILENCEPERIOD, NULL);
408 NativeAssert::ValidReturnCode(hr, S_OK); 408 // NativeAssert::ValidReturnCode(hr, S_OK);
409 } 409 // }
410 ::Sleep(FULLWAIT); 410 // ::Sleep(FULLWAIT);
411 411
412 hr = FileFromString(sczFile, 0, L"contents3", FILE_ENCODING_UTF16_WITH_BOM); 412 // hr = FileFromString(sczFile, 0, L"contents3", FILE_ENCODING_UTF16_WITH_BOM);
413 NativeAssert::ValidReturnCode(hr, S_OK); 413 // NativeAssert::ValidReturnCode(hr, S_OK);
414 414
415 ::Sleep(FULLWAIT); 415 // ::Sleep(FULLWAIT);
416 Assert::Equal<DWORD>(3, pResults->cDirectories); 416 // Assert::Equal<DWORD>(3, pResults->cDirectories);
417 } 417 // }
418 finally 418 // finally
419 { 419 // {
420 ReleaseStr(sczBaseDir); 420 // ReleaseStr(sczBaseDir);
421 ReleaseStr(sczDir); 421 // ReleaseStr(sczDir);
422 ReleaseStr(sczFile); 422 // ReleaseStr(sczFile);
423 } 423 // }
424 } 424 // }
425 425
426 [Fact(Skip = "Test demonstrates failure")] 426 // [Fact(Skip = "Test demonstrates failure")]
427 void MonUtilTest() 427 // void MonUtilTest()
428 { 428 // {
429 HRESULT hr = S_OK; 429 // HRESULT hr = S_OK;
430 MON_HANDLE handle = NULL; 430 // MON_HANDLE handle = NULL;
431 List<GCHandle>^ gcHandles = gcnew List<GCHandle>(); 431 // List<GCHandle>^ gcHandles = gcnew List<GCHandle>();
432 Results *pResults = (Results *)MemAlloc(sizeof(Results), TRUE); 432 // Results *pResults = (Results *)MemAlloc(sizeof(Results), TRUE);
433 Assert::True(NULL != pResults); 433 // Assert::True(NULL != pResults);
434 434
435 try 435 // try
436 { 436 // {
437 // These ensure the function pointers we send point to this thread's appdomain, which helps with assembly binding when running tests within msbuild 437 // // These ensure the function pointers we send point to this thread's appdomain, which helps with assembly binding when running tests within msbuild
438 MonGeneralDelegate^ fpMonGeneral = gcnew MonGeneralDelegate(MonGeneral); 438 // MonGeneralDelegate^ fpMonGeneral = gcnew MonGeneralDelegate(MonGeneral);
439 GCHandle gchMonGeneral = GCHandle::Alloc(fpMonGeneral); 439 // GCHandle gchMonGeneral = GCHandle::Alloc(fpMonGeneral);
440 gcHandles->Add(gchMonGeneral); 440 // gcHandles->Add(gchMonGeneral);
441 IntPtr ipMonGeneral = Marshal::GetFunctionPointerForDelegate(fpMonGeneral); 441 // IntPtr ipMonGeneral = Marshal::GetFunctionPointerForDelegate(fpMonGeneral);
442 442
443 MonDriveStatusDelegate^ fpMonDriveStatus = gcnew MonDriveStatusDelegate(MonDriveStatus); 443 // MonDriveStatusDelegate^ fpMonDriveStatus = gcnew MonDriveStatusDelegate(MonDriveStatus);
444 GCHandle gchMonDriveStatus = GCHandle::Alloc(fpMonDriveStatus); 444 // GCHandle gchMonDriveStatus = GCHandle::Alloc(fpMonDriveStatus);
445 gcHandles->Add(gchMonDriveStatus); 445 // gcHandles->Add(gchMonDriveStatus);
446 IntPtr ipMonDriveStatus = Marshal::GetFunctionPointerForDelegate(fpMonDriveStatus); 446 // IntPtr ipMonDriveStatus = Marshal::GetFunctionPointerForDelegate(fpMonDriveStatus);
447 447
448 MonDirectoryDelegate^ fpMonDirectory = gcnew MonDirectoryDelegate(MonDirectory); 448 // MonDirectoryDelegate^ fpMonDirectory = gcnew MonDirectoryDelegate(MonDirectory);
449 GCHandle gchMonDirectory = GCHandle::Alloc(fpMonDirectory); 449 // GCHandle gchMonDirectory = GCHandle::Alloc(fpMonDirectory);
450 gcHandles->Add(gchMonDirectory); 450 // gcHandles->Add(gchMonDirectory);
451 IntPtr ipMonDirectory = Marshal::GetFunctionPointerForDelegate(fpMonDirectory); 451 // IntPtr ipMonDirectory = Marshal::GetFunctionPointerForDelegate(fpMonDirectory);
452 452
453 MonRegKeyDelegate^ fpMonRegKey = gcnew MonRegKeyDelegate(MonRegKey); 453 // MonRegKeyDelegate^ fpMonRegKey = gcnew MonRegKeyDelegate(MonRegKey);
454 GCHandle gchMonRegKey = GCHandle::Alloc(fpMonRegKey); 454 // GCHandle gchMonRegKey = GCHandle::Alloc(fpMonRegKey);
455 gcHandles->Add(gchMonRegKey); 455 // gcHandles->Add(gchMonRegKey);
456 IntPtr ipMonRegKey = Marshal::GetFunctionPointerForDelegate(fpMonRegKey); 456 // IntPtr ipMonRegKey = Marshal::GetFunctionPointerForDelegate(fpMonRegKey);
457 457
458 // "Silence period" is 100 ms 458 // // "Silence period" is 100 ms
459 hr = MonCreate(&handle, static_cast<PFN_MONGENERAL>(ipMonGeneral.ToPointer()), static_cast<PFN_MONDRIVESTATUS>(ipMonDriveStatus.ToPointer()), static_cast<PFN_MONDIRECTORY>(ipMonDirectory.ToPointer()), static_cast<PFN_MONREGKEY>(ipMonRegKey.ToPointer()), pResults); 459 // hr = MonCreate(&handle, static_cast<PFN_MONGENERAL>(ipMonGeneral.ToPointer()), static_cast<PFN_MONDRIVESTATUS>(ipMonDriveStatus.ToPointer()), static_cast<PFN_MONDIRECTORY>(ipMonDirectory.ToPointer()), static_cast<PFN_MONREGKEY>(ipMonRegKey.ToPointer()), pResults);
460 NativeAssert::ValidReturnCode(hr, S_OK); 460 // NativeAssert::ValidReturnCode(hr, S_OK);
461 461
462 hr = RegInitialize(); 462 // hr = RegInitialize();
463 NativeAssert::ValidReturnCode(hr, S_OK); 463 // NativeAssert::ValidReturnCode(hr, S_OK);
464 464
465 TestDirectory(handle, pResults); 465 // TestDirectory(handle, pResults);
466 ClearResults(pResults); 466 // ClearResults(pResults);
467 TestRegKey(handle, pResults); 467 // TestRegKey(handle, pResults);
468 ClearResults(pResults); 468 // ClearResults(pResults);
469 TestMoreThan64(handle, pResults); 469 // TestMoreThan64(handle, pResults);
470 ClearResults(pResults); 470 // ClearResults(pResults);
471 } 471 // }
472 finally 472 // finally
473 { 473 // {
474 ReleaseMon(handle); 474 // ReleaseMon(handle);
475 475
476 for each (GCHandle gcHandle in gcHandles) 476 // for each (GCHandle gcHandle in gcHandles)
477 { 477 // {
478 gcHandle.Free(); 478 // gcHandle.Free();
479 } 479 // }
480 480
481 ReleaseMem(pResults->rgDirectories); 481 // ReleaseMem(pResults->rgDirectories);
482 ReleaseMem(pResults->rgRegKeys); 482 // ReleaseMem(pResults->rgRegKeys);
483 ReleaseMem(pResults); 483 // ReleaseMem(pResults);
484 484
485 RegUninitialize(); 485 // RegUninitialize();
486 } 486 // }
487 } 487 // }
488 }; 488 // };
489} 489}
diff --git a/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp b/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp
index 381ea39a..12a2aaf1 100644
--- a/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp
+++ b/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp
@@ -142,7 +142,15 @@ namespace DutilTests
142 else 142 else
143 { 143 {
144 NativeAssert::Succeeded(hr, "Failed to canonicalize path"); 144 NativeAssert::Succeeded(hr, "Failed to canonicalize path");
145 NativeAssert::StringEqual(L"\\\\?\\C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", sczCanonicalized); 145
146 if ('\\' == *sczCanonicalized)
147 {
148 NativeAssert::StringEqual(L"\\\\?\\C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", sczCanonicalized);
149 }
150 else
151 {
152 NativeAssert::StringEqual(L"C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", sczCanonicalized);
153 }
146 } 154 }
147 155
148 hr = PathCanonicalizeForComparison(L"\\\\?\\C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", 0, &sczCanonicalized); 156 hr = PathCanonicalizeForComparison(L"\\\\?\\C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", 0, &sczCanonicalized);
@@ -153,7 +161,15 @@ namespace DutilTests
153 else 161 else
154 { 162 {
155 NativeAssert::Succeeded(hr, "Failed to canonicalize path"); 163 NativeAssert::Succeeded(hr, "Failed to canonicalize path");
156 NativeAssert::StringEqual(L"\\\\?\\C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", sczCanonicalized); 164
165 if ('\\' == *sczCanonicalized)
166 {
167 NativeAssert::StringEqual(L"\\\\?\\C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", sczCanonicalized);
168 }
169 else
170 {
171 NativeAssert::StringEqual(L"C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", sczCanonicalized);
172 }
157 } 173 }
158 174
159 hr = PathCanonicalizeForComparison(L"\\\\server", PATH_CANONICALIZE_KEEP_UNC_ROOT, &sczCanonicalized); 175 hr = PathCanonicalizeForComparison(L"\\\\server", PATH_CANONICALIZE_KEEP_UNC_ROOT, &sczCanonicalized);
@@ -288,7 +304,15 @@ namespace DutilTests
288 { 304 {
289 hr = PathAllocCanonicalizePath(L"C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", PATHCCH_ALLOW_LONG_PATHS, &sczCanonicalized); 305 hr = PathAllocCanonicalizePath(L"C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", PATHCCH_ALLOW_LONG_PATHS, &sczCanonicalized);
290 NativeAssert::Succeeded(hr, "Failed to canonicalize path"); 306 NativeAssert::Succeeded(hr, "Failed to canonicalize path");
291 NativeAssert::StringEqual(L"\\\\?\\C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", sczCanonicalized); 307
308 if ('\\' == *sczCanonicalized)
309 {
310 NativeAssert::StringEqual(L"\\\\?\\C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", sczCanonicalized);
311 }
312 else
313 {
314 NativeAssert::StringEqual(L"C:\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", sczCanonicalized);
315 }
292 316
293 hr = PathAllocCanonicalizePath(L"abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", PATHCCH_ALLOW_LONG_PATHS, &sczCanonicalized); 317 hr = PathAllocCanonicalizePath(L"abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789\\abcdefghijklomnopqrstuvwxyz0123456789", PATHCCH_ALLOW_LONG_PATHS, &sczCanonicalized);
294 NativeAssert::Succeeded(hr, "Failed to canonicalize path"); 318 NativeAssert::Succeeded(hr, "Failed to canonicalize path");
@@ -937,50 +961,22 @@ namespace DutilTests
937 void PathGetTempPathTest() 961 void PathGetTempPathTest()
938 { 962 {
939 HRESULT hr = S_OK; 963 HRESULT hr = S_OK;
940 LPCWSTR wzEnvName = L"TMP";
941 LPCWSTR wzEnvName2 = L"TEMP";
942 LPCWSTR wzLongTempPath = L"C:\\aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\\cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc\\";
943 LPWSTR sczTempPath = NULL; 964 LPWSTR sczTempPath = NULL;
944 WCHAR wzOriginalTemp[MAX_PATH + 1] = { };
945 WCHAR wzOriginalTemp2[MAX_PATH + 1] = { };
946 DWORD cch = 0; 965 DWORD cch = 0;
947 DWORD cch2 = 0;
948 SIZE_T cchTemp = 0; 966 SIZE_T cchTemp = 0;
949 size_t cchTemp2 = 0; 967 WCHAR wzPath[MAX_PATH + 1];
950
951 try
952 {
953 cch = ::GetEnvironmentVariableW(wzEnvName, wzOriginalTemp, countof(wzOriginalTemp));
954 Assert::NotEqual<DWORD>(0, cch);
955
956 if (!::SetEnvironmentVariableW(wzEnvName, wzLongTempPath))
957 {
958 Assert::Equal<DWORD>(0xFFFFFFFF, ::GetLastError());
959 }
960 968
961 cch2 = ::GetEnvironmentVariableW(wzEnvName2, wzOriginalTemp2, countof(wzOriginalTemp2)); 969 hr = PathGetTempPath(&sczTempPath, &cchTemp);
962 Assert::NotEqual<DWORD>(0, cch2); 970 NativeAssert::Succeeded(hr, "Failed to get temp path.");
963 971
964 hr = PathGetTempPath(&sczTempPath, &cchTemp); 972 cch = countof(wzPath);
965 NativeAssert::Succeeded(hr, "Failed to get temp path."); 973 cch = ::GetTempPathW(cch, wzPath);
974 Assert::NotEqual((DWORD)0, cch);
966 975
967 PathFixedBackslashTerminate(wzOriginalTemp2, countof(wzOriginalTemp2)); 976 // normalize trailing backslash
977 PathFixedBackslashTerminate(wzPath, cch);
968 978
969 hr = ::StringCchLengthW(wzOriginalTemp2, countof(wzOriginalTemp2), &cchTemp2); 979 NativeAssert::StringEqual(wzPath, sczTempPath);
970 NativeAssert::Succeeded(hr, "Failed to get temp path length.");
971
972 NativeAssert::StringEqual(wzOriginalTemp2, sczTempPath);
973 Assert::Equal<SIZE_T>(cchTemp2, cchTemp);
974 }
975 finally
976 {
977 if (cch)
978 {
979 ::SetEnvironmentVariableW(wzEnvName, wzOriginalTemp);
980 }
981
982 ReleaseStr(sczTempPath);
983 }
984 } 980 }
985 981
986 [Fact] 982 [Fact]
diff --git a/src/libs/dutil/test/DUtilUnitTest/StrUtilTest.cpp b/src/libs/dutil/test/DUtilUnitTest/StrUtilTest.cpp
index 89ed3dbb..7ad1ebdf 100644
--- a/src/libs/dutil/test/DUtilUnitTest/StrUtilTest.cpp
+++ b/src/libs/dutil/test/DUtilUnitTest/StrUtilTest.cpp
@@ -80,7 +80,217 @@ namespace DutilTests
80 TestStrAnsiAllocString(b, 0, "abCd"); 80 TestStrAnsiAllocString(b, 0, "abCd");
81 } 81 }
82 82
83 [Fact]
84 void StrUtilMultiSzLenNullTest()
85 {
86 HRESULT hr = S_OK;
87 SIZE_T cchMultiSz = 7;
88
89 DutilInitialize(&DutilTestTraceError);
90
91 try
92 {
93 hr = MultiSzLen(NULL, &cchMultiSz);
94 NativeAssert::Succeeded(hr, "Failed to get MULTISZ length for null.");
95 NativeAssert::Equal<SIZE_T>(0, cchMultiSz);
96 }
97 finally
98 {
99 DutilUninitialize();
100 }
101 }
102
103 [Fact]
104 void StrUtilMultiSzPrependEmptyTest()
105 {
106 HRESULT hr = S_OK;
107 LPWSTR sczMultiSz = NULL;
108 SIZE_T cchMultiSz = 0;
109 const WCHAR expected[] = { L'f', L'i', L'r', L's', L't', L'\0', L'\0' };
110
111 DutilInitialize(&DutilTestTraceError);
112
113 try
114 {
115 hr = MultiSzPrepend(&sczMultiSz, &cchMultiSz, L"first");
116 NativeAssert::Succeeded(hr, "Failed to prepend into empty MULTISZ.");
117 VerifyMultiSz(sczMultiSz, expected, sizeof(expected) / sizeof(expected[0]));
118 NativeAssert::Equal<SIZE_T>(sizeof(expected) / sizeof(expected[0]), cchMultiSz);
119 }
120 finally
121 {
122 ReleaseNullStr(sczMultiSz);
123 DutilUninitialize();
124 }
125 }
126
127 [Fact]
128 void StrUtilMultiSzInsertEmptyTest()
129 {
130 HRESULT hr = S_OK;
131 LPWSTR sczMultiSz = NULL;
132 SIZE_T cchMultiSz = 0;
133 const WCHAR expected[] = { L'i', L'n', L's', L'e', L'r', L't', L'\0', L'\0' };
134
135 DutilInitialize(&DutilTestTraceError);
136
137 try
138 {
139 hr = MultiSzInsertString(&sczMultiSz, &cchMultiSz, 0, L"insert");
140 NativeAssert::Succeeded(hr, "Failed to insert into empty MULTISZ.");
141 VerifyMultiSz(sczMultiSz, expected, sizeof(expected) / sizeof(expected[0]));
142 NativeAssert::Equal<SIZE_T>(sizeof(expected) / sizeof(expected[0]), cchMultiSz);
143 }
144 finally
145 {
146 ReleaseNullStr(sczMultiSz);
147 DutilUninitialize();
148 }
149 }
150
151 [Fact]
152 void StrUtilMultiSzFindTest()
153 {
154 HRESULT hr = S_OK;
155 LPWSTR sczMultiSz = NULL;
156 DWORD_PTR dwIndex = 0;
157 LPCWSTR wzFound = NULL;
158 const WCHAR source[] = { L'o', L'n', L'e', L'\0', L't', L'w', L'o', L'\0', L't', L'h', L'r', L'e', L'e', L'\0', L'\0' };
159
160 DutilInitialize(&DutilTestTraceError);
161
162 try
163 {
164 CreateMultiSz(&sczMultiSz, source, sizeof(source) / sizeof(source[0]));
165
166 hr = MultiSzFindString(sczMultiSz, L"two", &dwIndex, &wzFound);
167 NativeAssert::Succeeded(hr, "Failed to find string in MULTISZ.");
168 NativeAssert::Equal<DWORD_PTR>(1, dwIndex);
169 NativeAssert::StringEqual(L"two", wzFound);
170
171 hr = MultiSzFindSubstring(sczMultiSz, L"re", &dwIndex, &wzFound);
172 NativeAssert::Succeeded(hr, "Failed to find substring in MULTISZ.");
173 NativeAssert::Equal<DWORD_PTR>(2, dwIndex);
174 NativeAssert::StringEqual(L"three", wzFound);
175
176 hr = MultiSzFindString(sczMultiSz, L"missing", &dwIndex, &wzFound);
177 NativeAssert::SpecificReturnCode(S_FALSE, hr, "Expected not found for missing string.");
178
179 hr = MultiSzFindSubstring(sczMultiSz, L"zzz", &dwIndex, &wzFound);
180 NativeAssert::SpecificReturnCode(S_FALSE, hr, "Expected not found for missing substring.");
181 }
182 finally
183 {
184 ReleaseNullStr(sczMultiSz);
185 DutilUninitialize();
186 }
187 }
188
189 [Fact]
190 void StrUtilMultiSzRemoveTest()
191 {
192 HRESULT hr = S_OK;
193 LPWSTR sczMultiSz = NULL;
194 const WCHAR source[] = { L'o', L'n', L'e', L'\0', L't', L'w', L'o', L'\0', L't', L'h', L'r', L'e', L'e', L'\0', L'\0' };
195 const WCHAR expected[] = { L'o', L'n', L'e', L'\0', L't', L'h', L'r', L'e', L'e', L'\0', L'\0' };
196
197 DutilInitialize(&DutilTestTraceError);
198
199 try
200 {
201 CreateMultiSz(&sczMultiSz, source, sizeof(source) / sizeof(source[0]));
202
203 hr = MultiSzRemoveString(&sczMultiSz, 1);
204 NativeAssert::Succeeded(hr, "Failed to remove string from MULTISZ.");
205 VerifyMultiSz(sczMultiSz, expected, sizeof(expected) / sizeof(expected[0]));
206
207 hr = MultiSzRemoveString(&sczMultiSz, 10);
208 NativeAssert::SpecificReturnCode(S_FALSE, hr, "Expected S_FALSE when removing out of range.");
209 }
210 finally
211 {
212 ReleaseNullStr(sczMultiSz);
213 DutilUninitialize();
214 }
215 }
216
217 [Fact]
218 void StrUtilMultiSzInsertTest()
219 {
220 HRESULT hr = S_OK;
221 LPWSTR sczMultiSz = NULL;
222 SIZE_T cchMultiSz = 0;
223 const WCHAR source[] = { L'o', L'n', L'e', L'\0', L't', L'w', L'o', L'\0', L'\0' };
224 const WCHAR expected[] = { L'o', L'n', L'e', L'\0', L't', L'h', L'r', L'e', L'e', L'\0', L't', L'w', L'o', L'\0', L'\0' };
225
226 DutilInitialize(&DutilTestTraceError);
227
228 try
229 {
230 CreateMultiSz(&sczMultiSz, source, sizeof(source) / sizeof(source[0]));
231 cchMultiSz = sizeof(source) / sizeof(source[0]);
232
233 hr = MultiSzInsertString(&sczMultiSz, &cchMultiSz, 1, L"three");
234 NativeAssert::Succeeded(hr, "Failed to insert string into MULTISZ.");
235 VerifyMultiSz(sczMultiSz, expected, sizeof(expected) / sizeof(expected[0]));
236 NativeAssert::Equal<SIZE_T>(sizeof(expected) / sizeof(expected[0]), cchMultiSz);
237
238 hr = MultiSzInsertString(&sczMultiSz, &cchMultiSz, 10, L"bad");
239 NativeAssert::SpecificReturnCode(HRESULT_FROM_WIN32(ERROR_OBJECT_NOT_FOUND), hr, "Expected insert to fail for invalid index.");
240 }
241 finally
242 {
243 ReleaseNullStr(sczMultiSz);
244 DutilUninitialize();
245 }
246 }
247
248 [Fact]
249 void StrUtilMultiSzReplaceTest()
250 {
251 HRESULT hr = S_OK;
252 LPWSTR sczMultiSz = NULL;
253 const WCHAR source[] = { L'o', L'n', L'e', L'\0', L't', L'w', L'o', L'\0', L't', L'h', L'r', L'e', L'e', L'\0', L'\0' };
254 const WCHAR expected[] = { L'o', L'n', L'e', L'\0', L't', L'w', L'o', L'\0', L'f', L'o', L'u', L'r', L'\0', L'\0' };
255
256 DutilInitialize(&DutilTestTraceError);
257
258 try
259 {
260 CreateMultiSz(&sczMultiSz, source, sizeof(source) / sizeof(source[0]));
261
262 hr = MultiSzReplaceString(&sczMultiSz, 2, L"four");
263 NativeAssert::Succeeded(hr, "Failed to replace string in MULTISZ.");
264 VerifyMultiSz(sczMultiSz, expected, sizeof(expected) / sizeof(expected[0]));
265 }
266 finally
267 {
268 ReleaseNullStr(sczMultiSz);
269 DutilUninitialize();
270 }
271 }
272
83 private: 273 private:
274 void CreateMultiSz(LPWSTR* ppwzMultiSz, const WCHAR* pwzSource, SIZE_T cchSource)
275 {
276 HRESULT hr = S_OK;
277
278 hr = StrAlloc(ppwzMultiSz, cchSource);
279 NativeAssert::Succeeded(hr, "Failed to allocate MULTISZ.");
280 ::CopyMemory(*ppwzMultiSz, pwzSource, cchSource * sizeof(WCHAR));
281 }
282
283 void VerifyMultiSz(LPCWSTR wzMultiSz, const WCHAR* pwzExpected, SIZE_T cchExpected)
284 {
285 HRESULT hr = S_OK;
286 SIZE_T cchMultiSz = 0;
287
288 hr = MultiSzLen(wzMultiSz, &cchMultiSz);
289 NativeAssert::Succeeded(hr, "Failed to get MULTISZ length.");
290 NativeAssert::Equal<SIZE_T>(cchExpected, cchMultiSz);
291 NativeAssert::True(0 == ::memcmp(wzMultiSz, pwzExpected, cchExpected * sizeof(WCHAR)));
292 }
293
84 void TestTrim(LPCWSTR wzInput, LPCWSTR wzExpectedResult) 294 void TestTrim(LPCWSTR wzInput, LPCWSTR wzExpectedResult)
85 { 295 {
86 HRESULT hr = S_OK; 296 HRESULT hr = S_OK;