[NTDLL_APITEST] Disable NtContinue test when runtime checks are enabled
[reactos.git] / rostests / winetests / kernel32 / volume.c
index 7dd7388..191987c 100644 (file)
@@ -53,6 +53,7 @@ static BOOL (WINAPI *pFindVolumeClose)(HANDLE);
 static UINT (WINAPI *pGetLogicalDriveStringsA)(UINT,LPSTR);
 static UINT (WINAPI *pGetLogicalDriveStringsW)(UINT,LPWSTR);
 static BOOL (WINAPI *pGetVolumeInformationA)(LPCSTR, LPSTR, DWORD, LPDWORD, LPDWORD, LPDWORD, LPSTR, DWORD);
+static BOOL (WINAPI *pGetVolumePathNameA)(LPCSTR, LPSTR, DWORD);
 static BOOL (WINAPI *pGetVolumePathNamesForVolumeNameA)(LPCSTR, LPSTR, DWORD, LPDWORD);
 static BOOL (WINAPI *pGetVolumePathNamesForVolumeNameW)(LPCWSTR, LPWSTR, DWORD, LPDWORD);
 
@@ -121,7 +122,7 @@ static void test_define_dos_deviceA(void)
     }
 
     /* Map it to point to the current directory */
-    ret = GetCurrentDirectory(sizeof(buf), buf);
+    ret = GetCurrentDirectoryA(sizeof(buf), buf);
     ok(ret, "GetCurrentDir\n");
 
     ret = DefineDosDeviceA(0, drivestr, buf);
@@ -213,7 +214,7 @@ static void test_GetVolumeNameForVolumeMountPointA(void)
             "GetVolumeNameForVolumeMountPointA failed, wrong error returned, was %d, should be ERROR_FILENAME_EXCED_RANGE\n",
              GetLastError());
 
-    /* Try on a arbitrary directory */
+    /* Try on an arbitrary directory */
     /* On FAT filesystems it seems that GetLastError() is set to
        ERROR_INVALID_FUNCTION. */
     ret = pGetVolumeNameForVolumeMountPointA(temp_path, volume, len);
@@ -367,26 +368,26 @@ static void test_GetVolumeInformationA(void)
     }
 
     /* get windows drive letter and update strings for testing */
-    result = GetWindowsDirectory(windowsdir, sizeof(windowsdir));
+    result = GetWindowsDirectoryA(windowsdir, sizeof(windowsdir));
     ok(result < sizeof(windowsdir), "windowsdir is abnormally long!\n");
     ok(result != 0, "GetWindowsDirectory: error %d\n", GetLastError());
     Root_Colon[0] = windowsdir[0];
     Root_Slash[0] = windowsdir[0];
     Root_UNC[4] = windowsdir[0];
 
-    result = GetCurrentDirectory(MAX_PATH, currentdir);
+    result = GetCurrentDirectoryA(MAX_PATH, currentdir);
     ok(result, "GetCurrentDirectory: error %d\n", GetLastError());
     /* Note that GetCurrentDir yields no trailing slash for subdirs */
 
     /* check for NO error on no trailing \ when current dir is root dir */
-    ret = SetCurrentDirectory(Root_Slash);
+    ret = SetCurrentDirectoryA(Root_Slash);
     ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
     ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
             NULL, NULL, fs_name_buf, fs_name_len);
     ok(ret, "GetVolumeInformationA root failed, last error %u\n", GetLastError());
 
     /* check for error on no trailing \ when current dir is subdir (windows) of queried drive */
-    ret = SetCurrentDirectory(windowsdir);
+    ret = SetCurrentDirectoryA(windowsdir);
     ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
     SetLastError(0xdeadbeef);
     ret = pGetVolumeInformationA(Root_Colon, vol_name_buf, vol_name_size, NULL,
@@ -395,7 +396,7 @@ static void test_GetVolumeInformationA(void)
         "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
 
     /* reset current directory */
-    ret = SetCurrentDirectory(currentdir);
+    ret = SetCurrentDirectoryA(currentdir);
     ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
 
     if (toupper(currentdir[0]) == toupper(windowsdir[0])) {
@@ -407,12 +408,12 @@ static void test_GetVolumeInformationA(void)
 
         /* C:\windows becomes the current directory on drive C: */
         /* Note that paths to subdirs are stored without trailing slash, like what GetCurrentDir yields. */
-        ret = SetEnvironmentVariable(Root_Env, windowsdir);
+        ret = SetEnvironmentVariableA(Root_Env, windowsdir);
         ok(ret, "SetEnvironmentVariable %s failed\n", Root_Env);
 
-        ret = SetCurrentDirectory(windowsdir);
+        ret = SetCurrentDirectoryA(windowsdir);
         ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
-        ret = SetCurrentDirectory(currentdir);
+        ret = SetCurrentDirectoryA(currentdir);
         ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
 
         /* windows dir is current on the root drive, call fails */
@@ -427,9 +428,9 @@ static void test_GetVolumeInformationA(void)
                 NULL, NULL, fs_name_buf, fs_name_len);
         ok(ret, "GetVolumeInformationA with \\ failed, last error %u\n", GetLastError());
 
-        ret = SetCurrentDirectory(Root_Slash);
+        ret = SetCurrentDirectoryA(Root_Slash);
         ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
-        ret = SetCurrentDirectory(currentdir);
+        ret = SetCurrentDirectoryA(currentdir);
         ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
 
         /* windows dir is STILL CURRENT on root drive; the call fails as before,   */
@@ -441,7 +442,7 @@ static void test_GetVolumeInformationA(void)
            "GetVolumeInformationA did%s fail, last error %u\n", ret ? " not":"", GetLastError());
 
         /* Now C:\ becomes the current directory on drive C: */
