1 /* 2 * PROJECT: ReactOS api tests 3 * LICENSE: GPLv2+ - See COPYING in the top level directory 4 * PURPOSE: Tests for GetVolumeInformation 5 * PROGRAMMER: Pierre Schweitzer <pierre@reactos.org> 6 */ 7 8 #include "precomp.h" 9 10 static VOID 11 TestGetVolumeInformationA(VOID) 12 { 13 BOOL Ret; 14 CHAR Outbuf[MAX_PATH]; 15 DWORD i, MCL, Flags, Len; 16 17 memset(Outbuf, 0xAA, MAX_PATH); 18 Ret = GetVolumeInformationA("C:\\", NULL, 0, NULL, &MCL, &Flags, Outbuf, MAX_PATH); 19 ok(Ret != FALSE, "GetVolumeInformationA failed: %ld\n", GetLastError()); 20 for (i = 0; i < MAX_PATH; ++i) 21 { 22 if (Outbuf[i] == 0) 23 { 24 break; 25 } 26 } 27 ok(i != MAX_PATH, "String was not null terminated!\n"); 28 29 memset(Outbuf, 0xAA, MAX_PATH); 30 Len = i; 31 Ret = GetVolumeInformationA("C:\\", NULL, 0, NULL, &MCL, &Flags, Outbuf, Len + 1); 32 ok(Ret != FALSE, "GetVolumeInformationA failed: %ld\n", GetLastError()); 33 for (i = 0; i < MAX_PATH; ++i) 34 { 35 if (Outbuf[i] == 0) 36 { 37 break; 38 } 39 } 40 ok(i != MAX_PATH, "String was not null terminated!\n"); 41 ok(i == Len, "String was truncated\n"); 42 43 memset(Outbuf, 0xAA, MAX_PATH); 44 Len = i; 45 SetLastError(0xdeadbeef); 46 Ret = GetVolumeInformationA("C:\\", NULL, 0, NULL, &MCL, &Flags, Outbuf, Len); 47 ok(Ret != TRUE, "GetVolumeInformationA succeed\n"); 48 ok(GetLastError() == ERROR_BAD_LENGTH, "Expected ERROR_BAD_LENGTH error, got %ld\n", GetLastError()); 49 ok(Outbuf[0] != 0xAA, "Output buffer was not written to\n"); 50 for (i = 0; i < MAX_PATH; ++i) 51 { 52 if (Outbuf[i] == 0) 53 { 54 break; 55 } 56 } 57 ok(i == MAX_PATH, "String was null terminated!\n"); 58 for (i = 0; i < MAX_PATH; ++i) 59 { 60 if (Outbuf[i] != 0xAA) 61 { 62 break; 63 } 64 } 65 ok(i != MAX_PATH, "String was not written to!\n"); 66 ok(i < Len, "Buffer has been overruned\n"); 67 } 68 69 static VOID 70 TestGetVolumeInformationW(VOID) 71 { 72 BOOL Ret; 73 WCHAR Outbuf[MAX_PATH]; 74 DWORD i, MCL, Flags, Len; 75 76 memset(Outbuf, 0xAA, sizeof(Outbuf)); 77 Ret = GetVolumeInformationW(L"C:\\", NULL, 0, NULL, &MCL, &Flags, Outbuf, MAX_PATH); 78 ok(Ret != FALSE, "GetVolumeInformationW failed: %ld\n", GetLastError()); 79 for (i = 0; i < MAX_PATH; ++i) 80 { 81 if (Outbuf[i] == 0) 82 { 83 break; 84 } 85 } 86 ok(i != MAX_PATH, "String was not null terminated!\n"); 87 88 memset(Outbuf, 0xAA, sizeof(Outbuf)); 89 Len = i; 90 Ret = GetVolumeInformationW(L"C:\\", NULL, 0, NULL, &MCL, &Flags, Outbuf, Len + 1); 91 ok(Ret != FALSE, "GetVolumeInformationW failed: %ld\n", GetLastError()); 92 for (i = 0; i < MAX_PATH; ++i) 93 { 94 if (Outbuf[i] == 0) 95 { 96 break; 97 } 98 } 99 ok(i != MAX_PATH, "String was not null terminated!\n"); 100 ok(i == Len, "String was truncated\n"); 101 102 memset(Outbuf, 0xAA, sizeof(Outbuf)); 103 Len = i; 104 SetLastError(0xdeadbeef); 105 Ret = GetVolumeInformationW(L"C:\\", NULL, 0, NULL, &MCL, &Flags, Outbuf, Len); 106 ok(Ret != TRUE, "GetVolumeInformationW succeed\n"); 107 ok(GetLastError() == ERROR_BAD_LENGTH, "Expected ERROR_BAD_LENGTH error, got %ld\n", GetLastError()); 108 ok(Outbuf[0] != 0xAA, "Output buffer was not written to\n"); 109 for (i = 0; i < MAX_PATH; ++i) 110 { 111 if (Outbuf[i] == 0) 112 { 113 break; 114 } 115 } 116 ok(i == MAX_PATH, "String was null terminated!\n"); 117 ok(i >= Len, "Buffer has not been overrun\n"); 118 } 119 120 START_TEST(GetVolumeInformation) 121 { 122 TestGetVolumeInformationW(); 123 TestGetVolumeInformationA(); 124 } 125