aboutsummaryrefslogtreecommitdiff
path: root/src/libs/dutil/test/DUtilUnitTest/MonUtilTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/dutil/test/DUtilUnitTest/MonUtilTest.cpp')
-rw-r--r--src/libs/dutil/test/DUtilUnitTest/MonUtilTest.cpp896
1 files changed, 448 insertions, 448 deletions
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}