-        ret = SetEnvironmentVariable(Root_Env, Root_Slash); /* set =C:=C:\ */
+        ret = SetEnvironmentVariableA(Root_Env, Root_Slash); /* set =C:=C:\ */
         ok(ret, "SetEnvironmentVariable %s failed\n", Root_Env);
 
         /* \ is current on root drive, call succeeds */
@@ -450,9 +451,9 @@ static void test_GetVolumeInformationA(void)
         ok(ret, "GetVolumeInformationA failed, last error %u\n", GetLastError());
 
         /* again, SetCurrentDirectory on another drive does not matter */
-        ret = SetCurrentDirectory(Root_Slash);
+        ret = SetCurrentDirectoryA(Root_Slash);
         ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
-        ret = SetCurrentDirectory(currentdir);
+        ret = SetCurrentDirectoryA(currentdir);
         ok(ret, "SetCurrentDirectory: error %d\n", GetLastError());
 
         /* \ is current on root drive, call succeeds */
@@ -532,7 +533,7 @@ static void test_enum_vols(void)
     }
 
     /*get windows drive letter and update strings for testing  */
-    ret = GetWindowsDirectory( windowsdir, sizeof(windowsdir) );
+    ret = GetWindowsDirectoryA( windowsdir, sizeof(windowsdir) );
     ok(ret < sizeof(windowsdir), "windowsdir is abnormally long!\n");
     ok(ret != 0, "GetWindowsDirecory: error %d\n", GetLastError());
     path[0] = windowsdir[0];
@@ -590,6 +591,86 @@ static void test_disk_extents(void)
     CloseHandle( handle );
 }
 
