[NTDLL_APITEST] Add several tests for RtlDosApplyFileIsolationRedirection_Ustr
authorGiannis Adamopoulos <gadamopoulos@reactos.org>
Wed, 4 Oct 2017 08:10:59 +0000 (11:10 +0300)
committerGiannis Adamopoulos <gadamopoulos@reactos.org>
Sun, 24 Dec 2017 19:19:03 +0000 (21:19 +0200)
modules/rostests/apitests/ntdll/CMakeLists.txt
modules/rostests/apitests/ntdll/RtlDosApplyFileIsolationRedirection_Ustr.c
modules/rostests/apitests/ntdll/ntdlltest.manifest [new file with mode: 0644]

index 42fc3fb..c1a3aea 100644 (file)
@@ -77,3 +77,4 @@ add_rostests_file(TARGET ntdll_apitest SUBDIR testdata)
 add_rostests_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/ntdll_apitest.exe.local" SUBDIR testdata)
 add_rostests_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/shell32.dll" SUBDIR testdata)
 add_rostests_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/test.dll" SUBDIR testdata)
+add_rostests_file(FILE "${CMAKE_CURRENT_SOURCE_DIR}/ntdlltest.manifest" SUBDIR testdata)
index 9b9f159..fb2b516 100644 (file)
@@ -33,6 +33,11 @@ struct test_data Tests[] =
     {__LINE__, STATUS_SUCCESS, L"COMCTL32.DLL", L"\\winsxs\\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82"},
     {__LINE__, STATUS_SUCCESS, L"comctl32.DLL", L"\\winsxs\\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82"},
     {__LINE__, STATUS_SUCCESS, L"c:\\windows\\system32\\comctl32.DLL", L"\\winsxs\\x86_microsoft.windows.common-controls_6595b64144ccf1df_5.82"},
+    /* Files defined in the manifest, one exists, one doesn't */
+    {__LINE__, STATUS_SUCCESS, L"deptest.dll", EXPECT_IN_SAME_DIR},
+    {__LINE__, STATUS_SUCCESS, L"adllfile.dll", EXPECT_IN_SAME_DIR},
+    /* A file that exists in the same dir but isn't mentioned in the manifest */
+    {__LINE__, STATUS_SUCCESS, L"fil1.txt", EXPECT_IN_SAME_DIR},
     /* This is a weird case; the source doesn't exist but does get redirected */
     {__LINE__, STATUS_SUCCESS, L"c:\\windows\\system32\\gdiplus.DLL", L"\\winsxs\\x86_microsoft.windows.gdiplus_6595b64144ccf1df_1."},
     /* But redirecting gdiplus from a different directory doesn't work */
@@ -48,6 +53,28 @@ struct test_data Tests[] =
     {__LINE__, STATUS_SUCCESS, L"c:\\shell32.dll", EXPECT_IN_SAME_DIR}
 };
 
+HANDLE _CreateActCtxFromFile(LPCWSTR FileName, int line)
+{
+    ACTCTXW ActCtx = {sizeof(ACTCTX)};
+    HANDLE h;
+    WCHAR buffer[MAX_PATH] , *separator;
+
+    ok (GetModuleFileNameW(NULL, buffer, MAX_PATH), "GetModuleFileName failed\n");
+    separator = wcsrchr(buffer, L'\\');
+    if (separator)
+        wcscpy(separator + 1, FileName);
+
+    ActCtx.lpSource = buffer;
+
+    SetLastError(0xdeaddead);
+    h = CreateActCtxW(&ActCtx);
+    ok_(__FILE__, line)(h != INVALID_HANDLE_VALUE, "CreateActCtx failed for %S\n", FileName);
+    // In win10 last error is unchanged and in win2k3 it is ERROR_BAD_EXE_FORMAT    
+    ok_(__FILE__, line)(GetLastError() == ERROR_BAD_EXE_FORMAT || GetLastError() == 0xdeaddead, "Wrong last error %lu\n", GetLastError());
+
+    return h;
+}
+
 void TestRedirection(void)
 {
     WCHAR SystemDir[MAX_PATH];
@@ -92,12 +119,6 @@ void TestRedirection(void)
                                                           NULL);
         ok(Status == Tests[i].ExpectedStatus, "%d: Status 0x%lx, expected 0x%lx\n", Tests[i].testline, Status, Tests[i].ExpectedStatus);
 
