static VOID RunTestCases(VOID) { /* TODO: don't duplicate this in the other tests */ /* TODO: Drive Relative tests don't work yet if the current drive isn't C: */ struct { PCWSTR FileName; PREFIX_TYPE PrefixType; PCWSTR FullPathName; RTL_PATH_TYPE PathType; PREFIX_TYPE FilePartPrefixType; SIZE_T FilePartSize; } TestCases[] = { { L"C:", PrefixCurrentPath, L"", RtlPathTypeDriveRelative, PrefixCurrentPathWithoutLastPart }, { L"C:\\", PrefixNone, L"C:\\", RtlPathTypeDriveAbsolute }, { L"C:\\test", PrefixNone, L"C:\\test", RtlPathTypeDriveAbsolute, PrefixCurrentDrive }, { L"C:\\test\\", PrefixNone, L"C:\\test\\", RtlPathTypeDriveAbsolute }, { L"C:/test/", PrefixNone, L"C:\\test\\", RtlPathTypeDriveAbsolute }, { L"C:\\\\test", PrefixNone, L"C:\\test", RtlPathTypeDriveAbsolute, PrefixCurrentDrive }, { L"test", PrefixCurrentPath, L"\\test", RtlPathTypeRelative, PrefixCurrentPath, sizeof(WCHAR) }, { L"\\test", PrefixCurrentDrive, L"test", RtlPathTypeRooted, PrefixCurrentDrive }, { L"/test", PrefixCurrentDrive, L"test", RtlPathTypeRooted, PrefixCurrentDrive }, { L".\\test", PrefixCurrentPath, L"\\test", RtlPathTypeRelative, PrefixCurrentPath, sizeof(WCHAR) }, { L"\\.", PrefixCurrentDrive, L"", RtlPathTypeRooted }, { L"\\.\\", PrefixCurrentDrive, L"", RtlPathTypeRooted }, { L"\\\\.", PrefixNone, L"\\\\.\\", RtlPathTypeRootLocalDevice }, { L"\\\\.\\", PrefixNone, L"\\\\.\\", RtlPathTypeLocalDevice }, { L"\\\\.\\Something\\", PrefixNone, L"\\\\.\\Something\\", RtlPathTypeLocalDevice }, { L"\\??\\", PrefixCurrentDrive, L"??\\", RtlPathTypeRooted }, { L"\\??\\C:", PrefixCurrentDrive, L"??\\C:", RtlPathTypeRooted, PrefixCurrentDrive, 3 * sizeof(WCHAR) }, { L"\\??\\C:\\", PrefixCurrentDrive, L"??\\C:\\", RtlPathTypeRooted }, { L"\\??\\C:\\test", PrefixCurrentDrive, L"??\\C:\\test", RtlPathTypeRooted, PrefixCurrentDrive, 6 * sizeof(WCHAR) }, { L"\\??\\C:\\test\\", PrefixCurrentDrive, L"??\\C:\\test\\", RtlPathTypeRooted }, { L"\\\\??\\", PrefixNone, L"\\\\??\\", RtlPathTypeUncAbsolute }, { L"\\\\??\\C:", PrefixNone, L"\\\\??\\C:", RtlPathTypeUncAbsolute }, { L"\\\\??\\C:\\", PrefixNone, L"\\\\??\\C:\\", RtlPathTypeUncAbsolute }, { L"\\\\??\\C:\\test", PrefixNone, L"\\\\??\\C:\\test", RtlPathTypeUncAbsolute, PrefixNone, sizeof(L"\\\\??\\C:\\") }, { L"\\\\??\\C:\\test\\", PrefixNone, L"\\\\??\\C:\\test\\", RtlPathTypeUncAbsolute }, }; NTSTATUS Status, ExceptionStatus; UNICODE_STRING FileName; UNICODE_STRING FullPathName; WCHAR FullPathNameBuffer[MAX_PATH]; UNICODE_STRING TempString; PUNICODE_STRING StringUsed; SIZE_T FilePartSize; BOOLEAN NameInvalid; RTL_PATH_TYPE PathType; SIZE_T LengthNeeded; WCHAR ExpectedPathName[MAX_PATH]; SIZE_T ExpectedFilePartSize; const INT TestCount = sizeof(TestCases) / sizeof(TestCases[0]); INT i; BOOLEAN Okay; for (i = 0; i < TestCount; i++) { trace("i = %d\n", i); switch (TestCases[i].PrefixType) { case PrefixNone: ExpectedPathName[0] = UNICODE_NULL; break; case PrefixCurrentDrive: GetCurrentDirectoryW(sizeof(ExpectedPathName) / sizeof(WCHAR), ExpectedPathName); ExpectedPathName[3] = UNICODE_NULL; break; case PrefixCurrentPath: { ULONG Length; Length = GetCurrentDirectoryW(sizeof(ExpectedPathName) / sizeof(WCHAR), ExpectedPathName); if (Length == 3 && TestCases[i].FullPathName[0]) ExpectedPathName[2] = UNICODE_NULL; break; } default: skip(0, "Invalid test!\n"); continue; } wcscat(ExpectedPathName, TestCases[i].FullPathName); RtlInitUnicodeString(&FileName, TestCases[i].FileName); RtlInitEmptyUnicodeString(&FullPathName, FullPathNameBuffer, sizeof(FullPathNameBuffer)); RtlFillMemory(FullPathName.Buffer, FullPathName.MaximumLength, 0xAA); TempString = FileName; PathType = RtlPathTypeNotSet; StringUsed = InvalidPointer; FilePartSize = 1234; NameInvalid = (BOOLEAN)-1; LengthNeeded = 1234; StartSeh() Status = pRtlGetFullPathName_UstrEx(&FileName, &FullPathName, NULL, &StringUsed, &FilePartSize, &NameInvalid, &PathType, &LengthNeeded); ok(Status == STATUS_SUCCESS, "status = %lx\n", Status); EndSeh(STATUS_SUCCESS); ok_eq_ustr(&FileName, &TempString); ok(FullPathName.Buffer == FullPathNameBuffer, "Buffer modified\n"); ok(FullPathName.MaximumLength == sizeof(FullPathNameBuffer), "MaximumLength modified\n"); Okay = CheckStringBuffer(&FullPathName, ExpectedPathName); ok(Okay, "Wrong path name '%wZ', expected '%S'\n", &FullPathName, ExpectedPathName); ok(StringUsed == &FullPathName, "StringUsed = %p, expected %p\n", StringUsed, &FullPathName); switch (TestCases[i].FilePartPrefixType) { case PrefixNone: ExpectedFilePartSize = 0; break; case PrefixCurrentDrive: ExpectedFilePartSize = sizeof(L"C:\\"); break; case PrefixCurrentPath: ExpectedFilePartSize = GetCurrentDirectoryW(0, NULL) * sizeof(WCHAR); if (ExpectedFilePartSize == sizeof(L"C:\\")) ExpectedFilePartSize -= sizeof(WCHAR); break; case PrefixCurrentPathWithoutLastPart: { WCHAR CurrentPath[MAX_PATH]; PCWSTR BackSlash; ExpectedFilePartSize = GetCurrentDirectoryW(sizeof(CurrentPath) / sizeof(WCHAR), CurrentPath) * sizeof(WCHAR) + sizeof(UNICODE_NULL); if (ExpectedFilePartSize == sizeof(L"C:\\")) ExpectedFilePartSize = 0; else { BackSlash = wcsrchr(CurrentPath, L'\\'); if (BackSlash) ExpectedFilePartSize -= wcslen(BackSlash + 1) * sizeof(WCHAR); else ok(0, "GetCurrentDirectory returned %S\n", CurrentPath); } break; } default: skip(0, "Invalid test!\n"); continue; } ExpectedFilePartSize += TestCases[i].FilePartSize; if (ExpectedFilePartSize != 0) ExpectedFilePartSize = (ExpectedFilePartSize - sizeof(UNICODE_NULL)) / sizeof(WCHAR); ok(FilePartSize == ExpectedFilePartSize, "FilePartSize = %lu, expected %lu\n", (ULONG)FilePartSize, (ULONG)ExpectedFilePartSize); ok(NameInvalid == FALSE, "NameInvalid = %u\n", NameInvalid); ok(PathType == TestCases[i].PathType, "PathType = %d, expected %d\n", PathType, TestCases[i].PathType); ok(LengthNeeded == 0, "LengthNeeded = %lu\n", (ULONG)LengthNeeded); } }
void test_InProcess() { LARGE_INTEGER move; ULARGE_INTEGER size; HRESULT res; ULONG i; RTL_MEMORY_STREAM stream; RTL_MEMORY_STREAM previous; IStream * istream; UCHAR buffer[80]; UCHAR buffer2[180]; ULONG bytesRead; STATSTG stat; finalReleaseCallCount = 0; for (i = 0; i < sizeof(buffer2); i++) { buffer2[i] = i % UCHAR_MAX; } memset(&stream, 0x90, sizeof(stream)); memset(&previous, 0x00, sizeof(previous)); StartSeh() RtlInitMemoryStream(NULL); EndSeh(STATUS_ACCESS_VIOLATION); StartSeh() RtlInitMemoryStream(&stream); EndSeh(STATUS_SUCCESS); CompareStructsAndSaveForLater(&previous, &stream, "After init"); ok(stream.RefCount == 0, "RefCount has a wrong value: %d (expected %d).\n", stream.RefCount, 0); stream.Current = buffer2; stream.Start = buffer2; stream.End = buffer2 + sizeof(buffer2); stream.FinalRelease = CustomFinalReleaseMemoryStream; CompareStructsAndSaveForLater(&previous, &stream, "After assigning"); StartSeh() res = IStream_QueryInterface((struct IStream*)&stream, NULL, NULL); ok(res == E_INVALIDARG, "QueryInterface to IStream returned wrong hResult: 0x%08x.\n", res); ok(stream.RefCount == 0, "RefCount has a wrong value: %d (expected %d).\n", stream.RefCount, 2); EndSeh(STATUS_ACCESS_VIOLATION); StartSeh() res = IStream_QueryInterface((struct IStream*)&stream, &IID_IStream, NULL); ok(res == E_INVALIDARG, "QueryInterface to IStream returned wrong hResult: 0x%08x.\n", res); ok(stream.RefCount == 1, "RefCount has a wrong value: %d (expected %d).\n", stream.RefCount, 2); EndSeh(STATUS_ACCESS_VIOLATION); StartSeh() res = IStream_QueryInterface((struct IStream*)&stream, NULL, (void**)&istream); ok(res == E_INVALIDARG, "QueryInterface to IStream returned wrong hResult: 0x%08x.\n", res); ok(stream.RefCount == 1, "RefCount has a wrong value: %d (expected %d).\n", stream.RefCount, 2); EndSeh(STATUS_ACCESS_VIOLATION); StartSeh() res = IStream_QueryInterface((struct IStream*)&stream, &IID_IStream, (void**)&istream); ok(res == S_OK, "QueryInterface to IStream returned wrong hResult: 0x%08x.\n", res); ok(stream.RefCount == 2, "RefCount has a wrong value: %d (expected %d).\n", stream.RefCount, 2); EndSeh(STATUS_SUCCESS); CompareStructsAndSaveForLater(&previous, &stream, "After QueryInterface"); StartSeh() res = IStream_Stat(istream, NULL, 0); ok(res == STG_E_INVALIDPOINTER, "Stat to IStream returned wrong hResult: 0x%08x.\n", res); EndSeh(STATUS_SUCCESS); StartSeh() res = IStream_Stat(istream, &stat, STATFLAG_NONAME); ok(res == S_OK, "Stat to IStream returned wrong hResult: 0x%08x.\n", res); EndSeh(STATUS_SUCCESS); ok(stream.Current == buffer2, "stream.Current points to the wrong address 0x%p (expected 0x%p)\n", stream.Current, buffer2); ok(stream.Start == buffer2, "stream.Start was changed unexpectedly\n"); ok(stream.End == buffer2 + sizeof(buffer2), "stream.End was changed unexpectedly\n"); ok(stat.cbSize.QuadPart == ((PUCHAR)stream.End - (PUCHAR)stream.Start), "stat.cbSize has the wrong value %lld (expected %d)\n", stat.cbSize.QuadPart, (PUCHAR)stream.End - (PUCHAR)stream.Start); CompareStructsAndSaveForLater(&previous, &stream, "After Stat"); StartSeh() res = IStream_AddRef(istream); ok(res == 3, "AddRef to IStream returned wrong hResult: %d.\n", res); EndSeh(STATUS_SUCCESS); StartSeh() res = IStream_AddRef(istream); ok(res == 4, "AddRef to IStream returned wrong hResult: %d.\n", res); EndSeh(STATUS_SUCCESS); StartSeh() res = IStream_Release(istream); ok(res == 3, "Release to IStream returned wrong hResult: %d.\n", res); EndSeh(STATUS_SUCCESS); StartSeh() res = IStream_AddRef(istream); ok(res == 4, "AddRef to IStream returned wrong hResult: %d.\n", res); EndSeh(STATUS_SUCCESS); StartSeh() res = IStream_Release(istream); ok(res == 3, "Release to IStream returned wrong hResult: %d.\n", res); EndSeh(STATUS_SUCCESS); StartSeh() res = IStream_Release(istream); ok(res == 2, "Release to IStream returned wrong hResult: %d.\n", res); EndSeh(STATUS_SUCCESS); CompareStructsAndSaveForLater(&previous, &stream, "After AddRef"); StartSeh() res = IStream_Read(istream, NULL, 0, &bytesRead); ok(res == S_OK, "Read to IStream returned wrong hResult: 0x%08x.\n", res); EndSeh(STATUS_SUCCESS); StartSeh() res = IStream_Read(istream, buffer, 40, NULL); ok(res == S_OK, "Read to IStream returned wrong hResult: 0x%08x.\n", res); EndSeh(STATUS_ACCESS_VIOLATION); StartSeh() res = IStream_Read(istream, buffer + 40, 39, &bytesRead); ok(res == S_OK, "Read to IStream returned wrong hResult: 0x%08x.\n", res); EndSeh(STATUS_SUCCESS); if (SUCCEEDED(res)) { bytesRead += 40; for (i = 0; i < bytesRead; i++) { ok(buffer[i] == i, "Buffer[%d] contains a wrong number %d (expected %d).\n", i, buffer[i], i); } } ok(stream.Current == buffer2 + 79, "stream.Current points to the wrong address 0x%p (expected 0x%p)\n", stream.Current, buffer2); ok(stream.Start == buffer2, "stream.Start was changed unexpectedly\n"); ok(stream.End == buffer2 + sizeof(buffer2), "stream.End was changed unexpectedly\n"); CompareStructsAndSaveForLater(&previous, &stream, "After Read 1"); size.QuadPart = 0x9090909090909090ull; StartSeh() move.QuadPart = -1; res = IStream_Seek(istream, move, STREAM_SEEK_END, &size); ok(res == STG_E_INVALIDPOINTER, "Seek to IStream returned wrong hResult: 0x%08x.\n", res); ok(size.QuadPart == 0x9090909090909090ull, "Seek modified the new location in an error (0x%08x,0x%08x).\n", size.HighPart, size.LowPart); EndSeh(STATUS_SUCCESS); StartSeh() move.QuadPart = 0; res = IStream_Seek(istream, move, STREAM_SEEK_END, &size); ok(res == S_OK, "Seek to IStream returned wrong hResult: 0x%08x.\n", res); ok(size.QuadPart == (PUCHAR)stream.End - (PUCHAR)stream.Start, "Seek new location unexpected value: 0x%08x.\n", size.LowPart); EndSeh(STATUS_SUCCESS); size.QuadPart = 0x9090909090909090ull; StartSeh() move.QuadPart = 1; res = IStream_Seek(istream, move, STREAM_SEEK_END, &size); ok(res == S_OK, "Seek to IStream returned wrong hResult: 0x%08x.\n", res); ok(size.QuadPart == (PUCHAR)stream.End - (PUCHAR)stream.Start - 1, "Seek new location unexpected value: 0x%08x.\n", size.LowPart); EndSeh(STATUS_SUCCESS); size.QuadPart = 0x9090909090909090ull; StartSeh() move.QuadPart = 2; res = IStream_Seek(istream, move, STREAM_SEEK_END, &size); ok(res == S_OK, "Seek to IStream returned wrong hResult: 0x%08x.\n", res); ok(size.QuadPart == (PUCHAR)stream.End - (PUCHAR)stream.Start - 2, "Seek new location unexpected value: 0x%08x.\n", size.LowPart); EndSeh(STATUS_SUCCESS); size.QuadPart = 0x9090909090909090ull; StartSeh() move.QuadPart = -20; res = IStream_Seek(istream, move, STREAM_SEEK_SET, &size); ok(res == STG_E_INVALIDPOINTER, "Seek to IStream returned wrong hResult: 0x%08x.\n", res); ok(size.QuadPart == 0x9090909090909090ull, "Seek modified the new location in an error.\n"); EndSeh(STATUS_SUCCESS); StartSeh() move.QuadPart = 4000; res = IStream_Seek(istream, move, STREAM_SEEK_SET, &size); ok(res == STG_E_INVALIDPOINTER, "Seek to IStream returned wrong hResult: 0x%08x.\n", res); ok(size.QuadPart == 0x9090909090909090ull, "Seek modified the new location in an error.\n"); EndSeh(STATUS_SUCCESS); StartSeh() move.QuadPart = 0x100000000ull; res = IStream_Seek(istream, move, STREAM_SEEK_SET, &size); #ifdef _WIN64 ok(res == STG_E_INVALIDPOINTER, "Seek to IStream returned wrong hResult: 0x%08x.\n", res); ok(size.QuadPart == 0x9090909090909090ull, "Seek modified the new location in an error (0x%08x,0x%08x).\n", size.HighPart, size.LowPart); #else ok(res == S_OK, "Seek to IStream returned wrong hResult: 0x%08x.\n", res); ok(size.QuadPart == 0, "Seek new location unexpected value: 0x%08x.\n", size.LowPart); #endif EndSeh(STATUS_SUCCESS); #ifdef _WIN64 StartSeh() move.QuadPart = 0; res = IStream_Seek(istream, move, STREAM_SEEK_SET, &size); ok(res == S_OK, "Seek to IStream returned wrong hResult: 0x%08x.\n", res); ok(size.QuadPart == 0, "Seek new location unexpected value: 0x%08x.\n", size.LowPart); EndSeh(STATUS_SUCCESS); #endif size.QuadPart = 0x9090909090909090ull; StartSeh() move.QuadPart = -20; res = IStream_Seek(istream, move, STREAM_SEEK_CUR, &size); ok(res == STG_E_INVALIDPOINTER, "Seek to IStream returned wrong hResult: 0x%08x.\n", res); ok(size.QuadPart == 0x9090909090909090ull, "Seek modified the new location in an error (0x%08x,0x%08x).\n", size.HighPart, size.LowPart); EndSeh(STATUS_SUCCESS); StartSeh() move.QuadPart = 0x100000000ull; res = IStream_Seek(istream, move, STREAM_SEEK_CUR, &size); #ifdef _WIN64 ok(res == STG_E_INVALIDPOINTER, "Seek to IStream returned wrong hResult: 0x%08x.\n", res); ok(size.QuadPart == 0x9090909090909090ull, "Seek modified the new location in an error (0x%08x,0x%08x).\n", size.HighPart, size.LowPart); #else ok(res == S_OK, "Seek to IStream returned wrong hResult: 0x%08x.\n", res); ok(size.QuadPart == 0, "Seek new location unexpected value: 0x%08x.\n", size.LowPart); #endif EndSeh(STATUS_SUCCESS); StartSeh() move.QuadPart = 40; res = IStream_Seek(istream, move, STREAM_SEEK_SET, &size); ok(res == S_OK, "Seek to IStream returned wrong hResult: 0x%08x.\n", res); EndSeh(STATUS_SUCCESS); ok(size.QuadPart == 40, "Seek returned wrong offset %lld (expected %d)\n", size.QuadPart, 40); ok(stream.Current == buffer2 + 40, "stream.Current points to the wrong address 0x%p (expected 0x%p)\n", stream.Current, buffer2); ok(stream.Start == buffer2, "stream.Start was changed unexpectedly\n"); ok(stream.End == buffer2 + sizeof(buffer2), "stream.End was changed unexpectedly\n"); CompareStructsAndSaveForLater(&previous, &stream, "After Seek"); res = IStream_Read(istream, buffer, sizeof(buffer), &bytesRead); ok(res == S_OK, "Read to IStream returned wrong hResult: 0x%08x.\n", res); if (SUCCEEDED(res)) { for (i = 0; i < bytesRead; i++) { ok(buffer[i] == (i + 40), "Buffer[%d] contains a wrong number %d (expected %d).\n", i, buffer[i], i + 40); } } ok(stream.Current == buffer2 + 40 + sizeof(buffer), "stream.Current points to the wrong address 0x%p (expected 0x%p)\n", stream.Current, buffer2); ok(stream.Start == buffer2, "stream.Start was changed unexpectedly\n"); ok(stream.End == buffer2 + sizeof(buffer2), "stream.End was changed unexpectedly\n"); CompareStructsAndSaveForLater(&previous, &stream, "After Read 2"); res = IStream_Release(istream); ok(res == 1, "Release to IStream returned wrong hResult: 0x%08x.\n", res); ok(stream.RefCount == 1, "RefCount has a wrong value: %d (expected %d).\n", stream.RefCount, 1); res = IStream_Release(istream); ok(res == S_OK, "Release to IStream returned wrong hResult: 0x%08x.\n", res); ok(stream.RefCount == 0, "RefCount has a wrong value: %d (expected %d).\n", stream.RefCount, 0); ok(finalReleaseCallCount == 1, "FinalRelease was called %d times instead of 1.\n", finalReleaseCallCount); }
static VOID RunTestCases( PCWSTR CustomPath) { struct { PCWSTR SearchPath; PCWSTR FileName; PCWSTR Extension; PCWSTR ResultPath; PCWSTR ResultFileName; } Tests[] = { { L"", L"", NULL, NULL, NULL }, { L"C:\\%ls\\Folder1", L"File1", NULL, L"C:\\%ls\\Folder1\\", L"File1" }, /* No path: current directory */ { L"", L"File1", NULL, L"C:\\%ls\\CurrentDirectory\\", L"File1" }, /* Full path as FileName */ { L"", L"C:\\", NULL, L"C:\\", NULL }, { L"", L"C:\\%ls\\Folder1", NULL, L"C:\\%ls\\", L"Folder1" }, /* No FileName */ { L"C:\\", L"", NULL, L"C:\\", NULL }, { L"C:\\%ls\\Folder1", L"", NULL, L"C:\\%ls\\Folder1\\", NULL }, /* Full path as FileName */ { L"", L"C:\\%ls\\Folder1\\SomeProgram.exe", NULL, L"C:\\%ls\\Folder1\\", L"SomeProgram.exe" }, { L"", L"C:\\%ls\\Folder1\\SomeProgram.exe", L".exe", L"C:\\%ls\\Folder1\\", L"SomeProgram.exe" }, { L"", L"C:\\%ls\\Folder1\\SomeProgram", NULL, NULL, NULL }, // 10 { L"", L"C:\\%ls\\Folder1\\SomeProgram", L".exe", NULL, NULL }, /* Both SearchPath and FileName */ { L"C:\\%ls\\Folder1\\", L"SomeProgram.exe", NULL, L"C:\\%ls\\Folder1\\", L"SomeProgram.exe" }, { L"C:\\%ls\\Folder1\\", L"SomeProgram.exe", L".exe", L"C:\\%ls\\Folder1\\", L"SomeProgram.exe" }, { L"C:\\%ls\\Folder1\\", L"SomeProgram", NULL, NULL, NULL }, { L"C:\\%ls\\Folder1\\", L"SomeProgram", L".exe", L"C:\\%ls\\Folder1\\", L"SomeProgram.exe" }, { L"C:\\%ls\\Folder1", L"SomeProgram.exe", NULL, L"C:\\%ls\\Folder1\\", L"SomeProgram.exe" }, { L"C:\\%ls\\Folder1", L"SomeProgram.exe", L".exe", L"C:\\%ls\\Folder1\\", L"SomeProgram.exe" }, { L"C:\\%ls\\Folder1", L"SomeProgram", NULL, NULL, NULL }, { L"C:\\%ls\\Folder1", L"SomeProgram", L".exe", L"C:\\%ls\\Folder1\\", L"SomeProgram.exe" }, /* Full path to file in SearchPath doesn't work */ { L"C:\\%ls\\Folder1\\SomeProgram.exe", L"", NULL, NULL, NULL }, // 20 { L"C:\\%ls\\Folder1\\SomeProgram.exe", L"", L".exe", NULL, NULL }, { L"C:\\%ls\\Folder1\\SomeProgram", L"", NULL, NULL, NULL }, { L"C:\\%ls\\Folder1\\SomeProgram", L"", L".exe", NULL, NULL }, /* */ { L"C:\\%ls\\Folder1", L"File1", NULL, L"C:\\%ls\\Folder1\\", L"File1" }, { L"C:\\%ls\\CurrentDirectory", L"File1", NULL, L"C:\\%ls\\CurrentDirectory\\", L"File1" }, { L"C:\\%ls\\Folder1 ", L"File1", NULL, NULL, NULL }, { L"C:\\%ls\\CurrentDirectory ",L"File1", NULL, NULL, NULL }, { L" C:\\%ls\\Folder1", L"File1", NULL, NULL, NULL }, { L" C:\\%ls\\CurrentDirectory",L"File1", NULL, NULL, NULL }, { L" C:\\%ls\\Folder1 ", L"File1", NULL, NULL, NULL }, // 30 { L" C:\\%ls\\CurrentDirectory ",L"File1", NULL, NULL, NULL }, /* Multiple search paths */ { L"C:\\%ls\\Folder1;C:\\%ls\\CurrentDirectory", L"File1", NULL, L"C:\\%ls\\Folder1\\", L"File1" }, { L"C:\\%ls\\CurrentDirectory;C:\\%ls\\Folder1", L"File1", NULL, L"C:\\%ls\\CurrentDirectory\\", L"File1" }, { L"C:\\%ls\\CurrentDirectory ; C:\\%ls\\Folder1", L"File1", NULL, NULL, NULL }, { L"C:\\%ls\\CurrentDirectory ;C:\\%ls\\Folder1", L"File1", NULL, L"C:\\%ls\\Folder1\\", L"File1" }, { L"C:\\%ls\\CurrentDirectory; C:\\%ls\\Folder1", L"File1", NULL, L"C:\\%ls\\CurrentDirectory\\", L"File1" }, { L";C:\\%ls\\Folder1", L"File1", NULL, L"C:\\%ls\\CurrentDirectory\\", L"File1" }, { L";C:\\%ls\\Folder1;", L"File1", NULL, L"C:\\%ls\\CurrentDirectory\\", L"File1" }, { L";C:\\%ls\\Folder1;", L"File1", NULL, L"C:\\%ls\\CurrentDirectory\\", L"File1" }, { L"C:\\%ls\\Folder1", L"OnlyInCurr", NULL, NULL, NULL }, // 40 { L"", L"OnlyInCurr", NULL, L"C:\\%ls\\CurrentDirectory\\", L"OnlyInCurr" }, { L"", L"OnlyInCurr ", NULL, L"C:\\%ls\\CurrentDirectory\\", L"OnlyInCurr" }, { L"", L" OnlyInCurr", NULL, NULL, NULL }, { L" ", L"OnlyInCurr", NULL, NULL, NULL }, { L";", L"OnlyInCurr", NULL, L"C:\\%ls\\CurrentDirectory\\", L"OnlyInCurr" }, { L"; ", L"OnlyInCurr", NULL, L"C:\\%ls\\CurrentDirectory\\", L"OnlyInCurr" }, { L" ;", L"OnlyInCurr", NULL, NULL, NULL }, { L" ; ", L"OnlyInCurr", NULL, NULL, NULL }, { L";C:\\%ls\\Folder1", L"OnlyInCurr", NULL, L"C:\\%ls\\CurrentDirectory\\", L"OnlyInCurr" }, { L"C:\\%ls\\Folder1;", L"OnlyInCurr", NULL, NULL, NULL }, // 50 { L"C:\\%ls\\Folder1;;", L"OnlyInCurr", NULL, L"C:\\%ls\\CurrentDirectory\\", L"OnlyInCurr" }, { L";C:\\%ls\\Folder1;", L"OnlyInCurr", NULL, L"C:\\%ls\\CurrentDirectory\\", L"OnlyInCurr" }, { L"C:\\%ls\\Folder1;C:\\%ls\\Folder2", L"OnlyInCurr", NULL, NULL, NULL }, { L";C:\\%ls\\Folder1;C:\\%ls\\Folder2", L"OnlyInCurr", NULL, L"C:\\%ls\\CurrentDirectory\\", L"OnlyInCurr" }, { L"C:\\%ls\\Folder1;;C:\\%ls\\Folder2", L"OnlyInCurr", NULL, L"C:\\%ls\\CurrentDirectory\\", L"OnlyInCurr" }, { L"C:\\%ls\\Folder1;C:\\%ls\\Folder2;", L"OnlyInCurr", NULL, NULL, NULL }, { L"C:\\%ls\\Folder1;C:\\%ls\\Folder2;;", L"OnlyInCurr", NULL, L"C:\\%ls\\CurrentDirectory\\", L"OnlyInCurr" }, /* Spaces in FileName! */ { L"", L"C:\\%ls\\Folder1\\SomeProgram With Spaces", L".exe", NULL, NULL }, { L"", L"C:\\%ls\\Folder1\\SomeProgram With Spaces.exe", L".exe", NULL, NULL }, { L"", L"C:\\%ls\\Folder1\\Program", L".exe", NULL, NULL }, // 60 { L"", L"C:\\%ls\\Folder1\\Program.exe", L".exe", L"C:\\%ls\\Folder1\\", L"Program.exe" }, { L"", L"C:\\%ls\\Folder1\\Program With", L".exe", NULL, NULL }, { L"", L"C:\\%ls\\Folder1\\Program With.exe", L".exe", L"C:\\%ls\\Folder1\\", L"Program With.exe" }, { L"", L"C:\\%ls\\Folder1\\Program With Spaces",L".exe", NULL, NULL }, { L"", L"C:\\%ls\\Folder1\\Program With Spaces.exe", L".exe", L"C:\\%ls\\Folder1\\", L"Program With Spaces.exe" }, /* Same tests with path in SearchPath - now extensions are appended */ { L"C:\\%ls\\Folder1", L"SomeProgram With Spaces", L".exe", NULL, NULL }, { L"C:\\%ls\\Folder1", L"SomeProgram With Spaces.exe", L".exe", NULL, NULL }, { L"C:\\%ls\\Folder1", L"Program", L".exe", L"C:\\%ls\\Folder1\\", L"Program.exe" }, { L"C:\\%ls\\Folder1", L"Program.exe", L".exe", L"C:\\%ls\\Folder1\\", L"Program.exe" }, { L"C:\\%ls\\Folder1", L"Program With", L".exe", L"C:\\%ls\\Folder1\\", L"Program With.exe" }, // 70 { L"C:\\%ls\\Folder1", L"Program With.exe", L".exe", L"C:\\%ls\\Folder1\\", L"Program With.exe" }, { L"C:\\%ls\\Folder1", L"Program With Spaces", L".exe", L"C:\\%ls\\Folder1\\", L"Program With Spaces.exe" }, { L"C:\\%ls\\Folder1", L"Program With Spaces.exe", L".exe", L"C:\\%ls\\Folder1\\", L"Program With Spaces.exe" }, }; ULONG i; ULONG Length; PWSTR PartName; WCHAR SearchPath[MAX_PATH]; WCHAR FileName[MAX_PATH]; WCHAR ResultPath[MAX_PATH]; WCHAR Buffer[MAX_PATH]; BOOLEAN Okay; for (i = 0; i < sizeof(Tests) / sizeof(Tests[0]); i++) { swprintf(SearchPath, Tests[i].SearchPath, CustomPath, CustomPath, CustomPath, CustomPath); swprintf(FileName, Tests[i].FileName, CustomPath, CustomPath, CustomPath, CustomPath); RtlFillMemory(Buffer, sizeof(Buffer), 0x55); PartName = InvalidPointer; StartSeh() Length = RtlDosSearchPath_U(SearchPath, FileName, Tests[i].Extension, sizeof(Buffer), Buffer, &PartName); EndSeh(STATUS_SUCCESS); if (Tests[i].ResultPath) { swprintf(ResultPath, Tests[i].ResultPath, CustomPath, CustomPath, CustomPath, CustomPath); if (Tests[i].ResultFileName) { ok(PartName == &Buffer[wcslen(ResultPath)], "PartName = %p (%ls), expected %p\n", PartName, PrintablePointer(PartName), &Buffer[wcslen(ResultPath)]); wcscat(ResultPath, Tests[i].ResultFileName); } else { ok(PartName == NULL, "PartName = %p (%ls), expected NULL\n", PartName, PrintablePointer(PartName)); } Okay = CheckStringBuffer(Buffer, Length, sizeof(Buffer), ResultPath); ok(Okay == TRUE, "CheckStringBuffer failed. Got '%ls', expected '%ls'\n", Buffer, ResultPath); } else { Okay = CheckBuffer(Buffer, sizeof(Buffer), 0x55); ok(Okay == TRUE, "CheckBuffer failed\n"); ok(Length == 0, "Length = %lu\n", Length); ok(PartName == InvalidPointer, "PartName = %p (%ls), expected %p\n", PartName, PrintablePointer(PartName), InvalidPointer); } } }
static VOID RunTestCases(VOID) { /* TODO: don't duplicate this in the other tests */ /* TODO: Drive Relative tests don't work yet if the current drive isn't C: */ struct { PCWSTR FileName; PREFIX_TYPE PrefixType; PCWSTR FullPathName; PREFIX_TYPE FilePartPrefixType; SIZE_T FilePartSize; } TestCases[] = { { L"C:", PrefixCurrentPath, L"", PrefixCurrentPathWithoutLastPart }, { L"C:\\", PrefixNone, L"C:\\" }, { L"C:\\test", PrefixNone, L"C:\\test", PrefixCurrentDrive }, { L"C:\\test\\", PrefixNone, L"C:\\test\\" }, { L"C:/test/", PrefixNone, L"C:\\test\\" }, { L"C:\\\\test", PrefixNone, L"C:\\test", PrefixCurrentDrive }, { L"test", PrefixCurrentPath, L"\\test", PrefixCurrentPath, sizeof(WCHAR) }, { L"\\test", PrefixCurrentDrive, L"test", PrefixCurrentDrive }, { L"/test", PrefixCurrentDrive, L"test", PrefixCurrentDrive }, { L".\\test", PrefixCurrentPath, L"\\test", PrefixCurrentPath, sizeof(WCHAR) }, { L"\\.", PrefixCurrentDrive, L"" }, { L"\\.\\", PrefixCurrentDrive, L"" }, { L"\\\\.", PrefixNone, L"\\\\.\\" }, { L"\\\\.\\", PrefixNone, L"\\\\.\\" }, { L"\\\\.\\Something\\", PrefixNone, L"\\\\.\\Something\\" }, { L"\\??\\", PrefixCurrentDrive, L"??\\" }, { L"\\??\\C:", PrefixCurrentDrive, L"??\\C:", PrefixCurrentDrive, 3 * sizeof(WCHAR) }, { L"\\??\\C:\\", PrefixCurrentDrive, L"??\\C:\\" }, { L"\\??\\C:\\test", PrefixCurrentDrive, L"??\\C:\\test", PrefixCurrentDrive, 6 * sizeof(WCHAR) }, { L"\\??\\C:\\test\\", PrefixCurrentDrive, L"??\\C:\\test\\" }, { L"\\\\??\\", PrefixNone, L"\\\\??\\" }, { L"\\\\??\\C:", PrefixNone, L"\\\\??\\C:" }, { L"\\\\??\\C:\\", PrefixNone, L"\\\\??\\C:\\" }, { L"\\\\??\\C:\\test", PrefixNone, L"\\\\??\\C:\\test", PrefixNone, sizeof(L"\\\\??\\C:\\") }, { L"\\\\??\\C:\\test\\", PrefixNone, L"\\\\??\\C:\\test\\" }, }; WCHAR FullPathNameBuffer[MAX_PATH]; PWSTR ShortName; SIZE_T Length; WCHAR ExpectedPathName[MAX_PATH]; SIZE_T FilePartSize; SIZE_T ExpectedFilePartSize; const INT TestCount = sizeof(TestCases) / sizeof(TestCases[0]); INT i; BOOLEAN Okay; for (i = 0; i < TestCount; i++) { trace("i = %d\n", i); switch (TestCases[i].PrefixType) { case PrefixNone: ExpectedPathName[0] = UNICODE_NULL; break; case PrefixCurrentDrive: GetCurrentDirectoryW(sizeof(ExpectedPathName) / sizeof(WCHAR), ExpectedPathName); ExpectedPathName[3] = UNICODE_NULL; break; case PrefixCurrentPath: Length = GetCurrentDirectoryW(sizeof(ExpectedPathName) / sizeof(WCHAR), ExpectedPathName); if (Length == 3 && TestCases[i].FullPathName[0]) ExpectedPathName[2] = UNICODE_NULL; break; default: skip(0, "Invalid test!\n"); continue; } wcscat(ExpectedPathName, TestCases[i].FullPathName); RtlFillMemory(FullPathNameBuffer, sizeof(FullPathNameBuffer), 0xAA); Length = 0; StartSeh() Length = RtlGetFullPathName_U(TestCases[i].FileName, sizeof(FullPathNameBuffer), FullPathNameBuffer, &ShortName); EndSeh(STATUS_SUCCESS); Okay = CheckStringBuffer(FullPathNameBuffer, Length, sizeof(FullPathNameBuffer), ExpectedPathName); ok(Okay, "Wrong path name '%S', expected '%S'\n", FullPathNameBuffer, ExpectedPathName); if (!ShortName) FilePartSize = 0; else FilePartSize = ShortName - FullPathNameBuffer; switch (TestCases[i].FilePartPrefixType) { case PrefixNone: ExpectedFilePartSize = 0; break; case PrefixCurrentDrive: ExpectedFilePartSize = sizeof(L"C:\\"); break; case PrefixCurrentPath: ExpectedFilePartSize = GetCurrentDirectoryW(0, NULL) * sizeof(WCHAR); if (ExpectedFilePartSize == sizeof(L"C:\\")) ExpectedFilePartSize -= sizeof(WCHAR); break; case PrefixCurrentPathWithoutLastPart: { WCHAR CurrentPath[MAX_PATH]; PCWSTR BackSlash; ExpectedFilePartSize = GetCurrentDirectoryW(sizeof(CurrentPath) / sizeof(WCHAR), CurrentPath) * sizeof(WCHAR) + sizeof(UNICODE_NULL); if (ExpectedFilePartSize == sizeof(L"C:\\")) ExpectedFilePartSize = 0; else { BackSlash = wcsrchr(CurrentPath, L'\\'); if (BackSlash) ExpectedFilePartSize -= wcslen(BackSlash + 1) * sizeof(WCHAR); else ok(0, "GetCurrentDirectory returned %S\n", CurrentPath); } break; } default: skip(0, "Invalid test!\n"); continue; } ExpectedFilePartSize += TestCases[i].FilePartSize; if (ExpectedFilePartSize != 0) ExpectedFilePartSize = (ExpectedFilePartSize - sizeof(UNICODE_NULL)) / sizeof(WCHAR); ok(FilePartSize == ExpectedFilePartSize, "FilePartSize = %lu, expected %lu\n", (ULONG)FilePartSize, (ULONG)ExpectedFilePartSize); } }
static VOID RunTestCases(VOID) { /* TODO: don't duplicate this in the other tests */ /* TODO: Drive Relative tests don't work yet if the current drive isn't C: */ struct { PCWSTR FileName; PREFIX_TYPE PrefixType; PCWSTR FullPathName; RTL_PATH_TYPE PathType; PREFIX_TYPE FilePartPrefixType; SIZE_T FilePartSize; } TestCases[] = { { L"C:", PrefixCurrentPath, L"", RtlPathTypeDriveRelative, PrefixCurrentPathWithoutLastPart }, { L"C:\\", PrefixNone, L"C:\\", RtlPathTypeDriveAbsolute }, { L"C:\\test", PrefixNone, L"C:\\test", RtlPathTypeDriveAbsolute, PrefixCurrentDrive }, { L"C:\\test\\", PrefixNone, L"C:\\test\\", RtlPathTypeDriveAbsolute }, { L"C:/test/", PrefixNone, L"C:\\test\\", RtlPathTypeDriveAbsolute }, { L"C:\\\\test", PrefixNone, L"C:\\test", RtlPathTypeDriveAbsolute, PrefixCurrentDrive }, { L"test", PrefixCurrentPath, L"\\test", RtlPathTypeRelative, PrefixCurrentPath, sizeof(WCHAR) }, { L"\\test", PrefixCurrentDrive, L"test", RtlPathTypeRooted, PrefixCurrentDrive }, { L"/test", PrefixCurrentDrive, L"test", RtlPathTypeRooted, PrefixCurrentDrive }, { L".\\test", PrefixCurrentPath, L"\\test", RtlPathTypeRelative, PrefixCurrentPath, sizeof(WCHAR) }, { L"\\.", PrefixCurrentDrive, L"", RtlPathTypeRooted }, { L"\\.\\", PrefixCurrentDrive, L"", RtlPathTypeRooted }, { L"\\\\.", PrefixNone, L"\\\\.\\", RtlPathTypeRootLocalDevice }, { L"\\\\.\\", PrefixNone, L"\\\\.\\", RtlPathTypeLocalDevice }, { L"\\\\.\\Something\\", PrefixNone, L"\\\\.\\Something\\", RtlPathTypeLocalDevice }, { L"\\??\\", PrefixCurrentDrive, L"??\\", RtlPathTypeRooted }, { L"\\??\\C:", PrefixCurrentDrive, L"??\\C:", RtlPathTypeRooted, PrefixCurrentDrive, 3 * sizeof(WCHAR) }, { L"\\??\\C:\\", PrefixCurrentDrive, L"??\\C:\\", RtlPathTypeRooted }, { L"\\??\\C:\\test", PrefixCurrentDrive, L"??\\C:\\test", RtlPathTypeRooted, PrefixCurrentDrive, 6 * sizeof(WCHAR) }, { L"\\??\\C:\\test\\", PrefixCurrentDrive, L"??\\C:\\test\\", RtlPathTypeRooted }, { L"\\\\??\\", PrefixNone, L"\\\\??\\", RtlPathTypeUncAbsolute }, { L"\\\\??\\C:", PrefixNone, L"\\\\??\\C:", RtlPathTypeUncAbsolute }, { L"\\\\??\\C:\\", PrefixNone, L"\\\\??\\C:\\", RtlPathTypeUncAbsolute }, { L"\\\\??\\C:\\test", PrefixNone, L"\\\\??\\C:\\test", RtlPathTypeUncAbsolute, PrefixNone, sizeof(L"\\\\??\\C:\\") }, { L"\\\\??\\C:\\test\\", PrefixNone, L"\\\\??\\C:\\test\\", RtlPathTypeUncAbsolute }, }; ULONG Length; UNICODE_STRING FileName; WCHAR FullPathNameBuffer[MAX_PATH]; UNICODE_STRING TempString; const WCHAR *ShortName; BOOLEAN NameInvalid; PATH_TYPE_AND_UNKNOWN PathType; WCHAR ExpectedPathName[MAX_PATH]; SIZE_T ExpectedFilePartSize; const WCHAR *ExpectedShortName; const INT TestCount = sizeof(TestCases) / sizeof(TestCases[0]); INT i; BOOLEAN Okay; for (i = 0; i < TestCount; i++) { trace("i = %d\n", i); switch (TestCases[i].PrefixType) { case PrefixNone: ExpectedPathName[0] = UNICODE_NULL; break; case PrefixCurrentDrive: GetCurrentDirectoryW(sizeof(ExpectedPathName) / sizeof(WCHAR), ExpectedPathName); ExpectedPathName[3] = UNICODE_NULL; break; case PrefixCurrentPath: { ULONG Length; Length = GetCurrentDirectoryW(sizeof(ExpectedPathName) / sizeof(WCHAR), ExpectedPathName); if (Length == 3 && TestCases[i].FullPathName[0]) ExpectedPathName[2] = UNICODE_NULL; break; } default: skip("Invalid test!\n"); continue; } wcscat(ExpectedPathName, TestCases[i].FullPathName); RtlInitUnicodeString(&FileName, TestCases[i].FileName); RtlFillMemory(FullPathNameBuffer, sizeof(FullPathNameBuffer), 0xAA); TempString = FileName; PathType.Type = RtlPathTypeNotSet; PathType.Unknown = 1234; ShortName = InvalidPointer; NameInvalid = (BOOLEAN)-1; Length = 1234; StartSeh() Length = RtlGetFullPathName_Ustr(&FileName, sizeof(FullPathNameBuffer), FullPathNameBuffer, &ShortName, &NameInvalid, &PathType); EndSeh(STATUS_SUCCESS); ok_eq_ustr(&FileName, &TempString); Okay = CheckStringBuffer(FullPathNameBuffer, Length, sizeof(FullPathNameBuffer), ExpectedPathName); ok(Okay, "Wrong path name '%S', expected '%S'\n", FullPathNameBuffer, ExpectedPathName); switch (TestCases[i].FilePartPrefixType) { case PrefixNone: ExpectedFilePartSize = 0; break; case PrefixCurrentDrive: ExpectedFilePartSize = sizeof(L"C:\\"); break; case PrefixCurrentPath: ExpectedFilePartSize = GetCurrentDirectoryW(0, NULL) * sizeof(WCHAR); if (ExpectedFilePartSize == sizeof(L"C:\\")) ExpectedFilePartSize -= sizeof(WCHAR); break; case PrefixCurrentPathWithoutLastPart: { WCHAR CurrentPath[MAX_PATH]; PCWSTR BackSlash; ExpectedFilePartSize = GetCurrentDirectoryW(sizeof(CurrentPath) / sizeof(WCHAR), CurrentPath) * sizeof(WCHAR) + sizeof(UNICODE_NULL); if (ExpectedFilePartSize == sizeof(L"C:\\")) ExpectedFilePartSize = 0; else { BackSlash = wcsrchr(CurrentPath, L'\\'); if (BackSlash) ExpectedFilePartSize -= wcslen(BackSlash + 1) * sizeof(WCHAR); else ok(0, "GetCurrentDirectory returned %S\n", CurrentPath); } break; } default: skip("Invalid test!\n"); continue; } ExpectedFilePartSize += TestCases[i].FilePartSize; if (ExpectedFilePartSize == 0) { ExpectedShortName = NULL; } else { ExpectedFilePartSize = (ExpectedFilePartSize - sizeof(UNICODE_NULL)) / sizeof(WCHAR); ExpectedShortName = FullPathNameBuffer + ExpectedFilePartSize; } ok(ShortName == ExpectedShortName, "ShortName = %p, expected %p\n", ShortName, ExpectedShortName); ok(NameInvalid == FALSE, "NameInvalid = %u\n", NameInvalid); ok(PathType.Type == TestCases[i].PathType, "PathType = %d, expected %d\n", PathType.Type, TestCases[i].PathType); ok(PathType.Unknown == 1234 || broken(PathType.Unknown == 0) || broken(PathType.Unknown == 32), "Unknown = %lu\n", PathType.Unknown); } }
/* * Tests for NhGetInterfaceNameFromGuid */ static VOID test_NhGetInterfaceNameFromGuid(GUID AdapterGUID, DWORD par1, DWORD par2) { DWORD ApiReturn, Error; ULONG ulOutBufLen; WCHAR Name[MAX_INTERFACE_NAME_LEN + 4]; GUID UniqueGUID = MY_TEST_GUID; // Test NULL GUID SetLastError(0xbeeffeed); Error = 0xbeeffeed; ZeroMemory(&Name, sizeof(Name)); ApiReturn = ERROR_SUCCESS; ulOutBufLen = sizeof(Name); StartSeh() ApiReturn = pNhGetInterfaceNameFromGuid(NULL, &Name, &ulOutBufLen, par1, par2); Error = GetLastError(); EndSeh(STATUS_SUCCESS); ok(ApiReturn == ERROR_INVALID_PARAMETER, "ApiReturn returned %ld, expected ERROR_INVALID_PARAMETER\n", ApiReturn); ok(Error == 0xbeeffeed, "GetLastError() returned %ld, expected 0xbeeffeed\n", Error); ok(ulOutBufLen == sizeof(Name), "ulOutBufLen is %ld, expected = sizeof(Name)\n", ulOutBufLen); ok_wstr(L"", Name); // Test correct GUID, but NULL name SetLastError(0xbeeffeed); ZeroMemory(&Name, sizeof(Name)); ApiReturn = pNhGetInterfaceNameFromGuid(&AdapterGUID, NULL, &ulOutBufLen, par1, par2); Error = GetLastError(); ok(ApiReturn == ERROR_SUCCESS, "ApiReturn returned %ld, expected ERROR_SUCCESS\n", ApiReturn); ok(Error == 0xbeeffeed, "GetLastError() returned %ld, expected 0xbeeffeed\n", Error); ok(ulOutBufLen > 0, "ulOutBufLen is %ld, expected > 0\n", ulOutBufLen); ok_wstr(L"", Name); // NhGetInterfaceNameFromGuid will throw exception if pOutBufLen is NULL SetLastError(0xbeeffeed); Error = 0xbeeffeed; ZeroMemory(&Name, sizeof(Name)); ApiReturn = ERROR_SUCCESS; StartSeh() ApiReturn = pNhGetInterfaceNameFromGuid(&AdapterGUID, &Name, NULL, par1, par2); Error = GetLastError(); EndSeh(STATUS_SUCCESS); ok(ApiReturn == ERROR_INVALID_PARAMETER, "ApiReturn returned %ld, expected ERROR_INVALID_PARAMETER\n", ApiReturn); ok(Error == 0xbeeffeed, "GetLastError() returned %ld, expected 0xbeeffeed\n", Error); ok(ulOutBufLen > 0, "ulOutBufLen is %ld, expected > 0\n", ulOutBufLen); ok_wstr(L"", Name); // Test correct values SetLastError(0xbeeffeed); ZeroMemory(&Name, sizeof(Name)); ulOutBufLen = sizeof(Name); ApiReturn = pNhGetInterfaceNameFromGuid(&AdapterGUID, &Name, &ulOutBufLen, par1, par2); Error = GetLastError(); ok(ApiReturn == ERROR_SUCCESS, "ApiReturn returned %ld, expected ERROR_SUCCESS\n", ApiReturn); ok(Error == 0xbeeffeed, "GetLastError() returned %ld, expected 0xbeeffeed\n", Error); ok(ulOutBufLen > 0, "ulOutBufLen is %ld, expected > 0\n", ulOutBufLen); Error = wcslen(Name); ok(Error > 0, "wcslen(Name) is %ld, expected > 0\n", Error); if (Error > 0) trace("Adapter name: \"%S\"\n", Name); // Test correct values, but with new unique GUID SetLastError(0xbeeffeed); ZeroMemory(&Name, sizeof(Name)); ulOutBufLen = sizeof(Name); ApiReturn = pNhGetInterfaceNameFromGuid((PVOID)&UniqueGUID, &Name, &ulOutBufLen, par1, par2); Error = GetLastError(); ok(ApiReturn == ERROR_NOT_FOUND, "ApiReturn returned %ld, expected ERROR_NOT_FOUND\n", ApiReturn); ok(Error == ERROR_PATH_NOT_FOUND, "GetLastError() returned %ld, expected ERROR_PATH_NOT_FOUND\n", Error); ok(ulOutBufLen == sizeof(Name), "ulOutBufLen is %ld, expected = sizeof(Name)\n", ulOutBufLen); ok_wstr(L"", Name); // Test correct values, but with small length SetLastError(0xbeeffeed); ZeroMemory(&Name, sizeof(Name)); ulOutBufLen = 0; ApiReturn = pNhGetInterfaceNameFromGuid(&AdapterGUID, &Name, &ulOutBufLen, par1, par2); Error = GetLastError(); ok(ApiReturn == ERROR_INSUFFICIENT_BUFFER, "ApiReturn returned %ld, expected ERROR_INSUFFICIENT_BUFFER\n", ApiReturn); ok(Error == 0xbeeffeed, "GetLastError() returned %ld, expected 0xbeeffeed\n", Error); ok(ulOutBufLen == MAX_INTERFACE_NAME_LEN * 2, "ulOutBufLen is %ld, expected = MAX_INTERFACE_NAME_LEN * 2\n", ulOutBufLen); ok_wstr(L"", Name); }
static VOID TestNodeName(VOID) { int Error; PADDRINFOA AddrInfo; ADDRINFOA Hints; struct { PCSTR NodeName; PCSTR ExpectedAddress; INT Flags; } Tests[] = { { "", LocalAddress }, { " ", NULL }, { "doesntexist.reactos.org", NULL }, { "localhost", "127.0.0.1" }, { "localhost:80", NULL }, { "7.8.9.10", "7.8.9.10", AI_NUMERICHOST }, { "0.0.0.0", "0.0.0.0", AI_NUMERICHOST }, { "255.255.255.255", "255.255.255.255", AI_NUMERICHOST }, { "0.0.0.0 ", "0.0.0.0", /* no AI_NUMERICHOST */ }, { "0.0.0.0:80", NULL }, { "0.0.0.0.0", NULL }, { "1.1.1.256", NULL }, { "1.2.3", NULL }, { "1.2.3.0x4", "1.2.3.4", AI_NUMERICHOST }, { "1.2.3.010", "1.2.3.8", AI_NUMERICHOST }, /* let's just assume this one doesn't change any time soon ;) */ { "google-public-dns-a.google.com", "8.8.8.8" }, }; const INT TestCount = sizeof(Tests) / sizeof(Tests[0]); INT i; /* make sure we don't get IPv6 responses */ ZeroMemory(&Hints, sizeof(Hints)); Hints.ai_family = AF_INET; trace("Nodes\n"); for (i = 0; i < TestCount; i++) { trace("%d: '%s'\n", i, Tests[i].NodeName); StartSeh() AddrInfo = InvalidPointer; Error = getaddrinfo(Tests[i].NodeName, NULL, &Hints, &AddrInfo); if (Tests[i].ExpectedAddress) { ok_dec(Error, 0); ok_dec(WSAGetLastError(), 0); ok(AddrInfo != NULL && AddrInfo != InvalidPointer, "AddrInfo = %p\n", AddrInfo); } else { ok_dec(Error, WSAHOST_NOT_FOUND); ok_dec(WSAGetLastError(), WSAHOST_NOT_FOUND); ok_ptr(AddrInfo, NULL); } if (!Error && AddrInfo && AddrInfo != InvalidPointer) { ok_addrinfo(AddrInfo, Tests[i].Flags, AF_INET, 0, 0, sizeof(SOCKADDR_IN)); ok_ptr(AddrInfo->ai_canonname, NULL); ok_sockaddr_in(AddrInfo->ai_addr, AF_INET, 0, Tests[i].ExpectedAddress); ok_ptr(AddrInfo->ai_next, NULL); freeaddrinfo(AddrInfo); } EndSeh(STATUS_SUCCESS); } }
static VOID TestServiceName(VOID) { int Error; PADDRINFOA AddrInfo; ADDRINFOA Hints; struct { PCSTR ServiceName; INT ExpectedPort; INT SockType; } Tests[] = { { "", 0 }, { "0", 0 }, { "1", 1 }, { "a", -1 }, { "010", 10 }, { "0x1a", -1 }, { "http", 80, SOCK_STREAM }, { "smtp", 25, SOCK_STREAM }, { "mail", 25, SOCK_STREAM }, /* alias for smtp */ { "router", 520, SOCK_DGRAM }, { "domain", 53, 0 /* DNS supports both UDP and TCP */ }, { ":0", -1 }, { "123", 123 }, { " 123", 123 }, { " 123", 123 }, { "32767", 32767 }, { "32768", 32768 }, { "65535", 65535 }, { "65536", 0 }, { "65537", 1 }, { "65540", 4 }, { "65536", 0 }, { "4294967295", 65535 }, { "4294967296", 65535 }, { "9999999999", 65535 }, { "999999999999999999999999999999999999", 65535 }, { "+5", 5 }, { "-1", 65535 }, { "-4", 65532 }, { "-65534", 2 }, { "-65535", 1 }, { "-65536", 0 }, { "-65537", 65535 }, { "28a", -1 }, { "28 ", -1 }, { "a28", -1 }, }; const INT TestCount = sizeof(Tests) / sizeof(Tests[0]); INT i; /* make sure we don't get IPv6 responses */ ZeroMemory(&Hints, sizeof(Hints)); Hints.ai_family = AF_INET; trace("Services\n"); for (i = 0; i < TestCount; i++) { trace("%d: '%s'\n", i, Tests[i].ServiceName); StartSeh() AddrInfo = InvalidPointer; Error = getaddrinfo(NULL, Tests[i].ServiceName, &Hints, &AddrInfo); if (Tests[i].ExpectedPort != -1) { ok_dec(Error, 0); ok_dec(WSAGetLastError(), 0); ok(AddrInfo != NULL && AddrInfo != InvalidPointer, "AddrInfo = %p\n", AddrInfo); } else { ok_dec(Error, WSATYPE_NOT_FOUND); ok_dec(WSAGetLastError(), WSATYPE_NOT_FOUND); ok_ptr(AddrInfo, NULL); } if (!Error && AddrInfo && AddrInfo != InvalidPointer) { ok_addrinfo(AddrInfo, 0, AF_INET, Tests[i].SockType, 0, sizeof(SOCKADDR_IN)); ok_ptr(AddrInfo->ai_canonname, NULL); ok_sockaddr_in(AddrInfo->ai_addr, AF_INET, Tests[i].ExpectedPort, "127.0.0.1"); ok_ptr(AddrInfo->ai_next, NULL); freeaddrinfo(AddrInfo); } EndSeh(STATUS_SUCCESS); } }