+static void test_GetVolumePathNameA(void)
+{
+    BOOL ret;
+    char volume[MAX_PATH];
+    char expected[] = "C:\\", pathC1[] = "C:\\", pathC2[] = "C::";
+    DWORD error;
+
+    if (!pGetVolumePathNameA)
+    {
+        win_skip("required functions not found\n");
+        return;
+    }
+
+    SetLastError( 0xdeadbeef );
+    ret = pGetVolumePathNameA(NULL, NULL, 0);
+    error = GetLastError();
+    ok(!ret, "expected failure\n");
+    ok(error == ERROR_INVALID_PARAMETER
+       || broken( error == 0xdeadbeef) /* <=XP */,
+       "expected ERROR_INVALID_PARAMETER got %u\n", error);
+
+    SetLastError( 0xdeadbeef );
+    ret = pGetVolumePathNameA("", NULL, 0);
+    error = GetLastError();
+    ok(!ret, "expected failure\n");
+    ok(error == ERROR_INVALID_PARAMETER
+       || broken( error == 0xdeadbeef) /* <=XP */,
+       "expected ERROR_INVALID_PARAMETER got %u\n", error);
+
+    SetLastError( 0xdeadbeef );
+    ret = pGetVolumePathNameA(pathC1, NULL, 0);
+    error = GetLastError();
+    ok(!ret, "expected failure\n");
+    ok(error == ERROR_INVALID_PARAMETER
+       || broken(error == ERROR_FILENAME_EXCED_RANGE) /* <=XP */,
+       "expected ERROR_INVALID_PARAMETER got %u\n", error);
+
+    SetLastError( 0xdeadbeef );
+    ret = pGetVolumePathNameA(pathC1, volume, 0);
+    error = GetLastError();
+    ok(!ret, "expected failure\n");
+    ok(error == ERROR_INVALID_PARAMETER
+       || broken(error == ERROR_FILENAME_EXCED_RANGE ) /* <=XP */,
+       "expected ERROR_INVALID_PARAMETER got %u\n", error);
+
+    SetLastError( 0xdeadbeef );
+    ret = pGetVolumePathNameA(pathC1, volume, 1);
+    error = GetLastError();
+    ok(!ret, "expected failure\n");
+    ok(error == ERROR_FILENAME_EXCED_RANGE, "expected ERROR_FILENAME_EXCED_RANGE got %u\n", error);
+
+    volume[0] = '\0';
+    ret = pGetVolumePathNameA(pathC1, volume, sizeof(volume));
+    ok(ret, "expected success\n");
+    ok(!strcmp(expected, volume), "expected name '%s', returned '%s'\n", pathC1, volume);
+
+    pathC1[0] = tolower(pathC1[0]);
+    volume[0] = '\0';
+    ret = pGetVolumePathNameA(pathC1, volume, sizeof(volume));
+    ok(ret, "expected success\n");
+todo_wine
+    ok(!strcmp(expected, volume) || broken(!strcasecmp(expected, volume)) /* <=XP */,
+       "expected name '%s', returned '%s'\n", expected, volume);
+
+    volume[0] = '\0';
+    ret = pGetVolumePathNameA(pathC2, volume, sizeof(volume));
+todo_wine
+    ok(ret, "expected success\n");
+todo_wine
+    ok(!strcmp(expected, volume), "expected name '%s', returned '%s'\n", expected, volume);
+
+    /* test an invalid path */
+    SetLastError( 0xdeadbeef );
+    ret = pGetVolumePathNameA("\\\\$$$", volume, 1);
+    error = GetLastError();
+    ok(!ret, "expected failure\n");
+    ok(error == ERROR_INVALID_NAME || broken(ERROR_FILENAME_EXCED_RANGE) /* <=2000 */,
+       "expected ERROR_INVALID_NAME got %u\n", error);
+}
+
 static void test_GetVolumePathNamesForVolumeNameA(void)
 {
     BOOL ret;
@@ -684,6 +765,12 @@ static void test_GetVolumePathNamesForVolumeNameW(void)
     WCHAR volume[MAX_PATH], buffer[MAX_PATH];
     DWORD len, error;
 
+#ifdef __REACTOS__
+    /* due to failing all calls to GetVolumeNameForVolumeMountPointW, this
+     * buffer never gets initialized and could cause a buffer overflow later */
+    volume[0] = 0;
+#endif /* __REACTOS__ */
+
     if (!pGetVolumePathNamesForVolumeNameW || !pGetVolumeNameForVolumeMountPointW)
     {
         win_skip("required functions not found\n");
@@ -777,17 +864,12 @@ static void test_dvd_read_structure(HANDLE handle)
     /* Test whether this ioctl is supported */
     ret = DeviceIoControl(handle, IOCTL_DVD_READ_STRUCTURE, &dvdReadStructure, sizeof(DVD_READ_STRUCTURE),
         &completeDvdLayerDescriptor, sizeof(struct COMPLETE_DVD_LAYER_DESCRIPTOR), &nbBytes, NULL);
-    if ((!ret && GetLastError() == ERROR_INVALID_FUNCTION)
-     || (!ret && GetLastError() == ERROR_NOT_SUPPORTED))
-    {
-        skip("IOCTL_DVD_READ_STRUCTURE not supported\n");
-        return;
-    }
 
-    ok(ret || broken(GetLastError() == ERROR_NOT_READY) || broken(GetLastError() == ERROR_INVALID_PARAMETER),
-        "IOCTL_DVD_READ_STRUCTURE (DvdPhysicalDescriptor) failed, last error = %u\n", GetLastError());
     if(!ret)
+    {
+        skip("IOCTL_DVD_READ_STRUCTURE not supported: %u\n", GetLastError());
         return;
+    }
 
     /* Confirm there is always a header before the actual data */
     ok( completeDvdLayerDescriptor.Header.Length == 0x0802, "Length is 0x%04x instead of 0x0802\n", completeDvdLayerDescriptor.Header.Length);
@@ -933,12 +1015,14 @@ START_TEST(volume)
     pGetLogicalDriveStringsA = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsA");
     pGetLogicalDriveStringsW = (void *) GetProcAddress(hdll, "GetLogicalDriveStringsW");
     pGetVolumeInformationA = (void *) GetProcAddress(hdll, "GetVolumeInformationA");
+    pGetVolumePathNameA = (void *) GetProcAddress(hdll, "GetVolumePathNameA");
     pGetVolumePathNamesForVolumeNameA = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameA");
     pGetVolumePathNamesForVolumeNameW = (void *) GetProcAddress(hdll, "GetVolumePathNamesForVolumeNameW");
 
     test_query_dos_deviceA();
     test_define_dos_deviceA();
     test_FindFirstVolume();
+    test_GetVolumePathNameA();
     test_GetVolumeNameForVolumeMountPointA();
     test_GetVolumeNameForVolumeMountPointW();
     test_GetLogicalDriveStringsA();