diff --git a/dlls/shlwapi/tests/path.c b/dlls/shlwapi/tests/path.c index 6c116c9617e..e931d819bdf 100644 --- a/dlls/shlwapi/tests/path.c +++ b/dlls/shlwapi/tests/path.c @@ -1072,6 +1072,68 @@ static void test_PathCombineA(void) ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n", GetLastError()); } +static void test_PathAddBackslash(void) +{ + LPSTR str; + char path[MAX_PATH]; + char too_long[LONG_LEN]; + + /* try a NULL path */ + SetLastError(0xdeadbeef); + str = PathAddBackslashA(NULL); + ok(str == NULL, "Expected str == NULL, got %p\n", str); + ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n", GetLastError()); + + /* try an empty path */ + path[0] = '\0'; + SetLastError(0xdeadbeef); + str = PathAddBackslashA(path); + ok(str == (path + lstrlenA(path)), "Expected str to point to end of path, got %p\n", str); + ok(lstrlenA(path) == 0, "Expected empty string, got %i\n", lstrlenA(path)); + ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n", GetLastError()); + + /* try a relative path */ + lstrcpyA(path, "one\\two"); + SetLastError(0xdeadbeef); + str = PathAddBackslashA(path); + ok(str == (path + lstrlenA(path)), "Expected str to point to end of path, got %p\n", str); + ok(!lstrcmp(path, "one\\two\\"), "Expected one\\two\\, got %s\n", path); + ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n", GetLastError()); + + /* try periods */ + lstrcpyA(path, "one\\..\\two"); + SetLastError(0xdeadbeef); + str = PathAddBackslashA(path); + ok(str == (path + lstrlenA(path)), "Expected str to point to end of path, got %p\n", str); + ok(!lstrcmp(path, "one\\..\\two\\"), "Expected one\\..\\two\\, got %s\n", path); + ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n", GetLastError()); + + /* try just a space */ + lstrcpyA(path, " "); + SetLastError(0xdeadbeef); + str = PathAddBackslashA(path); + ok(str == (path + lstrlenA(path)), "Expected str to point to end of path, got %p\n", str); + ok(!lstrcmp(path, " \\"), "Expected \\, got %s\n", path); + ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n", GetLastError()); + + /* path already has backslash */ + lstrcpyA(path, "C:\\one\\"); + SetLastError(0xdeadbeef); + str = PathAddBackslashA(path); + ok(str == (path + lstrlenA(path)), "Expected str to point to end of path, got %p\n", str); + ok(!lstrcmp(path, "C:\\one\\"), "Expected C:\\one\\, got %s\n", path); + ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n", GetLastError()); + + memset(too_long, 'a', LONG_LEN); + too_long[LONG_LEN - 1] = '\0'; + + /* path is longer than MAX_PATH */ + SetLastError(0xdeadbeef); + str = PathAddBackslashA(too_long); + ok(str == NULL, "Expected str == NULL, got %p\n", str); + ok(GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n", GetLastError()); +} + START_TEST(path) { hShlwapi = LoadLibraryA("shlwapi.dll"); @@ -1090,6 +1152,7 @@ START_TEST(path) test_PathCreateFromUrl(); test_PathIsUrl(); + test_PathAddBackslash(); test_PathMakePretty(); test_PathMatchSpec();