diff --git a/dlls/wininet/tests/ftp.c b/dlls/wininet/tests/ftp.c index 6d27cb1..aefa493 100644 --- a/dlls/wininet/tests/ftp.c +++ b/dlls/wininet/tests/ftp.c @@ -55,19 +55,9 @@ static void test_getfile_no_open(void) "Expected ERROR_INTERNET_NOT_INITIALIZED or ERROR_INVALID_HANDLE (win98), got %d\n", GetLastError()); } -static void test_connect(void) +static void test_connect(HINTERNET hInternet) { - HINTERNET hInternet, hFtp; - - SetLastError(0xdeadbeef); - hInternet = InternetOpen(NULL, 0, NULL, NULL, 0); - ok(hInternet != NULL, "InternetOpen failed : %d\n", GetLastError()); - - if(!hInternet) - { - skip("No internet connection could be made\n"); - return; - } + HINTERNET hFtp; /* Try a few username/password combinations: * anonymous : NULL @@ -82,9 +72,14 @@ static void test_connect(void) ok ( GetLastError() == ERROR_SUCCESS, "ERROR_SUCCESS, got %d\n", GetLastError()); InternetCloseHandle(hFtp); } - else + else { + if ( GetLastError() == ERROR_INTERNET_CANNOT_CONNECT ) { + skip("No ftp connection could be made to ftp.winehq.org, skipping FTP tests.\n"); + return; + } ok ( GetLastError() == ERROR_INTERNET_LOGIN_FAILURE, "Expected ERROR_INTERNET_LOGIN_FAILURE, got %d\n", GetLastError()); + } SetLastError(0xdeadbeef); hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, NULL, "IEUser@", INTERNET_SERVICE_FTP, 0, 0); @@ -112,13 +107,12 @@ static void test_connect(void) "ERROR_SUCCESS, got %d\n", GetLastError()); InternetCloseHandle(hFtp); - InternetCloseHandle(hInternet); } -static void test_createdir(void) +static void test_createdir(HINTERNET hInternet) { BOOL bRet; - HINTERNET hInternet, hFtp, hConnect; + HINTERNET hFtp, hConnect; /* Invalid internet handle, the other is a valid parameter */ SetLastError(0xdeadbeef); @@ -127,14 +121,8 @@ static void test_createdir(void) ok ( GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError()); - hInternet = InternetOpen(NULL, 0, NULL, NULL, 0); hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0); - if(!hFtp) - { - skip("No ftp connection could be made to ftp.winehq.org\n"); - InternetCloseHandle(hInternet); - return; - } + ok ( hFtp != NULL, "InternetConnect failed : %d\n", GetLastError()); /* We should have a ftp-connection (valid ftp session handle), try some creating */ @@ -173,13 +161,12 @@ static void test_createdir(void) "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError()); InternetCloseHandle(hConnect); - InternetCloseHandle(hInternet); } -static void test_deletefile(void) +static void test_deletefile(HINTERNET hInternet) { BOOL bRet; - HINTERNET hInternet, hFtp, hConnect; + HINTERNET hFtp, hConnect; /* Invalid internet handle, the other is a valid parameter */ SetLastError(0xdeadbeef); @@ -188,14 +175,8 @@ static void test_deletefile(void) ok ( GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError()); - hInternet = InternetOpen(NULL, 0, NULL, NULL, 0); hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0); - if(!hFtp) - { - skip("No ftp connection could be made to ftp.winehq.org\n"); - InternetCloseHandle(hInternet); - return; - } + ok ( hFtp != NULL, "InternetConnect failed : %d\n", GetLastError()); /* We should have a ftp-connection, try some deleting */ @@ -234,13 +215,12 @@ static void test_deletefile(void) "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError()); InternetCloseHandle(hConnect); - InternetCloseHandle(hInternet); } -static void test_getfile(void) +static void test_getfile(HINTERNET hInternet) { BOOL bRet; - HINTERNET hInternet, hFtp, hConnect; + HINTERNET hFtp, hConnect; HANDLE hFile; /* The order of checking is: @@ -266,14 +246,8 @@ static void test_getfile(void) ok ( GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError()); - hInternet = InternetOpen(NULL, 0, NULL, NULL, 0); hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0); - if(!hFtp) - { - skip("No ftp connection could be made to ftp.winehq.org\n"); - InternetCloseHandle(hInternet); - return; - } + ok ( hFtp != NULL, "InternetConnect failed : %d\n", GetLastError()); /* Make sure we start clean */ @@ -426,12 +400,11 @@ static void test_getfile(void) "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError()); InternetCloseHandle(hConnect); - InternetCloseHandle(hInternet); } -static void test_openfile(void) +static void test_openfile(HINTERNET hInternet) { - HINTERNET hOpenFile, hInternet, hFtp, hConnect; + HINTERNET hOpenFile, hFtp, hConnect; /* Invalid internet handle, the rest are valid parameters */ SetLastError(0xdeadbeef); @@ -441,14 +414,8 @@ static void test_openfile(void) "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError()); InternetCloseHandle(hOpenFile); /* Just in case */ - hInternet = InternetOpen(NULL, 0, NULL, NULL, 0); hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0); - if(!hFtp) - { - skip("No ftp connection could be made to ftp.winehq.org\n"); - InternetCloseHandle(hInternet); - return; - } + ok ( hFtp != NULL, "InternetConnect failed : %d\n", GetLastError()); /* We should have a ftp-connection (valid ftp session handle), try some opening */ @@ -578,13 +545,12 @@ static void test_openfile(void) InternetCloseHandle(hOpenFile); /* Just in case */ InternetCloseHandle(hConnect); - InternetCloseHandle(hInternet); } -static void test_putfile(void) +static void test_putfile(HINTERNET hInternet) { BOOL bRet; - HINTERNET hInternet, hFtp, hConnect; + HINTERNET hFtp, hConnect; HANDLE hFile; /* The order of checking is: @@ -610,14 +576,8 @@ static void test_putfile(void) ok ( GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError()); - hInternet = InternetOpen(NULL, 0, NULL, NULL, 0); hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0); - if(!hFtp) - { - skip("No ftp connection could be made to ftp.winehq.org\n"); - InternetCloseHandle(hInternet); - return; - } + ok ( hFtp != NULL, "InternetConnect failed : %d\n", GetLastError()); /* Start clean */ DeleteFileA("non_existing_local"); @@ -696,13 +656,12 @@ static void test_putfile(void) "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError()); InternetCloseHandle(hConnect); - InternetCloseHandle(hInternet); } -static void test_removedir(void) +static void test_removedir(HINTERNET hInternet) { BOOL bRet; - HINTERNET hInternet, hFtp, hConnect; + HINTERNET hFtp, hConnect; /* Invalid internet handle, the other is a valid parameter */ SetLastError(0xdeadbeef); @@ -711,14 +670,8 @@ static void test_removedir(void) ok ( GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError()); - hInternet = InternetOpen(NULL, 0, NULL, NULL, 0); hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0); - if(!hFtp) - { - skip("No ftp connection could be made to ftp.winehq.org\n"); - InternetCloseHandle(hInternet); - return; - } + ok ( hFtp != NULL, "InternetConnect failed : %d\n", GetLastError()); /* We should have a ftp-connection, try some removing */ @@ -765,13 +718,12 @@ static void test_removedir(void) "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError()); InternetCloseHandle(hConnect); - InternetCloseHandle(hInternet); } -static void test_renamefile(void) +static void test_renamefile(HINTERNET hInternet) { BOOL bRet; - HINTERNET hInternet, hFtp, hConnect; + HINTERNET hFtp, hConnect; /* Invalid internet handle, the rest are valid parameters */ SetLastError(0xdeadbeef); @@ -780,14 +732,8 @@ static void test_renamefile(void) ok ( GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError()); - hInternet = InternetOpen(NULL, 0, NULL, NULL, 0); hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0); - if(!hFtp) - { - skip("No ftp connection could be made to ftp.winehq.org\n"); - InternetCloseHandle(hInternet); - return; - } + ok ( hFtp != NULL, "InternetConnect failed : %d\n", GetLastError()); /* We should have a ftp-connection, try some renaming */ @@ -833,22 +779,15 @@ static void test_renamefile(void) "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got %d\n", GetLastError()); InternetCloseHandle(hConnect); - InternetCloseHandle(hInternet); } -static void test_multiple(void) +static void test_multiple(HINTERNET hInternet) { BOOL bRet; - HINTERNET hInternet, hFtp, hOpenFile; + HINTERNET hFtp, hOpenFile; - hInternet = InternetOpen(NULL, 0, NULL, NULL, 0); hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0); - if(!hFtp) - { - skip("No ftp connection could be made to ftp.winehq.org\n"); - InternetCloseHandle(hInternet); - return; - } + ok ( hFtp != NULL, "InternetConnect failed : %d\n", GetLastError()); /* A correct call */ bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0); @@ -866,11 +805,12 @@ static void test_multiple(void) InternetCloseHandle(hOpenFile); InternetCloseHandle(hFtp); - InternetCloseHandle(hInternet); } START_TEST(ftp) { + HINTERNET hInternet, hFtp; + /* The first call should always be a proper InternetOpen, if not * several calls will return ERROR_INTERNET_NOT_INITIALIZED when * all parameters are correct but no session handle is given. Whereas @@ -880,19 +820,42 @@ START_TEST(ftp) * the other sub-tests will show the other situation. */ test_getfile_no_open(); - test_connect(); - test_createdir(); - test_deletefile(); - test_getfile(); - test_openfile(); - test_putfile(); - test_removedir(); - test_renamefile(); + + SetLastError(0xdeadbeef); + hInternet = InternetOpen(NULL, 0, NULL, NULL, 0); + ok(hInternet != NULL, "InternetOpen failed : %d\n", GetLastError()); + + if(!hInternet) + { + skip("No internet connection could be made, skipping FTP tests.\n"); + return; + } + hFtp = InternetConnect(hInternet, "ftp.winehq.org", INTERNET_DEFAULT_FTP_PORT, + "anonymous", "IEUser@", INTERNET_SERVICE_FTP, 0, 0); + if(hFtp == NULL) + { + skip("InternetConnect failed, skipping FTP tests: %d\n", GetLastError()); + return; + } + else + { + InternetCloseHandle(hFtp); + } + + test_connect(hInternet); + test_createdir(hInternet); + test_deletefile(hInternet); + test_getfile(hInternet); + test_openfile(hInternet); + test_putfile(hInternet); + test_removedir(hInternet); + test_renamefile(hInternet); /* A test that does two particular calls in one connection, this currently fails on Wine. * The problem lies in FtpGetFile but is exposed in FtpOpenFile. * Once this is fixed we should change the total test to setup and clear the connections * only once. (and get rid of test_multiple). */ - test_multiple(); + test_multiple(hInternet); + InternetCloseHandle(hInternet); }