-        if (DynamicString.Buffer)
-        {
-            BOOL exists = RtlDoesFileExists_U(DynamicString.Buffer);
-            ok(exists, "%d: Expected file %S to exist!\n", Tests[i].testline, DynamicString.Buffer);
-        }
-
         if(Tests[i].ExpectedSubString && DynamicString.Buffer == NULL)
         {
             ok(0, "%d: Expected a returned string\n", Tests[i].testline);
@@ -118,6 +139,231 @@ void TestRedirection(void)
     }
 }
 
+void TestBuffers()
+{
+    UNICODE_STRING Param, DynamicString, StaticString;
+    PUNICODE_STRING StringUsed = NULL;
+    NTSTATUS Status;
+    WCHAR buffer[MAX_PATH];
+
+    RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
+    Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
+                                                      NULL, 
+                                                      NULL,
+                                                      NULL,
+                                                      &DynamicString,
+                                                      &StringUsed,
+                                                      NULL,
+                                                      NULL,
+                                                      NULL);
+    ok(Status ==STATUS_INVALID_PARAMETER, "0x%lx\n", Status);
+
+    RtlInitEmptyUnicodeString(&Param, NULL, 0);
+    RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
+    Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
+                                                      &Param, 
+                                                      NULL, 
+                                                      NULL,
+                                                      &DynamicString,
+                                                      &StringUsed,
+                                                      NULL,
+                                                      NULL,
+                                                      NULL);
+    ok(Status ==STATUS_SXS_KEY_NOT_FOUND, "0x%lx\n", Status);
+
+    /* Tests for NULL termination of OriginalName */
+    Param.MaximumLength = Param.Length = 12 * sizeof(WCHAR);
+    Param.Buffer = L"comctl32.dllcrapcrap";
+    RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
+    Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
+                                                      &Param, 
+                                                      NULL, 
+                                                      NULL,
+                                                      &DynamicString,
+                                                      &StringUsed,
+                                                      NULL,
+                                                      NULL,
+                                                      NULL);
+    ok(Status ==STATUS_SUCCESS, "\n");
+
+    /* Tests for the Extension parameter */
+    RtlInitUnicodeString(&Param, L"comctl32.dll");
+    RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
+    Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
+                                                      &Param, 
+                                                      NULL, 
+                                                      NULL,
+                                                      &DynamicString,
+                                                      &StringUsed,
+                                                      NULL,
+                                                      NULL,
+                                                      NULL);
+    ok(Status ==STATUS_SUCCESS, "\n");
+
+    RtlInitUnicodeString(&Param, L"comctl32");
+    RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
+    Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
+                                                      &Param, 
+                                                      NULL, 
+                                                      NULL,
+                                                      &DynamicString,
+                                                      &StringUsed,
+                                                      NULL,
+                                                      NULL,
+                                                      NULL);
+    ok(Status ==STATUS_SXS_KEY_NOT_FOUND, "0x%lx\n", Status);
+
+    RtlInitUnicodeString(&Param, L"comctl32");
+    RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
+    Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
+                                                      &Param, 
+                                                      &DotDll, 
+                                                      NULL,
+                                                      &DynamicString,
+                                                      &StringUsed,
+                                                      NULL,
+                                                      NULL,
+                                                      NULL);
+    ok(Status ==STATUS_SUCCESS, "\n");
+
+    /* Tests for the DynamicString parameter */
+    RtlInitUnicodeString(&Param, L"comctl32.dll");
+    RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
+    Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
+                                                      &Param, 
+                                                      NULL,
+                                                      NULL,
+                                                      &DynamicString,
+                                                      &StringUsed,
+                                                      NULL,
+                                                      NULL,
+                                                      NULL);
+    ok(Status ==STATUS_SUCCESS, "\n");
+    ok(DynamicString.Length >0 , "\n");
+    ok(DynamicString.MaximumLength == DynamicString.Length + sizeof(WCHAR) , "\n");
+    if (DynamicString.Buffer && DynamicString.Length)
+        ok(wcslen(DynamicString.Buffer) * sizeof(WCHAR) == DynamicString.Length, "got %d and %d\n", wcslen(DynamicString.Buffer)  * sizeof(WCHAR) , DynamicString.Length);
+    else
+        ok(DynamicString.Buffer != NULL, "Expected non NULL buffer\n");
+    ok(StringUsed == &DynamicString, "\n");
+
+    /* Tests for the StaticString parameter */
+    wcscpy(buffer, L"comctl32.dll");
+    StaticString.Buffer = buffer;
+    StaticString.Length = sizeof(L"comctl32.dll");
+    StaticString.MaximumLength = sizeof(buffer);
+    Param = StaticString;
+    Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
+                                                      &Param, 
+                                                      NULL, 
+                                                      &StaticString,
+                                                      NULL,
+                                                      &StringUsed,
+                                                      NULL,
+                                                      NULL,
+                                                      NULL);
+    ok(Status ==STATUS_SXS_KEY_NOT_FOUND, "0x%lx\n", Status);
+
+    wcscpy(buffer, L"comctl32.dll");
+    StaticString.Buffer = buffer;
+    StaticString.Length = sizeof(L"comctl32.dll");
+    StaticString.MaximumLength = sizeof(buffer);
+    Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
+                                                      &StaticString, 
+                                                      NULL, 
+                                                      &StaticString,
+                                                      NULL,
+                                                      &StringUsed,
+                                                      NULL,
+                                                      NULL,
+                                                      NULL);
+    ok(Status ==STATUS_SXS_KEY_NOT_FOUND, "0x%lx\n", Status);
+
+    RtlInitUnicodeString(&Param, L"comctl32.dll");
+    RtlInitEmptyUnicodeString(&StaticString, buffer, sizeof(buffer));
+    Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
+                                                      &Param, 
+                                                      NULL, 
+                                                      &StaticString,
+                                                      NULL,
+                                                      &StringUsed,
+                                                      NULL,
+                                                      NULL,
+                                                      NULL);
+    ok(Status ==STATUS_SUCCESS, "\n");
+    ok(StaticString.Length >0 , "\n");
+    ok(StaticString.MaximumLength == sizeof(buffer) , "\n");
+    if (StaticString.Buffer && StaticString.Length)
+        ok(wcslen(StaticString.Buffer) * sizeof(WCHAR) == StaticString.Length, "got %d and %d\n", wcslen(StaticString.Buffer)  * sizeof(WCHAR) , StaticString.Length);
+    else
+        ok(StaticString.Length != 0, "Expected non 0 lenght\n");
+    ok(StringUsed == &StaticString, "\n");
+
+    RtlInitEmptyUnicodeString(&StaticString, buffer, 5 * sizeof(WCHAR));
+    Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
+                                                      &Param, 
+                                                      NULL, 
+                                                      &StaticString,
+                                                      NULL,
+                                                      &StringUsed,
+                                                      NULL,
+                                                      NULL,
+                                                      NULL);
+    ok(Status == STATUS_BUFFER_TOO_SMALL, "0x%lx\n", Status);
+
+    RtlInitUnicodeString(&Param, L"comctl32.dll");
+    RtlInitEmptyUnicodeString(&StaticString, buffer, sizeof(buffer));
+    RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
+    Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
+                                                      &Param, 
+                                                      NULL, 
+                                                      &StaticString,
+                                                      &DynamicString,
+                                                      &StringUsed,
+                                                      NULL,
+                                                      NULL,
+                                                      NULL);
+    ok(Status ==STATUS_SUCCESS, "\n");
+    ok(StaticString.Length >0 , "\n");
+    ok(StaticString.MaximumLength == sizeof(buffer) , "\n");
+    if (StaticString.Buffer && StaticString.Length)
+        ok(wcslen(StaticString.Buffer) * sizeof(WCHAR) == StaticString.Length, "got %d and %d\n", wcslen(StaticString.Buffer)  * sizeof(WCHAR) , StaticString.Length);
+    else
+        ok(StaticString.Length != 0, "Expected non 0 lenght\n");
+    ok(DynamicString.Buffer == NULL, "\n");
+    ok(DynamicString.Length == 0, "\n");
+    ok(DynamicString.MaximumLength == 0, "\n");
+    ok(StringUsed == &StaticString, "\n");
+
+    /* Test a small buffer and a dynamic buffer */
+    RtlInitUnicodeString(&Param, L"comctl32.dll");
+    RtlInitEmptyUnicodeString(&StaticString, buffer, 5 * sizeof(WCHAR));
+    RtlInitEmptyUnicodeString(&DynamicString, NULL, 0);
+    StaticString.Buffer[0] = 1;
+    Status = RtlDosApplyFileIsolationRedirection_Ustr(TRUE,
+                                                      &Param, 
+                                                      NULL, 
+                                                      &StaticString,
+                                                      &DynamicString,
+                                                      &StringUsed,
+                                                      NULL,
+                                                      NULL,
+                                                      NULL);
+    ok(Status ==STATUS_SUCCESS, "\n");
+    ok(StaticString.Buffer == buffer, "\n");
+    ok(StaticString.Length == 0 , "%d\n", StaticString.Length);
+    ok(StaticString.Buffer[0] == 0, "\n");
+    ok(StaticString.MaximumLength == 5 * sizeof(WCHAR) , "%d\n", StaticString.MaximumLength);
+    ok(DynamicString.Length >0 , "\n");
+    ok(DynamicString.MaximumLength == DynamicString.Length + sizeof(WCHAR) , "\n");
+    if (DynamicString.Buffer && DynamicString.Length)
+        ok(wcslen(DynamicString.Buffer) * sizeof(WCHAR) == DynamicString.Length, "got %d and %d\n", wcslen(DynamicString.Buffer)  * sizeof(WCHAR) , DynamicString.Length);
+    else
+        ok(DynamicString.Length != 0, "Expected non 0 lenght\n");
+
+    ok(StringUsed == &DynamicString, "\n");
+}
+
 START_TEST(RtlDosApplyFileIsolationRedirection_Ustr)
 {
     int argc;
@@ -125,7 +371,18 @@ START_TEST(RtlDosApplyFileIsolationRedirection_Ustr)
     argc = winetest_get_mainargs( &test_argv );
     if (argc >= 3)
     {
+        HANDLE h = _CreateActCtxFromFile(L"ntdlltest.manifest", __LINE__);
+        BOOL bactivated = FALSE;
+        ULONG_PTR cookie;
+        
+        if (h != INVALID_HANDLE_VALUE)
+            bactivated = ActivateActCtx(h, &cookie);
+
         TestRedirection();
+        TestBuffers();
+
+        if (bactivated)
+            DeactivateActCtx(0, cookie);
     }
     else
     {
diff --git a/modules/rostests/apitests/ntdll/ntdlltest.manifest b/modules/rostests/apitests/ntdll/ntdlltest.manifest
new file mode 100644 (file)
index 0000000..a91a9b6
--- /dev/null
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+  <assemblyIdentity type="win32" name="ntdll_apitest" version="1.0.0.0"/>
+    <dependency>
+         <dependentAssembly>
+            <assemblyIdentity type="win32" name="Microsoft.Windows.GdiPlus" version="1.0.100.0" language="*" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df"/>
+         </dependentAssembly>
+    </dependency>
+    <dependency>
+         <dependentAssembly>
+            <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="5.82.0.0" language="*" processorArchitecture="x86" publicKeyToken="6595b64144ccf1df"/>
+         </dependentAssembly>
+    </dependency>
+    <file name="deptest.dll"/>
+    <file name="adllfile.dll"/>
+</assembly>