static void test_qsort_s(void) { int arr[5] = { 23, 42, 8, 4, 16 }; int arr2[5] = { 23, 42, 8, 4, 16 }; char carr[5] = { 42, 23, 4, 8, 16 }; const char *strarr[7] = { "Hello", "Wine", "World", "!", "Hopefully", "Sorted", "." }; if(!p_qsort_s) { win_skip("qsort_s not found\n"); return; } SET_EXPECT(invalid_parameter_handler); p_qsort_s(NULL, 0, 0, NULL, NULL); CHECK_CALLED(invalid_parameter_handler); SET_EXPECT(invalid_parameter_handler); p_qsort_s(NULL, 0, 0, intcomparefunc, NULL); CHECK_CALLED(invalid_parameter_handler); SET_EXPECT(invalid_parameter_handler); p_qsort_s(NULL, 0, sizeof(int), NULL, NULL); CHECK_CALLED(invalid_parameter_handler); SET_EXPECT(invalid_parameter_handler); p_qsort_s(NULL, 1, sizeof(int), intcomparefunc, NULL); CHECK_CALLED(invalid_parameter_handler); g_qsort_s_context_counter = 0; p_qsort_s(NULL, 0, sizeof(int), intcomparefunc, NULL); ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n"); /* overflow without side effects, other overflow values crash */ g_qsort_s_context_counter = 0; p_qsort_s((void*)arr2, (((size_t)1) << (8*sizeof(size_t) - 1)) + 1, sizeof(int), intcomparefunc, &g_qsort_s_context_counter); ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n"); ok(arr2[0] == 23, "should remain unsorted, arr2[0] is %d\n", arr2[0]); ok(arr2[1] == 42, "should remain unsorted, arr2[1] is %d\n", arr2[1]); ok(arr2[2] == 8, "should remain unsorted, arr2[2] is %d\n", arr2[2]); ok(arr2[3] == 4, "should remain unsorted, arr2[3] is %d\n", arr2[3]); g_qsort_s_context_counter = 0; p_qsort_s((void*)arr, 0, sizeof(int), intcomparefunc, &g_qsort_s_context_counter); ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n"); ok(arr[0] == 23, "badly sorted, nmemb=0, arr[0] is %d\n", arr[0]); ok(arr[1] == 42, "badly sorted, nmemb=0, arr[1] is %d\n", arr[1]); ok(arr[2] == 8, "badly sorted, nmemb=0, arr[2] is %d\n", arr[2]); ok(arr[3] == 4, "badly sorted, nmemb=0, arr[3] is %d\n", arr[3]); ok(arr[4] == 16, "badly sorted, nmemb=0, arr[4] is %d\n", arr[4]); g_qsort_s_context_counter = 0; p_qsort_s((void*)arr, 1, sizeof(int), intcomparefunc, &g_qsort_s_context_counter); ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n"); ok(arr[0] == 23, "badly sorted, nmemb=1, arr[0] is %d\n", arr[0]); ok(arr[1] == 42, "badly sorted, nmemb=1, arr[1] is %d\n", arr[1]); ok(arr[2] == 8, "badly sorted, nmemb=1, arr[2] is %d\n", arr[2]); ok(arr[3] == 4, "badly sorted, nmemb=1, arr[3] is %d\n", arr[3]); ok(arr[4] == 16, "badly sorted, nmemb=1, arr[4] is %d\n", arr[4]); SET_EXPECT(invalid_parameter_handler); g_qsort_s_context_counter = 0; p_qsort_s((void*)arr, 5, 0, intcomparefunc, &g_qsort_s_context_counter); ok(g_qsort_s_context_counter == 0, "callback shouldn't have been called\n"); ok(arr[0] == 23, "badly sorted, size=0, arr[0] is %d\n", arr[0]); ok(arr[1] == 42, "badly sorted, size=0, arr[1] is %d\n", arr[1]); ok(arr[2] == 8, "badly sorted, size=0, arr[2] is %d\n", arr[2]); ok(arr[3] == 4, "badly sorted, size=0, arr[3] is %d\n", arr[3]); ok(arr[4] == 16, "badly sorted, size=0, arr[4] is %d\n", arr[4]); CHECK_CALLED(invalid_parameter_handler); g_qsort_s_context_counter = 0; p_qsort_s((void*)arr, 5, sizeof(int), intcomparefunc, &g_qsort_s_context_counter); ok(g_qsort_s_context_counter > 0, "callback wasn't called\n"); ok(arr[0] == 4, "badly sorted, arr[0] is %d\n", arr[0]); ok(arr[1] == 8, "badly sorted, arr[1] is %d\n", arr[1]); ok(arr[2] == 16, "badly sorted, arr[2] is %d\n", arr[2]); ok(arr[3] == 23, "badly sorted, arr[3] is %d\n", arr[3]); ok(arr[4] == 42, "badly sorted, arr[4] is %d\n", arr[4]); g_qsort_s_context_counter = 0; p_qsort_s((void*)carr, 5, sizeof(char), charcomparefunc, &g_qsort_s_context_counter); ok(g_qsort_s_context_counter > 0, "callback wasn't called\n"); ok(carr[0] == 4, "badly sorted, carr[0] is %d\n", carr[0]); ok(carr[1] == 8, "badly sorted, carr[1] is %d\n", carr[1]); ok(carr[2] == 16, "badly sorted, carr[2] is %d\n", carr[2]); ok(carr[3] == 23, "badly sorted, carr[3] is %d\n", carr[3]); ok(carr[4] == 42, "badly sorted, carr[4] is %d\n", carr[4]); g_qsort_s_context_counter = 0; p_qsort_s((void*)strarr, 7, sizeof(char*), strcomparefunc, &g_qsort_s_context_counter); ok(g_qsort_s_context_counter > 0, "callback wasn't called\n"); ok(!strcmp(strarr[0],"!"), "badly sorted, strarr[0] is %s\n", strarr[0]); ok(!strcmp(strarr[1],"."), "badly sorted, strarr[1] is %s\n", strarr[1]); ok(!strcmp(strarr[2],"Hello"), "badly sorted, strarr[2] is %s\n", strarr[2]); ok(!strcmp(strarr[3],"Hopefully"), "badly sorted, strarr[3] is %s\n", strarr[3]); ok(!strcmp(strarr[4],"Sorted"), "badly sorted, strarr[4] is %s\n", strarr[4]); ok(!strcmp(strarr[5],"Wine"), "badly sorted, strarr[5] is %s\n", strarr[5]); ok(!strcmp(strarr[6],"World"), "badly sorted, strarr[6] is %s\n", strarr[6]); }
static void test_asctime(void) { struct tm* gmt_tm; time_t gmt; char *ret; if(!p_asctime || !p_gmtime) { win_skip("asctime or gmtime is not available\n"); return; } gmt = 0; gmt_tm = p_gmtime(&gmt); ret = p_asctime(gmt_tm); ok(!strcmp(ret, "Thu Jan 01 00:00:00 1970\n"), "asctime retunred %s\n", ret); gmt = 312433121; gmt_tm = p_gmtime(&gmt); ret = p_asctime(gmt_tm); ok(!strcmp(ret, "Mon Nov 26 02:58:41 1979\n"), "asctime retunred %s\n", ret); /* Week day is only checked if it's in 0..6 range */ gmt_tm->tm_wday = 3; ret = p_asctime(gmt_tm); ok(!strcmp(ret, "Wed Nov 26 02:58:41 1979\n"), "asctime returned %s\n", ret); errno = 0xdeadbeef; gmt_tm->tm_wday = 7; ret = p_asctime(gmt_tm); ok(!ret || broken(!ret[0]), "asctime returned %s\n", ret); ok(errno==EINVAL || broken(errno==0xdeadbeef), "errno = %d\n", errno); /* Year day is ignored */ gmt_tm->tm_wday = 3; gmt_tm->tm_yday = 1300; ret = p_asctime(gmt_tm); ok(!strcmp(ret, "Wed Nov 26 02:58:41 1979\n"), "asctime returned %s\n", ret); /* Dates that can't be displayed using 26 characters are broken */ gmt_tm->tm_mday = 28; gmt_tm->tm_year = 8100; ret = p_asctime(gmt_tm); ok(!strcmp(ret, "Wed Nov 28 02:58:41 :000\n"), "asctime returned %s\n", ret); gmt_tm->tm_year = 264100; ret = p_asctime(gmt_tm); ok(!strcmp(ret, "Wed Nov 28 02:58:41 :000\n"), "asctime returned %s\n", ret); /* asctime works from year 1900 */ errno = 0xdeadbeef; gmt_tm->tm_year = -1; ret = p_asctime(gmt_tm); ok(!ret || broken(!strcmp(ret, "Wed Nov 28 02:58:41 190/\n")), "asctime returned %s\n", ret); ok(errno==EINVAL || broken(errno == 0xdeadbeef), "errno = %d\n", errno); errno = 0xdeadbeef; gmt_tm->tm_mon = 1; gmt_tm->tm_mday = 30; gmt_tm->tm_year = 79; ret = p_asctime(gmt_tm); ok(!ret || broken(!strcmp(ret, "Wed Feb 30 02:58:41 1979\n")), "asctime returned %s\n", ret); ok(errno==EINVAL || broken(errno==0xdeadbeef), "errno = %d\n", errno); }
static void test_get_current_dir(HINTERNET hFtp, HINTERNET hConnect) { BOOL bRet; DWORD dwCurrentDirectoryLen = MAX_PATH; CHAR lpszCurrentDirectory[MAX_PATH]; if (!pFtpCommandA) { win_skip("FtpCommandA() is not available. Skipping the Ftp get_current_dir tests\n"); return; } /* change directories to get a more interesting pwd */ bRet = pFtpCommandA(hFtp, FALSE, FTP_TRANSFER_TYPE_ASCII, "CWD pub/", 0, NULL); if(bRet == FALSE) { skip("Failed to change directories in test_get_current_dir(HINTERNET hFtp).\n"); return; } /* test with all NULL arguments */ SetLastError(0xdeadbeef); bRet = FtpGetCurrentDirectoryA( NULL, NULL, 0 ); ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" ); ok ( GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got: %d\n", GetLastError()); /* test with NULL parameters instead of expected LPSTR/LPDWORD */ SetLastError(0xdeadbeef); bRet = FtpGetCurrentDirectoryA( hFtp, NULL, 0 ); ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" ); ok ( GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got: %d\n", GetLastError()); /* test with no valid handle and valid parameters */ SetLastError(0xdeadbeef); bRet = FtpGetCurrentDirectoryA( NULL, lpszCurrentDirectory, &dwCurrentDirectoryLen ); ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" ); ok ( GetLastError() == ERROR_INVALID_HANDLE, "Expected ERROR_INVALID_HANDLE, got: %d\n", GetLastError()); /* test with invalid dwCurrentDirectory and all other parameters correct */ SetLastError(0xdeadbeef); bRet = FtpGetCurrentDirectoryA( hFtp, lpszCurrentDirectory, 0 ); ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" ); ok ( GetLastError() == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got: %d\n", GetLastError()); /* test with invalid lpszCurrentDirectory and all other parameters correct */ SetLastError(0xdeadbeef); bRet = FtpGetCurrentDirectoryA( hFtp, NULL, &dwCurrentDirectoryLen ); ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" ); ok ( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got: %d\n", GetLastError()); /* test to show it checks the handle type */ SetLastError(0xdeadbeef); bRet = FtpGetCurrentDirectoryA( hConnect, lpszCurrentDirectory, &dwCurrentDirectoryLen ); ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n" ); ok ( GetLastError() == ERROR_INTERNET_INCORRECT_HANDLE_TYPE, "Expected ERROR_INTERNET_INCORRECT_HANDLE_TYPE, got: %d\n", GetLastError()); /* test for the current directory with legitimate values */ SetLastError(0xdeadbeef); bRet = FtpGetCurrentDirectoryA( hFtp, lpszCurrentDirectory, &dwCurrentDirectoryLen ); ok ( bRet == TRUE, "Expected FtpGetCurrentDirectoryA to pass\n" ); ok ( !strcmp(lpszCurrentDirectory, "/pub"), "Expected returned value \"%s\" to match \"/pub\"\n", lpszCurrentDirectory); ok ( GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got: %d\n", GetLastError()); /* test for the current directory with a size only large enough to * fit the string and not the null terminating character */ SetLastError(0xdeadbeef); dwCurrentDirectoryLen = 4; lpszCurrentDirectory[4] = 'a'; /* set position 4 of the array to something else to make sure a leftover \0 isn't fooling the test */ bRet = FtpGetCurrentDirectoryA( hFtp, lpszCurrentDirectory, &dwCurrentDirectoryLen ); ok ( bRet == FALSE, "Expected FtpGetCurrentDirectoryA to fail\n"); ok ( strcmp(lpszCurrentDirectory, "/pub"), "Expected returned value \"%s\" to not match \"/pub\"\n", lpszCurrentDirectory); ok ( GetLastError() == ERROR_INSUFFICIENT_BUFFER, "Expected ERROR_INSUFFICIENT_BUFFER, got: %d\n", GetLastError()); /* test for the current directory with a size large enough to store * the expected string as well as the null terminating character */ SetLastError(0xdeadbeef); dwCurrentDirectoryLen = 5; bRet = FtpGetCurrentDirectoryA( hFtp, lpszCurrentDirectory, &dwCurrentDirectoryLen ); ok ( bRet == TRUE, "Expected FtpGetCurrentDirectoryA to pass\n"); ok ( !strcmp(lpszCurrentDirectory, "/pub"), "Expected returned value \"%s\" to match \"/pub\"\n", lpszCurrentDirectory); ok ( GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got: %d\n", GetLastError()); }
static void test_searchenv(void) { const char *dirs[] = { "\\search_env_test", "\\search_env_test\\dir1", "\\search_env_test\\dir2", "\\search_env_test\\dir3longer" }; const char *files[] = { "\\search_env_test\\dir1\\1.dat", "\\search_env_test\\dir1\\2.dat", "\\search_env_test\\dir2\\1.dat", "\\search_env_test\\dir2\\3.dat", "\\search_env_test\\dir3longer\\3.dat" }; const WCHAR env_w[] = {'T','E','S','T','_','P','A','T','H',0}; const WCHAR dat1_w[] = {'1','.','d','a','t',0}; const WCHAR dat3_w[] = {'3','.','d','a','t',0}; char env1[4*MAX_PATH], env2[4*MAX_PATH], tmppath[MAX_PATH], path[2*MAX_PATH]; char result[MAX_PATH], exp[2*MAX_PATH]; WCHAR result_w[MAX_PATH]; int i, path_len; FILE *tmp_file; if (getenv("TEST_PATH")) { skip("TEST_PATH environment variable already set\n"); return; } path_len = GetTempPathA(MAX_PATH, tmppath); ok(path_len, "GetTempPath failed\n"); memcpy(path, tmppath, path_len); for (i=0; i<ARRAY_SIZE(dirs); i++) { strcpy(path+path_len, dirs[i]); ok(!mkdir(path), "mkdir failed (dir = %s)\n", path); } for (i=0; i<ARRAY_SIZE(files); i++) { strcpy(path+path_len, files[i]); tmp_file = fopen(path, "wb"); ok(tmp_file != NULL, "fopen failed (file = %s)\n", path); fclose(tmp_file); } strcpy(env1, "TEST_PATH="); strcpy(env2, "TEST_PATH=;"); for (i=1; i<ARRAY_SIZE(dirs); i++) { strcat(env1, tmppath); strcat(env1, dirs[i]); strcat(env1, ";"); strcat(env2, tmppath); strcat(env2, dirs[i]); strcat(env2, ";;"); } if (!p_searchenv_s || !p_wsearchenv_s) win_skip("searchenv_s or wsearchenv_s function is not available\n"); putenv(env1); memset(result, 'x', sizeof(result)); _searchenv("fail", "TEST_PATH", result); ok(!result[0], "got %s, expected ''\n", result); if (p_searchenv_s) { memset(result, 'x', sizeof(result)); i = p_searchenv_s("fail", "TEST_PATH", result, MAX_PATH); ok(i == ENOENT, "searchenv_s returned %d\n", i); ok(!result[0], "got %s, expected ''\n", result); } memset(result, 'x', sizeof(result)); strcpy(exp, tmppath); strcat(exp, files[0]); _searchenv("1.dat", "TEST_PATH", result); ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp); if (p_searchenv_s) { memset(result, 'x', sizeof(result)); i = p_searchenv_s("1.dat", "TEST_PATH", result, MAX_PATH); ok(!i, "searchenv_s returned %d\n", i); ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp); } memset(result_w, 'x', sizeof(result_w)); _wsearchenv(dat1_w, env_w, result_w); WideCharToMultiByte(CP_ACP, 0, result_w, -1, result, MAX_PATH, NULL, NULL); ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp); if (p_wsearchenv_s) { memset(result_w, 'x', sizeof(result_w)); i = p_wsearchenv_s(dat1_w, env_w, result_w, MAX_PATH); ok(!i, "wsearchenv_s returned %d\n", i); ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp); } memset(result, 'x', sizeof(result)); strcpy(exp, tmppath); strcat(exp, files[3]); _searchenv("3.dat", "TEST_PATH", result); ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp); if (p_searchenv_s) { memset(result, 'x', sizeof(result)); i = p_searchenv_s("3.dat", "TEST_PATH", result, MAX_PATH); ok(!i, "searchenv_s returned %d\n", i); ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp); } memset(result_w, 'x', sizeof(result_w)); _wsearchenv(dat3_w, env_w, result_w); WideCharToMultiByte(CP_ACP, 0, result_w, -1, result, MAX_PATH, NULL, NULL); ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp); if (p_wsearchenv_s) { memset(result_w, 'x', sizeof(result_w)); i = p_wsearchenv_s(dat3_w, env_w, result_w, MAX_PATH); ok(!i, "wsearchenv_s returned %d\n", i); ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp); } putenv(env2); memset(result, 'x', sizeof(result)); strcpy(exp, tmppath); strcat(exp, files[0]); _searchenv("1.dat", "TEST_PATH", result); ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp); if (p_searchenv_s) { memset(result, 'x', sizeof(result)); i = p_searchenv_s("1.dat", "TEST_PATH", result, MAX_PATH); ok(!i, "searchenv_s returned %d\n", i); ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp); } memset(result_w, 'x', sizeof(result_w)); _wsearchenv(dat1_w, env_w, result_w); WideCharToMultiByte(CP_ACP, 0, result_w, -1, result, MAX_PATH, NULL, NULL); ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp); if (p_wsearchenv_s) { memset(result_w, 'x', sizeof(result_w)); i = p_wsearchenv_s(dat1_w, env_w, result_w, MAX_PATH); ok(!i, "wsearchenv_s returned %d\n", i); ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp); } memset(result, 'x', sizeof(result)); strcpy(exp, tmppath); strcat(exp, files[3]); _searchenv("3.dat", "TEST_PATH", result); ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp); if (p_searchenv_s) { memset(result, 'x', sizeof(result)); i = p_searchenv_s("3.dat", "TEST_PATH", result, MAX_PATH); ok(!i, "searchenv_s returned %d\n", i); ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp); } memset(result_w, 'x', sizeof(result_w)); _wsearchenv(dat3_w, env_w, result_w); WideCharToMultiByte(CP_ACP, 0, result_w, -1, result, MAX_PATH, NULL, NULL); ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp); if (p_wsearchenv_s) { memset(result_w, 'x', sizeof(result_w)); i = p_wsearchenv_s(dat3_w, env_w, result_w, MAX_PATH); ok(!i, "wsearchenv_s returned %d\n", i); ok(!strcmp(result, exp), "got %s, expected '%s'\n", result, exp); } putenv("TEST_PATH="); for (i=ARRAY_SIZE(files)-1; i>=0; i--) { strcpy(path+path_len, files[i]); ok(!remove(path), "remove failed (file = %s)\n", path); } for (i=ARRAY_SIZE(dirs)-1; i>=0; i--) { strcpy(path+path_len, dirs[i]); ok(!rmdir(path), "rmdir failed (dir = %s)\n", path); } }
static void test_localtime64_s(void) { struct tm tm; __time64_t time; errno_t err; if (!p_localtime64_s) { win_skip("Skipping _localtime64_s tests\n"); return; } errno = EBADF; err = p_localtime64_s(NULL, NULL); ok(err == EINVAL, "Expected _localtime64_s to return EINVAL, got %d\n", err); ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno); errno = EBADF; time = 0xdeadbeef; err = p_localtime64_s(NULL, &time); ok(err == EINVAL, "Expected _localtime64_s to return EINVAL, got %d\n", err); ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno); memset(&tm, 0, sizeof(tm)); errno = EBADF; err = p_localtime64_s(&tm, NULL); ok(err == EINVAL, "Expected _localtime64_s to return EINVAL, got %d\n", err); ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno); ok(tm.tm_sec == -1 && tm.tm_min == -1 && tm.tm_hour == -1 && tm.tm_mday == -1 && tm.tm_mon == -1 && tm.tm_year == -1 && tm.tm_wday == -1 && tm.tm_yday == -1 && tm.tm_isdst == -1, "Expected tm structure members to be initialized to -1, got " "(%d, %d, %d, %d, %d, %d, %d, %d, %d)\n", tm.tm_sec, tm.tm_min, tm.tm_hour, tm.tm_mday, tm.tm_mon, tm.tm_year, tm.tm_wday, tm.tm_yday, tm.tm_isdst); memset(&tm, 0, sizeof(tm)); time = -1; errno = EBADF; err = p_localtime64_s(&tm, &time); ok(err == EINVAL, "Expected _localtime64_s to return EINVAL, got %d\n", err); ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno); ok(tm.tm_sec == -1 && tm.tm_min == -1 && tm.tm_hour == -1 && tm.tm_mday == -1 && tm.tm_mon == -1 && tm.tm_year == -1 && tm.tm_wday == -1 && tm.tm_yday == -1 && tm.tm_isdst == -1, "Expected tm structure members to be initialized to -1, got " "(%d, %d, %d, %d, %d, %d, %d, %d, %d)\n", tm.tm_sec, tm.tm_min, tm.tm_hour, tm.tm_mday, tm.tm_mon, tm.tm_year, tm.tm_wday, tm.tm_yday, tm.tm_isdst); memset(&tm, 0, sizeof(tm)); time = _MAX__TIME64_T + 1; errno = EBADF; err = p_localtime64_s(&tm, &time); ok(err == EINVAL, "Expected _localtime64_s to return EINVAL, got %d\n", err); ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno); ok(tm.tm_sec == -1 && tm.tm_min == -1 && tm.tm_hour == -1 && tm.tm_mday == -1 && tm.tm_mon == -1 && tm.tm_year == -1 && tm.tm_wday == -1 && tm.tm_yday == -1 && tm.tm_isdst == -1, "Expected tm structure members to be initialized to -1, got " "(%d, %d, %d, %d, %d, %d, %d, %d, %d)\n", tm.tm_sec, tm.tm_min, tm.tm_hour, tm.tm_mday, tm.tm_mon, tm.tm_year, tm.tm_wday, tm.tm_yday, tm.tm_isdst); }
static void test_editselection(void) { HWND hCombo; INT start,end; HWND hEdit; COMBOBOXINFO cbInfo; BOOL ret; DWORD len; BOOL (WINAPI *pGetComboBoxInfo)(HWND, PCOMBOBOXINFO); char edit[20]; pGetComboBoxInfo = (void*)GetProcAddress(GetModuleHandleA("user32.dll"), "GetComboBoxInfo"); if (!pGetComboBoxInfo){ win_skip("GetComboBoxInfo is not available\n"); return; } /* Build a combo */ hCombo = build_combo(CBS_SIMPLE); cbInfo.cbSize = sizeof(COMBOBOXINFO); SetLastError(0xdeadbeef); ret = pGetComboBoxInfo(hCombo, &cbInfo); ok(ret, "Failed to get combobox info structure. LastError=%d\n", GetLastError()); hEdit = cbInfo.hwndItem; /* Initially combo selection is empty*/ len = SendMessage(hCombo, CB_GETEDITSEL, 0,0); ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len)); ok(HIWORD(len)==0, "Unexpected end position for selection %d\n", HIWORD(len)); /* Set some text, and press a key to replace it */ edit[0] = 0x00; SendMessage(hCombo, WM_SETTEXT, 0, (LPARAM)"Jason1"); SendMessage(hCombo, WM_GETTEXT, sizeof(edit), (LPARAM)edit); ok(strcmp(edit, "Jason1")==0, "Unexpected text retrieved %s\n", edit); /* Now what is the selection - still empty */ SendMessage(hCombo, CB_GETEDITSEL, (WPARAM)&start, (WPARAM)&end); len = SendMessage(hCombo, CB_GETEDITSEL, 0,0); ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len)); ok(HIWORD(len)==0, "Unexpected end position for selection %d\n", HIWORD(len)); /* Give it focus, and it gets selected */ SendMessage(hCombo, WM_SETFOCUS, 0, (LPARAM)hEdit); SendMessage(hCombo, CB_GETEDITSEL, (WPARAM)&start, (WPARAM)&end); len = SendMessage(hCombo, CB_GETEDITSEL, 0,0); ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len)); ok(HIWORD(len)==6, "Unexpected end position for selection %d\n", HIWORD(len)); /* Now emulate a key press */ edit[0] = 0x00; SendMessage(hCombo, WM_CHAR, 'A', 0x1c0001); SendMessage(hCombo, WM_GETTEXT, sizeof(edit), (LPARAM)edit); ok(strcmp(edit, "A")==0, "Unexpected text retrieved %s\n", edit); len = SendMessage(hCombo, CB_GETEDITSEL, 0,0); ok(LOWORD(len)==1, "Unexpected start position for selection %d\n", LOWORD(len)); ok(HIWORD(len)==1, "Unexpected end position for selection %d\n", HIWORD(len)); /* Now what happens when it gets more focus a second time - it doesn't reselect */ SendMessage(hCombo, WM_SETFOCUS, 0, (LPARAM)hEdit); len = SendMessage(hCombo, CB_GETEDITSEL, 0,0); ok(LOWORD(len)==1, "Unexpected start position for selection %d\n", LOWORD(len)); ok(HIWORD(len)==1, "Unexpected end position for selection %d\n", HIWORD(len)); DestroyWindow(hCombo); /* Start again - Build a combo */ hCombo = build_combo(CBS_SIMPLE); cbInfo.cbSize = sizeof(COMBOBOXINFO); SetLastError(0xdeadbeef); ret = pGetComboBoxInfo(hCombo, &cbInfo); ok(ret, "Failed to get combobox info structure. LastError=%d\n", GetLastError()); hEdit = cbInfo.hwndItem; /* Set some text and give focus so it gets selected */ edit[0] = 0x00; SendMessage(hCombo, WM_SETTEXT, 0, (LPARAM)"Jason2"); SendMessage(hCombo, WM_GETTEXT, sizeof(edit), (LPARAM)edit); ok(strcmp(edit, "Jason2")==0, "Unexpected text retrieved %s\n", edit); SendMessage(hCombo, WM_SETFOCUS, 0, (LPARAM)hEdit); /* Now what is the selection */ SendMessage(hCombo, CB_GETEDITSEL, (WPARAM)&start, (WPARAM)&end); len = SendMessage(hCombo, CB_GETEDITSEL, 0,0); ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len)); ok(HIWORD(len)==6, "Unexpected end position for selection %d\n", HIWORD(len)); /* Now change the selection to the apparently invalid start -1, end -1 and show it means no selection (ie start -1) but cursor at end */ SendMessage(hCombo, CB_SETEDITSEL, 0, -1); edit[0] = 0x00; SendMessage(hCombo, WM_CHAR, 'A', 0x1c0001); SendMessage(hCombo, WM_GETTEXT, sizeof(edit), (LPARAM)edit); ok(strcmp(edit, "Jason2A")==0, "Unexpected text retrieved %s\n", edit); DestroyWindow(hCombo); }
static void test_setvalue_on_wow64(IPropertyStore *store) { PROPVARIANT pv; HRESULT hr; LONG ret; WCHAR *guidW; HKEY root, props, devkey; DWORD type, regval, size; static const PROPERTYKEY PKEY_Bogus = { {0x1da5d803, 0xd492, 0x4edd, {0x8c, 0x23, 0xe0, 0xc0, 0xff, 0xee, 0x7f, 0x00}}, 0x7f }; static const WCHAR bogusW[] = {'{','1','D','A','5','D','8','0','3','-','D','4','9','2','-','4','E','D','D','-','8','C','2','3','-','E','0','C','0','F','F','E','E','7','F','0','0','}',',','1','2','7',0}; PropVariantInit(&pv); pv.vt = VT_EMPTY; hr = IPropertyStore_GetValue(store, &PKEY_AudioEndpoint_GUID, &pv); ok(hr == S_OK, "Failed to get Endpoint GUID: %08x\n", hr); guidW = pv.u.pwszVal; pv.vt = VT_UI4; pv.u.ulVal = 0xAB; hr = IPropertyStore_SetValue(store, &PKEY_Bogus, &pv); ok(hr == S_OK || hr == E_ACCESSDENIED, "SetValue failed: %08x\n", hr); if (hr != S_OK) { win_skip("Missing permission to write to registry\n"); return; } pv.u.ulVal = 0x00; hr = IPropertyStore_GetValue(store, &PKEY_Bogus, &pv); ok(hr == S_OK, "GetValue failed: %08x\n", hr); ok(pv.u.ulVal == 0xAB, "Got wrong value: 0x%x\n", pv.u.ulVal); /* should find the key in 64-bit view */ ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE, software_renderW, 0, KEY_READ|KEY_WOW64_64KEY, &root); ok(ret == ERROR_SUCCESS, "Couldn't open mmdevices Render key: %u\n", ret); ret = RegOpenKeyExW(root, guidW, 0, KEY_READ|KEY_WOW64_64KEY, &devkey); ok(ret == ERROR_SUCCESS, "Couldn't open mmdevice guid key: %u\n", ret); ret = RegOpenKeyExW(devkey, propertiesW, 0, KEY_READ|KEY_WOW64_64KEY, &props); ok(ret == ERROR_SUCCESS, "Couldn't open mmdevice property key: %u\n", ret); /* Note: the registry key exists even without calling IPropStore::Commit */ size = sizeof(regval); ret = RegGetValueW(props, NULL, bogusW, RRF_RT_DWORD, &type, ®val, &size); ok(ret == ERROR_SUCCESS, "Couldn't get bogus propertykey value: %u\n", ret); ok(type == REG_DWORD, "Got wrong value type: %u\n", type); ok(regval == 0xAB, "Got wrong value: 0x%x\n", regval); RegCloseKey(props); RegCloseKey(devkey); RegCloseKey(root); CoTaskMemFree(guidW); /* should NOT find the key in 32-bit view */ ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE, software_renderW, 0, KEY_READ, &root); ok(ret == ERROR_FILE_NOT_FOUND, "Wrong error when opening mmdevices Render key: %u\n", ret); }
static void test_SetupDuplicateDiskSpaceListW(void) { HDSKSPC handle, duplicate; SetLastError(0xdeadbeef); duplicate = SetupDuplicateDiskSpaceListW(NULL, NULL, 0, 0); if (!duplicate && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) { win_skip("SetupDuplicateDiskSpaceListW is not available\n"); return; } ok(!duplicate, "Expected SetupDuplicateDiskSpaceList to return NULL, got %p\n", duplicate); ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected GetLastError() to return ERROR_INVALID_HANDLE, got %u\n", GetLastError()); SetLastError(0xdeadbeef); duplicate = SetupDuplicateDiskSpaceListW(NULL, (void *)0xdeadbeef, 0, 0); ok(!duplicate, "Expected SetupDuplicateDiskSpaceList to return NULL, got %p\n", duplicate); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); SetLastError(0xdeadbeef); duplicate = SetupDuplicateDiskSpaceListW(NULL, NULL, 0xdeadbeef, 0); ok(!duplicate, "Expected SetupDuplicateDiskSpaceList to return NULL, got %p\n", duplicate); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); SetLastError(0xdeadbeef); duplicate = SetupDuplicateDiskSpaceListW(NULL, NULL, 0, ~0U); ok(!duplicate, "Expected SetupDuplicateDiskSpaceList to return NULL, got %p\n", duplicate); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); handle = SetupCreateDiskSpaceListW(NULL, 0, 0); ok(handle != NULL, "Expected SetupCreateDiskSpaceListW to return a valid handle, got NULL\n"); if (!handle) { skip("Failed to create a disk space handle\n"); return; } SetLastError(0xdeadbeef); duplicate = SetupDuplicateDiskSpaceListW(handle, (void *)0xdeadbeef, 0, 0); ok(!duplicate, "Expected SetupDuplicateDiskSpaceList to return NULL, got %p\n", duplicate); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); SetLastError(0xdeadbeef); duplicate = SetupDuplicateDiskSpaceListW(handle, NULL, 0xdeadbeef, 0); ok(!duplicate, "Expected SetupDuplicateDiskSpaceList to return NULL, got %p\n", duplicate); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); SetLastError(0xdeadbeef); duplicate = SetupDuplicateDiskSpaceListW(handle, NULL, 0, SPDSL_IGNORE_DISK); ok(!duplicate, "Expected SetupDuplicateDiskSpaceList to return NULL, got %p\n", duplicate); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); SetLastError(0xdeadbeef); duplicate = SetupDuplicateDiskSpaceListW(handle, NULL, 0, ~0U); ok(!duplicate, "Expected SetupDuplicateDiskSpaceList to return NULL, got %p\n", duplicate); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); duplicate = SetupDuplicateDiskSpaceListW(handle, NULL, 0, 0); ok(duplicate != NULL, "Expected SetupDuplicateDiskSpaceList to return NULL, got %p\n", duplicate); ok(duplicate != handle, "Expected new handle (%p) to be different from the old handle (%p)\n", duplicate, handle); ok(SetupDestroyDiskSpaceList(duplicate), "Expected SetupDestroyDiskSpaceList to succeed\n"); ok(SetupDestroyDiskSpaceList(handle), "Expected SetupDestroyDiskSpaceList to succeed\n"); }
static void test_SetupQuerySpaceRequiredOnDriveA(void) { BOOL ret; HDSKSPC handle; LONGLONG space; if (is_win9x) win_skip("SetupQuerySpaceRequiredOnDriveA crashes with NULL disk space handle on Win9x\n"); else { SetLastError(0xdeadbeef); ret = SetupQuerySpaceRequiredOnDriveA(NULL, NULL, NULL, NULL, 0); ok(!ret, "Expected SetupQuerySpaceRequiredOnDriveA to return FALSE, got %d\n", ret); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); SetLastError(0xdeadbeef); space = 0xdeadbeef; ret = SetupQuerySpaceRequiredOnDriveA(NULL, NULL, &space, NULL, 0); ok(!ret, "Expected SetupQuerySpaceRequiredOnDriveA to return FALSE, got %d\n", ret); ok(space == 0xdeadbeef, "Expected output space parameter to be untouched\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); SetLastError(0xdeadbeef); ret = SetupQuerySpaceRequiredOnDriveA(NULL, "", NULL, NULL, 0); ok(!ret, "Expected SetupQuerySpaceRequiredOnDriveA to return FALSE, got %d\n", ret); ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected GetLastError() to return ERROR_INVALID_HANDLE, got %u\n", GetLastError()); SetLastError(0xdeadbeef); space = 0xdeadbeef; ret = SetupQuerySpaceRequiredOnDriveA(NULL, "", &space, NULL, 0); ok(!ret, "Expected SetupQuerySpaceRequiredOnDriveA to return FALSE, got %d\n", ret); ok(space == 0xdeadbeef, "Expected output space parameter to be untouched\n"); ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected GetLastError() to return ERROR_INVALID_HANDLE, got %u\n", GetLastError()); } handle = SetupCreateDiskSpaceListA(NULL, 0, 0); ok(handle != NULL, "Expected SetupCreateDiskSpaceListA to return a valid handle, got NULL\n"); SetLastError(0xdeadbeef); ret = SetupQuerySpaceRequiredOnDriveA(handle, NULL, NULL, NULL, 0); ok(!ret, "Expected SetupQuerySpaceRequiredOnDriveA to return FALSE, got %d\n", ret); ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INVALID_DRIVE, /* Win9x */ "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); SetLastError(0xdeadbeef); space = 0xdeadbeef; ret = SetupQuerySpaceRequiredOnDriveA(handle, NULL, &space, NULL, 0); ok(!ret, "Expected SetupQuerySpaceRequiredOnDriveA to return FALSE, got %d\n", ret); ok(space == 0xdeadbeef, "Expected output space parameter to be untouched\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INVALID_DRIVE, /* Win9x */ "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); SetLastError(0xdeadbeef); ret = SetupQuerySpaceRequiredOnDriveA(handle, "", NULL, NULL, 0); ok(!ret, "Expected SetupQuerySpaceRequiredOnDriveA to return FALSE, got %d\n", ret); ok(GetLastError() == ERROR_INVALID_DRIVE, "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); SetLastError(0xdeadbeef); space = 0xdeadbeef; ret = SetupQuerySpaceRequiredOnDriveA(handle, "", &space, NULL, 0); ok(!ret, "Expected SetupQuerySpaceRequiredOnDriveA to return FALSE, got %d\n", ret); ok(space == 0xdeadbeef, "Expected output space parameter to be untouched\n"); ok(GetLastError() == ERROR_INVALID_DRIVE, "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); ok(SetupDestroyDiskSpaceList(handle), "Expected SetupDestroyDiskSpaceList to succeed\n"); }
static void test_Load(void) { static const WCHAR xmlview_xmlW[] = {'/','x','m','l','/','x','m','l','v','i','e','w','.','x','m','l',0}; static const WCHAR res[] = {'r','e','s',':','/','/',0}; WCHAR buf[1024]; IPersistMoniker *pers_mon; IConnectionPointContainer *cpc; IConnectionPoint *cp; IMoniker *mon; IBindCtx *bctx; IHTMLElement *elem; HRESULT hres; MSG msg; BSTR source; lstrcpyW(buf, res); GetModuleFileNameW(NULL, buf+lstrlenW(buf), (sizeof(buf)-sizeof(res))/sizeof(WCHAR)); lstrcatW(buf, xmlview_xmlW); if(!pCreateURLMoniker) { win_skip("CreateURLMoniker not available\n"); return; } hres = CoCreateInstance(&CLSID_XMLView, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER, &IID_IPersistMoniker, (void**)&pers_mon); if(FAILED(hres)) { win_skip("Failed to create XMLView instance\n"); return; } ok(hres == S_OK, "CoCreateInstance returned %x, expected S_OK\n", hres); hres = IPersistMoniker_QueryInterface(pers_mon, &IID_IHTMLDocument2, (void**)&html_doc); ok(hres == S_OK, "QueryInterface(HTMLDocument2) returned %x, expected S_OK\n", hres); hres = IPersistMoniker_QueryInterface(pers_mon, &IID_IConnectionPointContainer, (void**)&cpc); ok(hres == S_OK, "QueryInterface(IConnectionPointContainer) returned %x, expected S_OK\n", hres); hres = IConnectionPointContainer_FindConnectionPoint(cpc, &IID_IDispatch, &cp); ok(hres == S_OK, "FindConnectionPoint returned %x, expected S_OK\n", hres); hres = IConnectionPoint_Advise(cp, (IUnknown*)&HTMLEvents, NULL); ok(hres == S_OK, "Advise returned %x, expected S_OK\n", hres); IConnectionPoint_Release(cp); IConnectionPointContainer_Release(cpc); hres = CreateBindCtx(0, &bctx); ok(hres == S_OK, "CreateBindCtx returned %x, expected S_OK\n", hres); hres = pCreateURLMoniker(NULL, buf, &mon); ok(hres == S_OK, "CreateUrlMoniker returned %x, expected S_OK\n", hres); loaded = FALSE; hres = IPersistMoniker_Load(pers_mon, TRUE, mon, bctx, 0); ok(hres == S_OK, "Load returned %x, expected S_OK\n", hres); IBindCtx_Release(bctx); IMoniker_Release(mon); while(!loaded && GetMessageA(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessageA(&msg); } hres = IHTMLDocument2_get_body(html_doc, &elem); ok(hres == S_OK, "get_body returned %x, expected S_OK\n", hres); hres = IHTMLElement_get_outerHTML(elem, &source); ok(hres == S_OK, "get_outerHTML returned %x, expected S_OK\n", hres); ok(!html_src_compare(source, xmlview_html), "Incorrect HTML source: %s\n", wine_dbgstr_w(source)); IHTMLElement_Release(elem); SysFreeString(source); IHTMLDocument2_Release(html_doc); html_doc = NULL; IPersistMoniker_Release(pers_mon); }
static void test_SetupDuplicateDiskSpaceListA(void) { HDSKSPC handle, duplicate; if (is_win9x) win_skip("SetupDuplicateDiskSpaceListA crashes with NULL disk space handle on Win9x\n"); else { SetLastError(0xdeadbeef); duplicate = SetupDuplicateDiskSpaceListA(NULL, NULL, 0, 0); ok(!duplicate, "Expected SetupDuplicateDiskSpaceList to return NULL, got %p\n", duplicate); ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected GetLastError() to return ERROR_INVALID_HANDLE, got %u\n", GetLastError()); SetLastError(0xdeadbeef); duplicate = SetupDuplicateDiskSpaceListA(NULL, (void *)0xdeadbeef, 0, 0); ok(!duplicate, "Expected SetupDuplicateDiskSpaceList to return NULL, got %p\n", duplicate); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); SetLastError(0xdeadbeef); duplicate = SetupDuplicateDiskSpaceListA(NULL, NULL, 0xdeadbeef, 0); ok(!duplicate, "Expected SetupDuplicateDiskSpaceList to return NULL, got %p\n", duplicate); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); SetLastError(0xdeadbeef); duplicate = SetupDuplicateDiskSpaceListA(NULL, NULL, 0, ~0U); ok(!duplicate, "Expected SetupDuplicateDiskSpaceList to return NULL, got %p\n", duplicate); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); } handle = SetupCreateDiskSpaceListA(NULL, 0, 0); ok(handle != NULL, "Expected SetupCreateDiskSpaceListA to return a valid handle, got NULL\n"); if (!handle) { skip("Failed to create a disk space handle\n"); return; } SetLastError(0xdeadbeef); duplicate = SetupDuplicateDiskSpaceListA(handle, (void *)0xdeadbeef, 0, 0); ok(!duplicate, "Expected SetupDuplicateDiskSpaceList to return NULL, got %p\n", duplicate); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); SetLastError(0xdeadbeef); duplicate = SetupDuplicateDiskSpaceListA(handle, NULL, 0xdeadbeef, 0); ok(!duplicate, "Expected SetupDuplicateDiskSpaceList to return NULL, got %p\n", duplicate); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); SetLastError(0xdeadbeef); duplicate = SetupDuplicateDiskSpaceListA(handle, NULL, 0, SPDSL_IGNORE_DISK); ok(!duplicate, "Expected SetupDuplicateDiskSpaceList to return NULL, got %p\n", duplicate); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); SetLastError(0xdeadbeef); duplicate = SetupDuplicateDiskSpaceListA(handle, NULL, 0, ~0U); ok(!duplicate, "Expected SetupDuplicateDiskSpaceList to return NULL, got %p\n", duplicate); ok(GetLastError() == ERROR_INVALID_PARAMETER, "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); duplicate = SetupDuplicateDiskSpaceListA(handle, NULL, 0, 0); ok(duplicate != NULL, "Expected SetupDuplicateDiskSpaceList to return NULL, got %p\n", duplicate); ok(duplicate != handle, "Expected new handle (%p) to be different from the old handle (%p)\n", duplicate, handle); ok(SetupDestroyDiskSpaceList(duplicate), "Expected SetupDestroyDiskSpaceList to succeed\n"); ok(SetupDestroyDiskSpaceList(handle), "Expected SetupDestroyDiskSpaceList to succeed\n"); }
static void test_format_object(void) { BOOL (WINAPI *pCryptFormatObject)(DWORD dwEncoding, DWORD dwFormatType, DWORD dwFormatStrType, void *pFormatStruct, LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD dwEncoded, void *pbFormat, DWORD *pcbFormat); BOOL ret; DWORD size; LPWSTR str; pCryptFormatObject = (void *)GetProcAddress(hCrypt, "CryptFormatObject"); if (!pCryptFormatObject) { skip("No CryptFormatObject\n"); return; } /* Crash */ if (0) { pCryptFormatObject(0, 0, 0, NULL, NULL, NULL, 0, NULL, NULL); } /* When called with any but the default encoding, it fails to find a * formatting function. */ SetLastError(0xdeadbeef); ret = pCryptFormatObject(0, 0, 0, NULL, NULL, NULL, 0, NULL, &size); ok(!ret && GetLastError() == ERROR_FILE_NOT_FOUND, "expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); /* When called with the default encoding type for any undefined struct type * (including none), it succeeds: the default encoding is a hex string * encoding. */ SetLastError(0xdeadbeef); ret = pCryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, NULL, NULL, 0, NULL, &size); ok(ret, "CryptFormatObject failed: %d\n", GetLastError()); if (ret) { if (size == 0 && GetLastError() == ERROR_FILE_NOT_FOUND) { win_skip("CryptFormatObject has no default implementation\n"); return; } ok(size == sizeof(WCHAR), "unexpected size %d\n", size); str = HeapAlloc(GetProcessHeap(), 0, size); SetLastError(0xdeadbeef); size = 0; ret = pCryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, NULL, NULL, 0, str, &size); ok(!ret && GetLastError() == ERROR_MORE_DATA, "expected ERROR_MORE_DATA, got %d\n", GetLastError()); size = sizeof(WCHAR); ret = pCryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, NULL, NULL, 0, str, &size); ok(ret, "CryptFormatObject failed: %d\n", GetLastError()); ok(!str[0], "expected empty string\n"); HeapFree(GetProcessHeap(), 0, str); } ret = pCryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, NULL, encodedInt, sizeof(encodedInt), NULL, &size); ok(ret, "CryptFormatObject failed: %d\n", GetLastError()); if (ret) { str = HeapAlloc(GetProcessHeap(), 0, size); ret = pCryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, NULL, encodedInt, sizeof(encodedInt), str, &size); ok(ret, "CryptFormatObject failed: %d\n", GetLastError()); ok(!lstrcmpW(str, encodedIntStr), "unexpected format string\n"); HeapFree(GetProcessHeap(), 0, str); } ret = pCryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, NULL, encodedBigInt, sizeof(encodedBigInt), NULL, &size); ok(ret, "CryptFormatObject failed: %d\n", GetLastError()); if (ret) { str = HeapAlloc(GetProcessHeap(), 0, size); ret = pCryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, NULL, encodedBigInt, sizeof(encodedBigInt), str, &size); ok(ret, "CryptFormatObject failed: %d\n", GetLastError()); ok(!lstrcmpiW(str, encodedBigIntStr), "unexpected format string\n"); HeapFree(GetProcessHeap(), 0, str); } /* When called with the default encoding type for any undefined struct * type but CRYPT_FORMAT_STR_NO_HEX specified, it fails to find a * formatting function. */ SetLastError(0xdeadbeef); ret = pCryptFormatObject(X509_ASN_ENCODING, 0, CRYPT_FORMAT_STR_NO_HEX, NULL, NULL, NULL, 0, NULL, &size); ok(!ret, "CryptFormatObject succeeded\n"); ok(GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == 0xdeadbeef, /* Vista, W2K8 */ "expected ERROR_FILE_NOT_FOUND or no change, got %d\n", GetLastError()); /* When called to format an AUTHORITY_KEY_ID2_INFO, it fails when no * data are given. */ SetLastError(0xdeadbeef); ret = pCryptFormatObject(X509_ASN_ENCODING, 0, 0, NULL, szOID_AUTHORITY_KEY_IDENTIFIER2, NULL, 0, NULL, &size); ok(!ret && GetLastError() == E_INVALIDARG, "expected E_INVALIDARG, got %d\n", GetLastError()); }
static void test_verifyRevocation(void) { HMODULE hCryptNet = GetModuleHandleA("cryptnet.dll"); BOOL ret; CERT_REVOCATION_STATUS status = { sizeof(status), 0 }; PCCERT_CONTEXT certs[2]; CERT_REVOCATION_PARA revPara = { sizeof(revPara), 0 }; FILETIME time; pCertVerifyRevocation = (void *)GetProcAddress(hCryptNet, "CertDllVerifyRevocation"); if (!pCertVerifyRevocation) { win_skip("no CertDllVerifyRevocation\n"); return; } if (0) { /* Crash */ pCertVerifyRevocation(0, 0, 0, NULL, 0, NULL, NULL); } SetLastError(0xdeadbeef); ret = pCertVerifyRevocation(0, 0, 0, NULL, 0, NULL, &status); ok(!ret && GetLastError() == E_INVALIDARG, "expected E_INVALIDARG, got %08x\n", GetLastError()); SetLastError(0xdeadbeef); ret = pCertVerifyRevocation(X509_ASN_ENCODING, 0, 0, NULL, 0, NULL, &status); ok(!ret && GetLastError() == E_INVALIDARG, "expected E_INVALIDARG, got %08x\n", GetLastError()); SetLastError(0xdeadbeef); ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE, 0, NULL, 0, NULL, &status); ok(!ret && GetLastError() == E_INVALIDARG, "expected E_INVALIDARG, got %08x\n", GetLastError()); certs[0] = CertCreateCertificateContext(X509_ASN_ENCODING, bigCert, sizeof(bigCert)); SetLastError(0xdeadbeef); ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE, 1, (void **)certs, 0, NULL, &status); ok(!ret && GetLastError() == CRYPT_E_NO_REVOCATION_CHECK, "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError()); ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK, "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status.dwError); ok(status.dwIndex == 0, "expected index 0, got %d\n", status.dwIndex); CertFreeCertificateContext(certs[0]); certs[0] = CertCreateCertificateContext(X509_ASN_ENCODING, rootWithKeySignAndCRLSign, sizeof(rootWithKeySignAndCRLSign)); certs[1] = CertCreateCertificateContext(X509_ASN_ENCODING, revokedCert, sizeof(revokedCert)); /* The root cert itself can't be checked for revocation */ SetLastError(0xdeadbeef); ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE, 1, (void **)certs, 0, NULL, &status); ok(!ret && GetLastError() == CRYPT_E_NO_REVOCATION_CHECK, "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError()); ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK, "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status.dwError); ok(status.dwIndex == 0, "expected index 0, got %d\n", status.dwIndex); /* Neither can the end cert */ SetLastError(0xdeadbeef); ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE, 1, (void **)&certs[1], 0, NULL, &status); ok(!ret && GetLastError() == CRYPT_E_NO_REVOCATION_CHECK, "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError()); ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK, "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status.dwError); ok(status.dwIndex == 0, "expected index 0, got %d\n", status.dwIndex); /* Both certs together can't, either (they're not CRLs) */ SetLastError(0xdeadbeef); ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE, 2, (void **)certs, 0, NULL, &status); ok(!ret && GetLastError() == CRYPT_E_NO_REVOCATION_CHECK, "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError()); ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK, "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status.dwError); ok(status.dwIndex == 0, "expected index 0, got %d\n", status.dwIndex); /* Now add a CRL to the hCrlStore */ revPara.hCrlStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0, CERT_STORE_CREATE_NEW_FLAG, NULL); CertAddEncodedCRLToStore(revPara.hCrlStore, X509_ASN_ENCODING, rootSignedCRLWithBadAKI, sizeof(rootSignedCRLWithBadAKI), CERT_STORE_ADD_ALWAYS, NULL); SetLastError(0xdeadbeef); ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE, 2, (void **)certs, 0, &revPara, &status); ok(!ret && GetLastError() == CRYPT_E_NO_REVOCATION_CHECK, "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError()); ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK, "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status.dwError); ok(status.dwIndex == 0, "expected index 0, got %d\n", status.dwIndex); /* Specifying CERT_VERIFY_REV_CHAIN_FLAG doesn't change things either */ SetLastError(0xdeadbeef); ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE, 2, (void **)certs, CERT_VERIFY_REV_CHAIN_FLAG, &revPara, &status); ok(!ret && GetLastError() == CRYPT_E_NO_REVOCATION_CHECK, "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError()); ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK, "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status.dwError); ok(status.dwIndex == 0, "expected index 0, got %d\n", status.dwIndex); /* Again, specifying the issuer cert: no change */ revPara.pIssuerCert = certs[0]; SetLastError(0xdeadbeef); ret = CertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE, 1, (void **)&certs[1], 0, &revPara, &status); /* Win2k thinks the cert is revoked, and it is, except the CRL contains a * bad authority key ID extension and can't be matched with the issuer * cert, hence the revocation status should be unknown. */ if (!ret && GetLastError() == ERROR_FILE_NOT_FOUND) { win_skip("CERT_CONTEXT_REVOCATION_TYPE unsupported, skipping\n"); return; } ok(!ret && (GetLastError() == CRYPT_E_NO_REVOCATION_CHECK || broken(GetLastError() == CRYPT_E_REVOKED /* Win2k */)), "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError()); ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK || broken(status.dwError == CRYPT_E_REVOKED /* Win2k */), "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status.dwError); ok(status.dwIndex == 0, "expected index 0, got %d\n", status.dwIndex); /* Specifying the time to check: still no change */ SystemTimeToFileTime(&oct2007, &time); revPara.pftTimeToUse = &time; ret = pCertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE, 1, (void **)&certs[1], 0, &revPara, &status); ok(!ret, "Expected failure\n"); ok(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK || broken(GetLastError() == CRYPT_E_REVOKED), /* W2K SP3/SP4 */ "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", GetLastError()); ok(status.dwError == CRYPT_E_NO_REVOCATION_CHECK || broken(GetLastError() == CRYPT_E_REVOKED), /* W2K SP3/SP4 */ "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status.dwError); ok(status.dwIndex == 0, "expected index 0, got %d\n", status.dwIndex); CertCloseStore(revPara.hCrlStore, 0); /* Test again with a valid CRL. This time, the cert should be revoked when * the time is after the validity period of the CRL, or considered * "revocation offline" when the checked time precedes the validity * period of the CRL. */ revPara.hCrlStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0, CERT_STORE_CREATE_NEW_FLAG, NULL); ret = CertAddEncodedCRLToStore(revPara.hCrlStore, X509_ASN_ENCODING, rootSignedCRL, sizeof(rootSignedCRL), CERT_STORE_ADD_ALWAYS, NULL); ok(ret, "CertAddEncodedCRLToStore failed: %08x\n", GetLastError()); revPara.pftTimeToUse = NULL; SetLastError(0xdeadbeef); ret = CertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE, 1, (void **)&certs[1], 0, &revPara, &status); ok(!ret && (GetLastError() == CRYPT_E_REVOKED || broken(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK /* NT4 */)), "expected CRYPT_E_REVOKED, got %08x\n", GetLastError()); revPara.pftTimeToUse = &time; SetLastError(0xdeadbeef); ret = CertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE, 1, (void **)&certs[1], 0, &revPara, &status); ok(!ret && (GetLastError() == CRYPT_E_REVOKED || broken(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK /* NT4 */)), "expected CRYPT_E_REVOKED, got %08x\n", GetLastError()); SystemTimeToFileTime(&may2007, &time); SetLastError(0xdeadbeef); ret = CertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE, 1, (void **)&certs[1], 0, &revPara, &status); ok(!ret && (GetLastError() == CRYPT_E_REVOCATION_OFFLINE || broken(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK /* NT4 */)), "expected CRYPT_E_REVOCATION_OFFLINE, got %08x\n", GetLastError()); CertFreeCertificateContext(certs[1]); /* Test again with a valid CRL and an un-revoked cert. No matter the * time checked, it's reported as revocation offline. */ certs[1] = CertCreateCertificateContext(X509_ASN_ENCODING, unRevokedCert, sizeof(unRevokedCert)); ok(certs[1] != NULL, "CertCreateCertificateContext failed: %08x\n", GetLastError()); revPara.pftTimeToUse = NULL; SetLastError(0xdeadbeef); ret = CertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE, 1, (void **)&certs[1], 0, &revPara, &status); ok(!ret && (GetLastError() == CRYPT_E_REVOCATION_OFFLINE || broken(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK /* NT4 */)), "expected CRYPT_E_REVOCATION_OFFLINE, got %08x\n", GetLastError()); revPara.pftTimeToUse = &time; SetLastError(0xdeadbeef); ret = CertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE, 1, (void **)&certs[1], 0, &revPara, &status); ok(!ret && (GetLastError() == CRYPT_E_REVOCATION_OFFLINE || broken(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK /* NT4 */)), "expected CRYPT_E_REVOCATION_OFFLINE, got %08x\n", GetLastError()); SystemTimeToFileTime(&may2007, &time); SetLastError(0xdeadbeef); ret = CertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE, 1, (void **)&certs[1], 0, &revPara, &status); ok(!ret && (GetLastError() == CRYPT_E_REVOCATION_OFFLINE || broken(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK /* NT4 */)), "expected CRYPT_E_REVOCATION_OFFLINE, got %08x\n", GetLastError()); CertCloseStore(revPara.hCrlStore, 0); CertFreeCertificateContext(certs[1]); CertFreeCertificateContext(certs[0]); }
static void test_retrieveObjectByUrl(void) { BOOL ret; char tmpfile[MAX_PATH * 2], url[MAX_PATH + 8]; CRYPT_BLOB_ARRAY *pBlobArray; PCCERT_CONTEXT cert; PCCRL_CONTEXT crl; HCERTSTORE store; CRYPT_RETRIEVE_AUX_INFO aux = { 0 }; FILETIME ft = { 0 }; SetLastError(0xdeadbeef); ret = CryptRetrieveObjectByUrlA(NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL); ok(!ret && (GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == E_INVALIDARG), "got 0x%x/%u (expected ERROR_INVALID_PARAMETER or E_INVALIDARG)\n", GetLastError(), GetLastError()); make_tmp_file(tmpfile); snprintf(url, sizeof(url), "file://%s", tmpfile); pBlobArray = (CRYPT_BLOB_ARRAY *)0xdeadbeef; ret = CryptRetrieveObjectByUrlA(url, NULL, 0, 0, (void **)&pBlobArray, NULL, NULL, NULL, NULL); if (!ret) { /* File URL support was apparently removed in Vista/Windows 2008 */ win_skip("File URLs not supported\n"); return; } ok(ret, "CryptRetrieveObjectByUrlA failed: %d\n", GetLastError()); ok(pBlobArray && pBlobArray != (CRYPT_BLOB_ARRAY *)0xdeadbeef, "Expected a valid pointer\n"); if (pBlobArray && pBlobArray != (CRYPT_BLOB_ARRAY *)0xdeadbeef) { ok(pBlobArray->cBlob == 1, "Expected 1 blob, got %d\n", pBlobArray->cBlob); ok(pBlobArray->rgBlob[0].cbData == sizeof(certWithCRLDistPoint), "Unexpected size %d\n", pBlobArray->rgBlob[0].cbData); CryptMemFree(pBlobArray); } cert = (PCCERT_CONTEXT)0xdeadbeef; ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CERTIFICATE, 0, 0, (void **)&cert, NULL, NULL, NULL, NULL); ok(ret, "CryptRetrieveObjectByUrlA failed: %d\n", GetLastError()); ok(cert && cert != (PCCERT_CONTEXT)0xdeadbeef, "Expected a cert\n"); if (cert && cert != (PCCERT_CONTEXT)0xdeadbeef) CertFreeCertificateContext(cert); crl = (PCCRL_CONTEXT)0xdeadbeef; SetLastError(0xdeadbeef); ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CRL, 0, 0, (void **)&crl, NULL, NULL, NULL, NULL); /* w2k3,XP, newer w2k: CRYPT_E_NO_MATCH, older w2k: CRYPT_E_ASN1_BADTAG * or OSS_DATA_ERROR. */ ok(!ret && (GetLastError() == CRYPT_E_NO_MATCH || broken(GetLastError() == CRYPT_E_ASN1_BADTAG || GetLastError() == OSS_DATA_ERROR)), "got 0x%x/%u (expected CRYPT_E_NO_MATCH)\n", GetLastError(), GetLastError()); /* only newer versions of cryptnet do the cleanup */ if(!ret && GetLastError() != CRYPT_E_ASN1_BADTAG && GetLastError() != OSS_DATA_ERROR) { ok(crl == NULL, "Expected CRL to be NULL\n"); } if (crl && crl != (PCCRL_CONTEXT)0xdeadbeef) CertFreeCRLContext(crl); store = (HCERTSTORE)0xdeadbeef; ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CAPI2_ANY, 0, 0, &store, NULL, NULL, NULL, NULL); ok(ret, "CryptRetrieveObjectByUrlA failed: %d\n", GetLastError()); if (store && store != (HCERTSTORE)0xdeadbeef) { DWORD certs = 0; cert = NULL; do { cert = CertEnumCertificatesInStore(store, cert); if (cert) certs++; } while (cert); ok(certs == 1, "Expected 1 cert, got %d\n", certs); CertCloseStore(store, 0); } /* Are file URLs cached? */ cert = (PCCERT_CONTEXT)0xdeadbeef; ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CERTIFICATE, CRYPT_CACHE_ONLY_RETRIEVAL, 0, (void **)&cert, NULL, NULL, NULL, NULL); ok(ret, "CryptRetrieveObjectByUrlA failed: %08x\n", GetLastError()); if (cert && cert != (PCCERT_CONTEXT)0xdeadbeef) CertFreeCertificateContext(cert); cert = (PCCERT_CONTEXT)0xdeadbeef; ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CERTIFICATE, 0, 0, (void **)&cert, NULL, NULL, NULL, &aux); /* w2k: failure with E_INVALIDARG */ ok(ret || broken(GetLastError() == E_INVALIDARG), "got %u with 0x%x/%u (expected '!=0' or '0' with E_INVALIDARG)\n", ret, GetLastError(), GetLastError()); if (cert && cert != (PCCERT_CONTEXT)0xdeadbeef) CertFreeCertificateContext(cert); cert = (PCCERT_CONTEXT)0xdeadbeef; aux.cbSize = sizeof(aux); ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CERTIFICATE, 0, 0, (void **)&cert, NULL, NULL, NULL, &aux); /* w2k: failure with E_INVALIDARG */ ok(ret || broken(GetLastError() == E_INVALIDARG), "got %u with 0x%x/%u (expected '!=0' or '0' with E_INVALIDARG)\n", ret, GetLastError(), GetLastError()); if (!ret) { /* no more tests useful */ DeleteFileA(tmpfile); skip("no usable CertificateContext\n"); return; } CertFreeCertificateContext(cert); aux.pLastSyncTime = &ft; ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CERTIFICATE, 0, 0, (void **)&cert, NULL, NULL, NULL, &aux); ok(ret, "CryptRetrieveObjectByUrlA failed: %08x\n", GetLastError()); CertFreeCertificateContext(cert); ok(ft.dwLowDateTime || ft.dwHighDateTime, "Expected last sync time to be set\n"); DeleteFileA(tmpfile); /* Okay, after being deleted, are file URLs still cached? */ SetLastError(0xdeadbeef); ret = CryptRetrieveObjectByUrlA(url, CONTEXT_OID_CERTIFICATE, CRYPT_CACHE_ONLY_RETRIEVAL, 0, (void **)&cert, NULL, NULL, NULL, NULL); ok(!ret && (GetLastError() == ERROR_FILE_NOT_FOUND || GetLastError() == ERROR_PATH_NOT_FOUND), "Expected ERROR_FILE_NOT_FOUND or ERROR_PATH_NOT_FOUND, got %d\n", GetLastError()); }
static void test_StrXXX_overflows(void) { CHAR str1[2*MAX_PATH+1], buf[2*MAX_PATH]; WCHAR wstr1[2*MAX_PATH+1], wbuf[2*MAX_PATH]; const WCHAR fmt[] = {'%','s',0}; STRRET strret; int ret; int i; for (i=0; i<2*MAX_PATH; i++) { str1[i] = '0'+(i%10); wstr1[i] = '0'+(i%10); } str1[2*MAX_PATH] = 0; wstr1[2*MAX_PATH] = 0; memset(buf, 0xbf, sizeof(buf)); expect_eq(StrCpyNA(buf, str1, 10), buf, PCHAR, "%p"); expect_eq(buf[9], 0, CHAR, "%x"); expect_eq(buf[10], '\xbf', CHAR, "%x"); if (pStrCatBuffA) { expect_eq(pStrCatBuffA(buf, str1, 100), buf, PCHAR, "%p"); expect_eq(buf[99], 0, CHAR, "%x"); expect_eq(buf[100], '\xbf', CHAR, "%x"); } else win_skip("StrCatBuffA() is not available\n"); if (0) { /* crashes on XP */ StrCpyNW(wbuf, (LPCWSTR)0x1, 10); StrCpyNW((LPWSTR)0x1, wstr1, 10); } memset(wbuf, 0xbf, sizeof(wbuf)); expect_eq(StrCpyNW(wbuf, (LPCWSTR)0x1, 1), wbuf, PWCHAR, "%p"); expect_eq(wbuf[0], 0, WCHAR, "%x"); expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x"); memset(wbuf, 0xbf, sizeof(wbuf)); expect_eq(StrCpyNW(wbuf, 0, 10), wbuf, PWCHAR, "%p"); expect_eq(wbuf[0], 0, WCHAR, "%x"); expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x"); memset(wbuf, 0xbf, sizeof(wbuf)); expect_eq(StrCpyNW(wbuf, 0, 0), wbuf, PWCHAR, "%p"); expect_eq(wbuf[0], (WCHAR)0xbfbf, WCHAR, "%x"); expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x"); memset(wbuf, 0xbf, sizeof(wbuf)); expect_eq(StrCpyNW(wbuf, wstr1, 0), wbuf, PWCHAR, "%p"); expect_eq(wbuf[0], (WCHAR)0xbfbf, WCHAR, "%x"); expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x"); memset(wbuf, 0xbf, sizeof(wbuf)); expect_eq(StrCpyNW(wbuf, wstr1, 10), wbuf, PWCHAR, "%p"); expect_eq(wbuf[9], 0, WCHAR, "%x"); expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x"); if (pStrCatBuffW) { expect_eq(pStrCatBuffW(wbuf, wstr1, 100), wbuf, PWCHAR, "%p"); expect_eq(wbuf[99], 0, WCHAR, "%x"); expect_eq(wbuf[100], (WCHAR)0xbfbf, WCHAR, "%x"); } else win_skip("StrCatBuffW() is not available\n"); if (pStrRetToBufW) { memset(wbuf, 0xbf, sizeof(wbuf)); strret.uType = STRRET_WSTR; U(strret).pOleStr = StrDupW(wstr1); expect_eq2(pStrRetToBufW(&strret, NULL, wbuf, 10), S_OK, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) /* Vista */, HRESULT, "%x"); expect_eq(wbuf[9], 0, WCHAR, "%x"); expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x"); } else win_skip("StrRetToBufW() is not available\n"); if (pStrRetToBufA) { memset(buf, 0xbf, sizeof(buf)); strret.uType = STRRET_CSTR; StrCpyN(U(strret).cStr, str1, MAX_PATH); expect_eq2(pStrRetToBufA(&strret, NULL, buf, 10), S_OK, HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) /* Vista */, HRESULT, "%x"); expect_eq(buf[9], 0, CHAR, "%x"); expect_eq(buf[10], (CHAR)0xbf, CHAR, "%x"); } else win_skip("StrRetToBufA() is not available\n"); if (pwnsprintfA) { memset(buf, 0xbf, sizeof(buf)); ret = pwnsprintfA(buf, 10, "%s", str1); ok(broken(ret == 9) || ret == -1 /* Vista */, "Unexpected wnsprintfA return %d, expected 9 or -1\n", ret); expect_eq(buf[9], 0, CHAR, "%x"); expect_eq(buf[10], (CHAR)0xbf, CHAR, "%x"); } else win_skip("wnsprintfA() is not available\n"); if (pwnsprintfW) { memset(wbuf, 0xbf, sizeof(wbuf)); ret = pwnsprintfW(wbuf, 10, fmt, wstr1); ok(broken(ret == 9) || ret == -1 /* Vista */, "Unexpected wnsprintfW return %d, expected 9 or -1\n", ret); expect_eq(wbuf[9], 0, WCHAR, "%x"); expect_eq(wbuf[10], (WCHAR)0xbfbf, WCHAR, "%x"); } else win_skip("wnsprintfW() is not available\n"); }
static void test_SetupQuerySpaceRequiredOnDriveW(void) { static const WCHAR emptyW[] = {0}; BOOL ret; HDSKSPC handle; LONGLONG space; SetLastError(0xdeadbeef); ret = SetupQuerySpaceRequiredOnDriveW(NULL, NULL, NULL, NULL, 0); if (!ret && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) { win_skip("SetupQuerySpaceRequiredOnDriveW is not available\n"); return; } ok(!ret, "Expected SetupQuerySpaceRequiredOnDriveW to return FALSE, got %d\n", ret); ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected GetLastError() to return ERROR_INVALID_HANDLE, got %u\n", GetLastError()); SetLastError(0xdeadbeef); space = 0xdeadbeef; ret = SetupQuerySpaceRequiredOnDriveW(NULL, NULL, &space, NULL, 0); ok(!ret, "Expected SetupQuerySpaceRequiredOnDriveW to return FALSE, got %d\n", ret); ok(space == 0xdeadbeef, "Expected output space parameter to be untouched\n"); ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected GetLastError() to return ERROR_INVALID_HANDLE, got %u\n", GetLastError()); SetLastError(0xdeadbeef); ret = SetupQuerySpaceRequiredOnDriveW(NULL, emptyW, NULL, NULL, 0); ok(!ret, "Expected SetupQuerySpaceRequiredOnDriveW to return FALSE, got %d\n", ret); ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected GetLastError() to return ERROR_INVALID_HANDLE, got %u\n", GetLastError()); SetLastError(0xdeadbeef); space = 0xdeadbeef; ret = SetupQuerySpaceRequiredOnDriveW(NULL, emptyW, &space, NULL, 0); ok(!ret, "Expected SetupQuerySpaceRequiredOnDriveW to return FALSE, got %d\n", ret); ok(space == 0xdeadbeef, "Expected output space parameter to be untouched\n"); ok(GetLastError() == ERROR_INVALID_HANDLE, "Expected GetLastError() to return ERROR_INVALID_HANDLE, got %u\n", GetLastError()); handle = SetupCreateDiskSpaceListA(NULL, 0, 0); ok(handle != NULL, "Expected SetupCreateDiskSpaceListA to return a valid handle, got NULL\n"); SetLastError(0xdeadbeef); ret = SetupQuerySpaceRequiredOnDriveW(handle, NULL, NULL, NULL, 0); ok(!ret, "Expected SetupQuerySpaceRequiredOnDriveW to return FALSE, got %d\n", ret); ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INVALID_DRIVE, /* NT4/Win2k/XP/Win2k3 */ "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); SetLastError(0xdeadbeef); space = 0xdeadbeef; ret = SetupQuerySpaceRequiredOnDriveW(handle, NULL, &space, NULL, 0); ok(!ret, "Expected SetupQuerySpaceRequiredOnDriveW to return FALSE, got %d\n", ret); ok(space == 0xdeadbeef, "Expected output space parameter to be untouched\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INVALID_DRIVE, /* NT4/Win2k/XP/Win2k3 */ "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); SetLastError(0xdeadbeef); ret = SetupQuerySpaceRequiredOnDriveW(handle, emptyW, NULL, NULL, 0); ok(!ret, "Expected SetupQuerySpaceRequiredOnDriveW to return FALSE, got %d\n", ret); ok(GetLastError() == ERROR_INVALID_DRIVE, "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); SetLastError(0xdeadbeef); space = 0xdeadbeef; ret = SetupQuerySpaceRequiredOnDriveW(handle, emptyW, &space, NULL, 0); ok(!ret, "Expected SetupQuerySpaceRequiredOnDriveW to return FALSE, got %d\n", ret); ok(space == 0xdeadbeef, "Expected output space parameter to be untouched\n"); ok(GetLastError() == ERROR_INVALID_DRIVE, "Expected GetLastError() to return ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); ok(SetupDestroyDiskSpaceList(handle), "Expected SetupDestroyDiskSpaceList to succeed\n"); }
static void test_WM_LBUTTONDOWN(void) { HWND hCombo, hEdit, hList; COMBOBOXINFO cbInfo; UINT x, y, item_height; LRESULT result; int i, idx; RECT rect; CHAR buffer[3]; static const UINT choices[] = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72}; static const CHAR stringFormat[] = "%2d"; BOOL ret; BOOL (WINAPI *pGetComboBoxInfo)(HWND, PCOMBOBOXINFO); pGetComboBoxInfo = (void*)GetProcAddress(GetModuleHandleA("user32.dll"), "GetComboBoxInfo"); if (!pGetComboBoxInfo){ win_skip("GetComboBoxInfo is not available\n"); return; } hCombo = CreateWindow("ComboBox", "Combo", WS_VISIBLE|WS_CHILD|CBS_DROPDOWN, 0, 0, 200, 150, hMainWnd, (HMENU)COMBO_ID, NULL, 0); for (i = 0; i < sizeof(choices)/sizeof(UINT); i++){ sprintf(buffer, stringFormat, choices[i]); result = SendMessageA(hCombo, CB_ADDSTRING, 0, (LPARAM)buffer); ok(result == i, "Failed to add item %d\n", i); } cbInfo.cbSize = sizeof(COMBOBOXINFO); SetLastError(0xdeadbeef); ret = pGetComboBoxInfo(hCombo, &cbInfo); ok(ret, "Failed to get combobox info structure. LastError=%d\n", GetLastError()); hEdit = cbInfo.hwndItem; hList = cbInfo.hwndList; trace("hMainWnd=%p, hCombo=%p, hList=%p, hEdit=%p\n", hMainWnd, hCombo, hList, hEdit); ok(GetFocus() == hMainWnd, "Focus not on Main Window, instead on %p\n", GetFocus()); /* Click on the button to drop down the list */ x = cbInfo.rcButton.left + (cbInfo.rcButton.right-cbInfo.rcButton.left)/2; y = cbInfo.rcButton.top + (cbInfo.rcButton.bottom-cbInfo.rcButton.top)/2; result = SendMessage(hCombo, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y)); ok(result, "WM_LBUTTONDOWN was not processed. LastError=%d\n", GetLastError()); ok(SendMessage(hCombo, CB_GETDROPPEDSTATE, 0, 0), "The dropdown list should have appeared after clicking the button.\n"); ok(GetFocus() == hEdit, "Focus not on ComboBox's Edit Control, instead on %p\n", GetFocus()); result = SendMessage(hCombo, WM_LBUTTONUP, 0, MAKELPARAM(x, y)); ok(result, "WM_LBUTTONUP was not processed. LastError=%d\n", GetLastError()); ok(GetFocus() == hEdit, "Focus not on ComboBox's Edit Control, instead on %p\n", GetFocus()); /* Click on the 5th item in the list */ item_height = SendMessage(hCombo, CB_GETITEMHEIGHT, 0, 0); ok(GetClientRect(hList, &rect), "Failed to get list's client rect.\n"); x = rect.left + (rect.right-rect.left)/2; y = item_height/2 + item_height*4; result = SendMessage(hList, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y)); ok(!result, "WM_LBUTTONDOWN was not processed. LastError=%d\n", GetLastError()); ok(GetFocus() == hEdit, "Focus not on ComboBox's Edit Control, instead on %p\n", GetFocus()); result = SendMessage(hList, WM_MOUSEMOVE, 0, MAKELPARAM(x, y)); ok(!result, "WM_MOUSEMOVE was not processed. LastError=%d\n", GetLastError()); ok(GetFocus() == hEdit, "Focus not on ComboBox's Edit Control, instead on %p\n", GetFocus()); ok(SendMessage(hCombo, CB_GETDROPPEDSTATE, 0, 0), "The dropdown list should still be visible.\n"); result = SendMessage(hList, WM_LBUTTONUP, 0, MAKELPARAM(x, y)); ok(!result, "WM_LBUTTONUP was not processed. LastError=%d\n", GetLastError()); ok(GetFocus() == hEdit, "Focus not on ComboBox's Edit Control, instead on %p\n", GetFocus()); ok(!SendMessage(hCombo, CB_GETDROPPEDSTATE, 0, 0), "The dropdown list should have been rolled up.\n"); idx = SendMessage(hCombo, CB_GETCURSEL, 0, 0); ok(idx, "Current Selection: expected %d, got %d\n", 4, idx); DestroyWindow(hCombo); }
static void test_register(void) { static WCHAR name[] = {'W','i','n','e',' ','t','e','s','t',0}; MFT_REGISTER_TYPE_INFO input[] = { { DUMMY_CLSID, DUMMY_GUID1 } }; MFT_REGISTER_TYPE_INFO output[] = { { DUMMY_CLSID, DUMMY_GUID2 } }; CLSID *clsids; UINT32 count; HRESULT ret; ret = MFTRegister(DUMMY_CLSID, MFT_CATEGORY_OTHER, name, 0, 1, input, 1, output, NULL); if (ret == E_ACCESSDENIED) { win_skip("Not enough permissions to register a filter\n"); return; } ok(ret == S_OK, "Failed to register dummy filter: %x\n", ret); if(0) { /* NULL name crashes on windows */ ret = MFTRegister(DUMMY_CLSID, MFT_CATEGORY_OTHER, NULL, 0, 1, input, 1, output, NULL); ok(ret == E_INVALIDARG, "got %x\n", ret); } ret = MFTRegister(DUMMY_CLSID, MFT_CATEGORY_OTHER, name, 0, 0, NULL, 0, NULL, NULL); ok(ret == S_OK, "Failed to register dummy filter: %x\n", ret); ret = MFTRegister(DUMMY_CLSID, MFT_CATEGORY_OTHER, name, 0, 1, NULL, 0, NULL, NULL); ok(ret == S_OK, "Failed to register dummy filter: %x\n", ret); ret = MFTRegister(DUMMY_CLSID, MFT_CATEGORY_OTHER, name, 0, 0, NULL, 1, NULL, NULL); ok(ret == S_OK, "Failed to register dummy filter: %x\n", ret); if(0) { /* NULL clsids/count crashes on windows (vista) */ count = 0; ret = MFTEnum(MFT_CATEGORY_OTHER, 0, NULL, NULL, NULL, NULL, &count); ok(ret == E_POINTER, "Failed to enumerate filters: %x\n", ret); ok(count == 0, "Expected count > 0\n"); clsids = NULL; ret = MFTEnum(MFT_CATEGORY_OTHER, 0, NULL, NULL, NULL, &clsids, NULL); ok(ret == E_POINTER, "Failed to enumerate filters: %x\n", ret); ok(count == 0, "Expected count > 0\n"); } count = 0; clsids = NULL; ret = MFTEnum(MFT_CATEGORY_OTHER, 0, NULL, NULL, NULL, &clsids, &count); ok(ret == S_OK, "Failed to enumerate filters: %x\n", ret); ok(count > 0, "Expected count > 0\n"); ok(clsids != NULL, "Expected clsids != NULL\n"); ok(check_clsid(clsids, count), "Filter was not part of enumeration\n"); CoTaskMemFree(clsids); count = 0; clsids = NULL; ret = MFTEnum(MFT_CATEGORY_OTHER, 0, input, NULL, NULL, &clsids, &count); ok(ret == S_OK, "Failed to enumerate filters: %x\n", ret); ok(count > 0, "Expected count > 0\n"); ok(clsids != NULL, "Expected clsids != NULL\n"); ok(check_clsid(clsids, count), "Filter was not part of enumeration\n"); CoTaskMemFree(clsids); count = 0; clsids = NULL; ret = MFTEnum(MFT_CATEGORY_OTHER, 0, NULL, output, NULL, &clsids, &count); ok(ret == S_OK, "Failed to enumerate filters: %x\n", ret); ok(count > 0, "Expected count > 0\n"); ok(clsids != NULL, "Expected clsids != NULL\n"); ok(check_clsid(clsids, count), "Filter was not part of enumeration\n"); CoTaskMemFree(clsids); count = 0; clsids = NULL; ret = MFTEnum(MFT_CATEGORY_OTHER, 0, input, output, NULL, &clsids, &count); ok(ret == S_OK, "Failed to enumerate filters: %x\n", ret); ok(count > 0, "Expected count > 0\n"); ok(clsids != NULL, "Expected clsids != NULL\n"); ok(check_clsid(clsids, count), "Filter was not part of enumeration\n"); CoTaskMemFree(clsids); /* exchange input and output */ count = 0; clsids = NULL; ret = MFTEnum(MFT_CATEGORY_OTHER, 0, output, input, NULL, &clsids, &count); ok(ret == S_OK, "Failed to enumerate filters: %x\n", ret); ok(!count, "got %d\n", count); ok(clsids == NULL, "Expected clsids == NULL\n"); ret = MFTUnregister(DUMMY_CLSID); ok(ret == S_OK || /* w7pro64 */ broken(ret == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)), "got %x\n", ret); ret = MFTUnregister(DUMMY_CLSID); ok(ret == S_OK || broken(ret == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)), "got %x\n", ret); }
static void test_xcvt(void) { char *str; int i, decpt, sign, err; for( i = 0; strcmp( test_cvt_testcases[i].expstr_e, "END"); i++){ decpt = sign = 100; str = _ecvt( test_cvt_testcases[i].value, test_cvt_testcases[i].nrdigits, &decpt, &sign); ok( 0 == strncmp( str, test_cvt_testcases[i].expstr_e, 15), "_ecvt() bad return, got \n'%s' expected \n'%s'\n", str, test_cvt_testcases[i].expstr_e); ok( decpt == test_cvt_testcases[i].expdecpt_e, "_ecvt() decimal point wrong, got %d expected %d\n", decpt, test_cvt_testcases[i].expdecpt_e); ok( sign == test_cvt_testcases[i].expsign, "_ecvt() sign wrong, got %d expected %d\n", sign, test_cvt_testcases[i].expsign); } for( i = 0; strcmp( test_cvt_testcases[i].expstr_e, "END"); i++){ decpt = sign = 100; str = _fcvt( test_cvt_testcases[i].value, test_cvt_testcases[i].nrdigits, &decpt, &sign); ok( 0 == strncmp( str, test_cvt_testcases[i].expstr_f, 15), "_fcvt() bad return, got \n'%s' expected \n'%s'\n", str, test_cvt_testcases[i].expstr_f); ok( decpt == test_cvt_testcases[i].expdecpt_f, "_fcvt() decimal point wrong, got %d expected %d\n", decpt, test_cvt_testcases[i].expdecpt_f); ok( sign == test_cvt_testcases[i].expsign, "_fcvt() sign wrong, got %d expected %d\n", sign, test_cvt_testcases[i].expsign); } if (p__ecvt_s) { str = malloc(1024); for( i = 0; strcmp( test_cvt_testcases[i].expstr_e, "END"); i++){ decpt = sign = 100; err = p__ecvt_s(str, 1024, test_cvt_testcases[i].value, test_cvt_testcases[i].nrdigits, &decpt, &sign); ok(err == 0, "_ecvt_s() failed with error code %d\n", err); ok( 0 == strncmp( str, test_cvt_testcases[i].expstr_e, 15), "_ecvt_s() bad return, got \n'%s' expected \n'%s'\n", str, test_cvt_testcases[i].expstr_e); ok( decpt == test_cvt_testcases[i].expdecpt_e, "_ecvt_s() decimal point wrong, got %d expected %d\n", decpt, test_cvt_testcases[i].expdecpt_e); ok( sign == test_cvt_testcases[i].expsign, "_ecvt_s() sign wrong, got %d expected %d\n", sign, test_cvt_testcases[i].expsign); } free(str); } else win_skip("_ecvt_s not available\n"); if (p__fcvt_s) { int i; str = malloc(1024); /* invalid arguments */ err = p__fcvt_s(NULL, 0, 0.0, 0, &i, &i); ok(err == EINVAL, "got %d, expected EINVAL\n", err); err = p__fcvt_s(str, 0, 0.0, 0, &i, &i); ok(err == EINVAL, "got %d, expected EINVAL\n", err); str[0] = ' '; str[1] = 0; err = p__fcvt_s(str, -1, 0.0, 0, &i, &i); ok(err == 0, "got %d, expected 0\n", err); ok(str[0] == 0, "got %c, expected 0\n", str[0]); ok(str[1] == 0, "got %c, expected 0\n", str[1]); err = p__fcvt_s(str, 1, 0.0, 0, NULL, &i); ok(err == EINVAL, "got %d, expected EINVAL\n", err); err = p__fcvt_s(str, 1, 0.0, 0, &i, NULL); ok(err == EINVAL, "got %d, expected EINVAL\n", err); for( i = 0; strcmp( test_cvt_testcases[i].expstr_e, "END"); i++){ decpt = sign = 100; err = p__fcvt_s(str, 1024, test_cvt_testcases[i].value, test_cvt_testcases[i].nrdigits, &decpt, &sign); ok(err == 0, "_fcvt_s() failed with error code %d\n", err); ok( 0 == strncmp( str, test_cvt_testcases[i].expstr_f, 15), "_fcvt_s() bad return, got '%s' expected '%s'. test %d\n", str, test_cvt_testcases[i].expstr_f, i); ok( decpt == test_cvt_testcases[i].expdecpt_f, "_fcvt_s() decimal point wrong, got %d expected %d\n", decpt, test_cvt_testcases[i].expdecpt_f); ok( sign == test_cvt_testcases[i].expsign, "_fcvt_s() sign wrong, got %d expected %d\n", sign, test_cvt_testcases[i].expsign); } free(str); } else win_skip("_fcvt_s not available\n"); }
static void translateinfstring_test(void) { HRESULT hr; char buffer[MAX_PATH]; DWORD dwSize; create_inf_file(); /* pass in a couple invalid parameters */ hr = pTranslateInfString(NULL, NULL, NULL, NULL, buffer, MAX_PATH, &dwSize, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", (UINT)hr); /* try to open an inf file that doesn't exist */ hr = pTranslateInfString("c:\\a.inf", "Options.NTx86", "Options.NTx86", "InstallDir", buffer, MAX_PATH, &dwSize, NULL); ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) || hr == E_INVALIDARG || hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND), "Expected E_INVALIDARG, 0x80070002 or 0x8007007e, got 0x%08x\n", (UINT)hr); if(hr == HRESULT_FROM_WIN32(ERROR_MOD_NOT_FOUND)) { win_skip("WinNT 3.51 detected. Skipping tests for TranslateInfString()\n"); return; } /* try a nonexistent section */ buffer[0] = 0; hr = pTranslateInfString(inf_file, "idontexist", "Options.NTx86", "InstallDir", buffer, MAX_PATH, &dwSize, NULL); if (hr == E_ACCESSDENIED) { skip("TranslateInfString is broken\n"); return; } ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr); ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer); ok(dwSize == 25, "Expected size 25, got %d\n", dwSize); buffer[0] = 0; /* try other nonexistent section */ hr = pTranslateInfString(inf_file, "Options.NTx86", "idontexist", "InstallDir", buffer, MAX_PATH, &dwSize, NULL); ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG, "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr); buffer[0] = 0; /* try nonexistent key */ hr = pTranslateInfString(inf_file, "Options.NTx86", "Options.NTx86", "notvalid", buffer, MAX_PATH, &dwSize, NULL); ok(hr == SPAPI_E_LINE_NOT_FOUND || hr == E_INVALIDARG, "Expected SPAPI_E_LINE_NOT_FOUND or E_INVALIDARG, got 0x%08x\n", (UINT)hr); buffer[0] = 0; /* test the behavior of pszInstallSection */ hr = pTranslateInfString(inf_file, "section", "Options.NTx86", "InstallDir", buffer, MAX_PATH, &dwSize, NULL); ok(hr == ERROR_SUCCESS || hr == E_FAIL, "Expected ERROR_SUCCESS or E_FAIL, got 0x%08x\n", (UINT)hr); if(hr == ERROR_SUCCESS) { ok(!strcmp(buffer, APP_PATH), "Expected '%s', got '%s'\n", APP_PATH, buffer); ok(dwSize == APP_PATH_LEN, "Expected size %d, got %d\n", APP_PATH_LEN, dwSize); } buffer[0] = 0; /* try without a pszInstallSection */ hr = pTranslateInfString(inf_file, NULL, "Options.NTx86", "InstallDir", buffer, MAX_PATH, &dwSize, NULL); ok(hr == S_OK, "Expected S_OK, got 0x%08x\n", (UINT)hr); todo_wine { ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer); ok(dwSize == 25, "Expected size 25, got %d\n", dwSize); } DeleteFileA("c:\\a.inf"); DeleteFileA(inf_file); }
static void test_makepath_s(void) { WCHAR driveW[MAX_PATH]; WCHAR dirW[MAX_PATH]; WCHAR fileW[MAX_PATH]; WCHAR extW[MAX_PATH]; WCHAR bufferW[MAX_PATH]; char buffer[MAX_PATH]; int ret; unsigned int i, n; if (!p_makepath_s || !p_wmakepath_s) { win_skip("Safe makepath functions are not available\n"); return; } errno = EBADF; ret = p_makepath_s(NULL, 0, NULL, NULL, NULL, NULL); ok(ret == EINVAL, "Expected _makepath_s to return EINVAL, got %d\n", ret); ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno); errno = EBADF; ret = p_makepath_s(buffer, 0, NULL, NULL, NULL, NULL); ok(ret == EINVAL, "Expected _makepath_s to return EINVAL, got %d\n", ret); ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno); errno = EBADF; ret = p_wmakepath_s(NULL, 0, NULL, NULL, NULL, NULL); ok(ret == EINVAL, "Expected _wmakepath_s to return EINVAL, got %d\n", ret); ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno); errno = EBADF; ret = p_wmakepath_s(bufferW, 0, NULL, NULL, NULL, NULL); ok(ret == EINVAL, "Expected _wmakepath_s to return EINVAL, got %d\n", ret); ok(errno == EINVAL, "Expected errno to be EINVAL, got %d\n", errno); /* Test with the normal _makepath cases. */ for (i = 0; i < ARRAY_SIZE(makepath_cases); i++) { const makepath_case *p = makepath_cases + i; memset(buffer, 'X', MAX_PATH); if (p->buffer) strcpy(buffer, p->buffer); /* Ascii */ ret = p_makepath_s(buffer, MAX_PATH, p->drive == USE_BUFF ? buffer : p->drive, p->dir == USE_BUFF ? buffer : p->dir, p->file == USE_BUFF? buffer : p->file, p->ext == USE_BUFF ? buffer : p->ext); ok(ret == 0, "[%d] Expected _makepath_s to return 0, got %d\n", i, ret); buffer[MAX_PATH - 1] = '\0'; ok(!strcmp(p->expected, buffer), "got '%s' for case %d\n", buffer, i); /* Unicode */ if (p->drive != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->drive, -1, driveW, MAX_PATH); if (p->dir != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->dir, -1, dirW, MAX_PATH); if (p->file != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->file, -1, fileW, MAX_PATH); if (p->ext != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->ext, -1, extW, MAX_PATH); memset(buffer, 0, MAX_PATH); for (n = 0; n < MAX_PATH; ++n) bufferW[n] = 'X'; if (p->buffer) MultiByteToWideChar( CP_ACP, 0, p->buffer, -1, bufferW, MAX_PATH); ret = p_wmakepath_s(bufferW, MAX_PATH, p->drive == USE_BUFF ? bufferW : p->drive ? driveW : NULL, p->dir == USE_BUFF ? bufferW : p->dir ? dirW : NULL, p->file == USE_BUFF? bufferW : p->file ? fileW : NULL, p->ext == USE_BUFF ? bufferW : p->ext ? extW : NULL); ok(ret == 0, "[%d] Expected _wmakepath_s to return 0, got %d\n", i, ret); bufferW[MAX_PATH - 1] = '\0'; WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buffer, MAX_PATH, NULL, NULL); ok(!strcmp(p->expected, buffer), "got '%s' for unicode case %d\n", buffer, i); } /* Try insufficient length cases. */ for (i = 0; i < ARRAY_SIZE(makepath_s_cases); i++) { const makepath_s_case *p = makepath_s_cases + i; memset(buffer, 'X', MAX_PATH); if (p->buffer) strcpy(buffer, p->buffer); /* Ascii */ errno = EBADF; ret = p_makepath_s(buffer, p->length, p->drive == USE_BUFF ? buffer : p->drive, p->dir == USE_BUFF ? buffer : p->dir, p->file == USE_BUFF? buffer : p->file, p->ext == USE_BUFF ? buffer : p->ext); ok(ret == ERANGE, "[%d] Expected _makepath_s to return ERANGE, got %d\n", i, ret); ok(errno == ERANGE, "[%d] Expected errno to be ERANGE, got %d\n", i, errno); ok(!memcmp(p->expected, buffer, p->expected_length), "unexpected output for case %d\n", i); /* Unicode */ if (p->drive != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->drive, -1, driveW, MAX_PATH); if (p->dir != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->dir, -1, dirW, MAX_PATH); if (p->file != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->file, -1, fileW, MAX_PATH); if (p->ext != USE_BUFF) MultiByteToWideChar(CP_ACP, 0, p->ext, -1, extW, MAX_PATH); memset(buffer, 0, MAX_PATH); for (n = 0; n < MAX_PATH; ++n) bufferW[n] = 'X'; if (p->buffer) MultiByteToWideChar( CP_ACP, 0, p->buffer, -1, bufferW, MAX_PATH); errno = EBADF; ret = p_wmakepath_s(bufferW, p->length, p->drive == USE_BUFF ? bufferW : p->drive ? driveW : NULL, p->dir == USE_BUFF ? bufferW : p->dir ? dirW : NULL, p->file == USE_BUFF? bufferW : p->file ? fileW : NULL, p->ext == USE_BUFF ? bufferW : p->ext ? extW : NULL); ok(ret == ERANGE, "[%d] Expected _wmakepath_s to return ERANGE, got %d\n", i, ret); ok(errno == ERANGE, "[%d] Expected errno to be ERANGE, got %d\n", i, errno); ok(!memcmp(p->expected_unicode, bufferW, p->expected_length * sizeof(WCHAR)), "unexpected output for case %d\n", i); } }
static void translateinfstringex_test(void) { HINF hinf; HRESULT hr; char buffer[MAX_PATH]; DWORD size = MAX_PATH; hr = pOpenINFEngine(inf_file, NULL, 0, &hinf, NULL); if (hr == E_UNEXPECTED) { win_skip("Skipping tests on win9x because of brokenness\n"); return; } create_inf_file(); /* need to see if there are any flags */ /* try a NULL filename */ hr = pOpenINFEngine(NULL, "Options.NTx86", 0, &hinf, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* try an empty filename */ hr = pOpenINFEngine("", "Options.NTx86", 0, &hinf, NULL); ok(hr == HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND) /* NT+ */ || hr == HRESULT_FROM_WIN32(E_UNEXPECTED) /* 9x */, "Expected HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND or E_UNEXPECTED), got %08x\n", hr); /* try a NULL hinf */ hr = pOpenINFEngine(inf_file, "Options.NTx86", 0, NULL, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* open the INF without the Install section specified */ hr = pOpenINFEngine(inf_file, NULL, 0, &hinf, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); /* try a NULL hinf */ hr = pTranslateInfStringEx(NULL, inf_file, "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* try a NULL filename */ hr = pTranslateInfStringEx(hinf, NULL, "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* try an empty filename */ memset(buffer, 'a', 25); buffer[24] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, "", "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); todo_wine { ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer); ok(size == 25, "Expected size 25, got %d\n", size); } /* try a NULL translate section */ hr = pTranslateInfStringEx(hinf, inf_file, NULL, "InstallDir", buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* try an empty translate section */ hr = pTranslateInfStringEx(hinf, inf_file, "", "InstallDir", buffer, size, &size, NULL); ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08x\n", hr); /* try a NULL translate key */ hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", NULL, buffer, size, &size, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* try an empty translate key */ hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "", buffer, size, &size, NULL); ok(hr == SPAPI_E_LINE_NOT_FOUND, "Expected SPAPI_E_LINE_NOT_FOUND, got %08x\n", hr); /* successfully translate the string */ memset(buffer, 'a', 25); buffer[24] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); todo_wine { ok(!strcmp(buffer, TEST_STRING2), "Expected %s, got %s\n", TEST_STRING2, buffer); ok(size == 25, "Expected size 25, got %d\n", size); } /* try a NULL hinf */ hr = pCloseINFEngine(NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got %08x\n", hr); /* successfully close the hinf */ hr = pCloseINFEngine(hinf); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); /* open the inf with the install section */ hr = pOpenINFEngine(inf_file, "section", 0, &hinf, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); /* translate the string with the install section specified */ memset(buffer, 'a', APP_PATH_LEN); buffer[APP_PATH_LEN - 1] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "InstallDir", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(!strcmp(buffer, APP_PATH), "Expected %s, got %s\n", APP_PATH, buffer); ok(size == APP_PATH_LEN, "Expected size %d, got %d\n", APP_PATH_LEN, size); /* Single quote test (Note size includes null on return from call) */ memset(buffer, 'a', APP_PATH_LEN); buffer[APP_PATH_LEN - 1] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result1", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(!lstrcmpiA(buffer, PROG_FILES_ROOT), "Expected %s, got %s\n", PROG_FILES_ROOT, buffer); ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n", lstrlenA(PROG_FILES_ROOT)+1, size); memset(buffer, 'a', APP_PATH_LEN); buffer[APP_PATH_LEN - 1] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result2", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(!lstrcmpiA(buffer, PROG_FILES_ROOT), "Expected %s, got %s\n", PROG_FILES_ROOT, buffer); ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n", lstrlenA(PROG_FILES_ROOT)+1, size); { char drive[MAX_PATH]; lstrcpyA(drive, PROG_FILES_ROOT); drive[3] = 0x00; /* Just keep the system drive plus '\' */ memset(buffer, 'a', APP_PATH_LEN); buffer[APP_PATH_LEN - 1] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result3", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(!lstrcmpiA(buffer, drive), "Expected %s, got %s\n", drive, buffer); ok(size == strlen(drive)+1, "Expected size %d, got %d\n", lstrlenA(drive)+1, size); } /* close the INF again */ hr = pCloseINFEngine(hinf); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); DeleteFileA(inf_file); /* Create another .inf file which is just here to trigger a wine bug */ { char data[1024]; char *ptr = data; DWORD dwNumberOfBytesWritten; HANDLE hf = CreateFileA(inf_file, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); append_str(&ptr, "[Version]\n"); append_str(&ptr, "Signature=\"$Chicago$\"\n"); append_str(&ptr, "[section]\n"); append_str(&ptr, "NotACustomDestination=Version\n"); append_str(&ptr, "CustomDestination=CustInstDestSection\n"); append_str(&ptr, "[CustInstDestSection]\n"); append_str(&ptr, "49010=DestA,1\n"); append_str(&ptr, "49020=DestB\n"); append_str(&ptr, "49030=DestC\n"); append_str(&ptr, "49040=DestD\n"); append_str(&ptr, "[Options.NTx86]\n"); append_str(&ptr, "Result2=%%49030%%\n"); append_str(&ptr, "[DestA]\n"); append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n"); /* The point of this test is to have HKCU just before the quoted HKLM */ append_str(&ptr, "[DestB]\n"); append_str(&ptr, "HKCU,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n"); append_str(&ptr, "[DestC]\n"); append_str(&ptr, "'HKLM','Software\\Microsoft\\Windows\\CurrentVersion',"); append_str(&ptr, "'ProgramFilesDir',,\"%%24%%\"\n"); append_str(&ptr, "[DestD]\n"); append_str(&ptr, "HKLM,\"Software\\Garbage\",\"ProgramFilesDir\",,'%%24%%'\n"); WriteFile(hf, data, ptr - data, &dwNumberOfBytesWritten, NULL); CloseHandle(hf); } /* open the inf with the install section */ hr = pOpenINFEngine(inf_file, "section", 0, &hinf, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); /* Single quote test (Note size includes null on return from call) */ memset(buffer, 'a', APP_PATH_LEN); buffer[APP_PATH_LEN - 1] = '\0'; size = MAX_PATH; hr = pTranslateInfStringEx(hinf, inf_file, "Options.NTx86", "Result2", buffer, size, &size, NULL); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); ok(!lstrcmpiA(buffer, PROG_FILES_ROOT), "Expected %s, got %s\n", PROG_FILES_ROOT, buffer); ok(size == strlen(PROG_FILES_ROOT)+1, "Expected size %d, got %d\n", lstrlenA(PROG_FILES_ROOT)+1, size); /* close the INF again */ hr = pCloseINFEngine(hinf); ok(hr == S_OK, "Expected S_OK, got %08x\n", hr); DeleteFileA(inf_file); }
static void test_WM_LBUTTONDOWN(void) { HWND hComboEx, hCombo, hEdit, hList; COMBOBOXINFO cbInfo; UINT x, y, item_height; LRESULT result; UINT i; int idx; RECT rect; WCHAR buffer[3]; static const UINT choices[] = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72}; static const WCHAR stringFormat[] = {'%','2','d','\0'}; BOOL (WINAPI *pGetComboBoxInfo)(HWND, PCOMBOBOXINFO); pGetComboBoxInfo = (void*)GetProcAddress(GetModuleHandleA("user32.dll"), "GetComboBoxInfo"); if (!pGetComboBoxInfo){ win_skip("GetComboBoxInfo is not available\n"); return; } hComboEx = CreateWindowExA(0, WC_COMBOBOXEXA, NULL, WS_VISIBLE|WS_CHILD|CBS_DROPDOWN, 0, 0, 200, 150, hComboExParentWnd, NULL, hMainHinst, NULL); for (i = 0; i < sizeof(choices)/sizeof(UINT); i++){ COMBOBOXEXITEMW cbexItem; wsprintfW(buffer, stringFormat, choices[i]); memset(&cbexItem, 0x00, sizeof(cbexItem)); cbexItem.mask = CBEIF_TEXT; cbexItem.iItem = i; cbexItem.pszText = buffer; cbexItem.cchTextMax = 0; ok(SendMessageW(hComboEx, CBEM_INSERTITEMW, 0, (LPARAM)&cbexItem) >= 0, "Failed to add item %d\n", i); } hCombo = (HWND)SendMessageA(hComboEx, CBEM_GETCOMBOCONTROL, 0, 0); hEdit = (HWND)SendMessageA(hComboEx, CBEM_GETEDITCONTROL, 0, 0); cbInfo.cbSize = sizeof(COMBOBOXINFO); result = pGetComboBoxInfo(hCombo, &cbInfo); ok(result, "Failed to get combobox info structure. LastError=%d\n", GetLastError()); hList = cbInfo.hwndList; ok(GetFocus() == hComboExParentWnd, "Focus not on Main Window, instead on %p\n", GetFocus()); /* Click on the button to drop down the list */ x = cbInfo.rcButton.left + (cbInfo.rcButton.right-cbInfo.rcButton.left)/2; y = cbInfo.rcButton.top + (cbInfo.rcButton.bottom-cbInfo.rcButton.top)/2; result = SendMessageA(hCombo, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y)); ok(result, "WM_LBUTTONDOWN was not processed. LastError=%d\n", GetLastError()); ok(GetFocus() == hCombo || broken(GetFocus() != hCombo), /* win98 */ "Focus not on ComboBoxEx's ComboBox Control, instead on %p\n", GetFocus()); ok(SendMessageA(hComboEx, CB_GETDROPPEDSTATE, 0, 0), "The dropdown list should have appeared after clicking the button.\n"); idx = SendMessageA(hCombo, CB_GETTOPINDEX, 0, 0); ok(idx == 0, "For TopIndex expected %d, got %d\n", 0, idx); result = SendMessageA(hCombo, WM_LBUTTONUP, 0, MAKELPARAM(x, y)); ok(result, "WM_LBUTTONUP was not processed. LastError=%d\n", GetLastError()); ok(GetFocus() == hCombo || broken(GetFocus() != hCombo), /* win98 */ "Focus not on ComboBoxEx's ComboBox Control, instead on %p\n", GetFocus()); /* Click on the 5th item in the list */ item_height = SendMessageA(hCombo, CB_GETITEMHEIGHT, 0, 0); ok(GetClientRect(hList, &rect), "Failed to get list's client rect.\n"); x = rect.left + (rect.right-rect.left)/2; y = item_height/2 + item_height*4; result = SendMessageA(hList, WM_MOUSEMOVE, 0, MAKELPARAM(x, y)); ok(!result, "WM_MOUSEMOVE was not processed. LastError=%d\n", GetLastError()); ok(GetFocus() == hCombo || broken(GetFocus() != hCombo), /* win98 */ "Focus not on ComboBoxEx's ComboBox Control, instead on %p\n", GetFocus()); result = SendMessageA(hList, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y)); ok(!result, "WM_LBUTTONDOWN was not processed. LastError=%d\n", GetLastError()); ok(GetFocus() == hCombo || broken(GetFocus() != hCombo), /* win98 */ "Focus not on ComboBoxEx's ComboBox Control, instead on %p\n", GetFocus()); ok(SendMessageA(hComboEx, CB_GETDROPPEDSTATE, 0, 0), "The dropdown list should still be visible.\n"); result = SendMessageA(hList, WM_LBUTTONUP, 0, MAKELPARAM(x, y)); ok(!result, "WM_LBUTTONUP was not processed. LastError=%d\n", GetLastError()); todo_wine ok(GetFocus() == hEdit || broken(GetFocus() == hCombo), /* win98 */ "Focus not on ComboBoxEx's Edit Control, instead on %p\n", GetFocus()); result = SendMessageA(hCombo, CB_GETDROPPEDSTATE, 0, 0); ok(!result || broken(result != 0), /* win98 */ "The dropdown list should have been rolled up.\n"); idx = SendMessageA(hComboEx, CB_GETCURSEL, 0, 0); ok(idx == 4 || broken(idx == -1), /* win98 */ "Current Selection: expected %d, got %d\n", 4, idx); ok(received_end_edit, "Expected to receive a CBEN_ENDEDIT message\n"); SetFocus( hComboExParentWnd ); ok( GetFocus() == hComboExParentWnd, "got %p\n", GetFocus() ); SetFocus( hComboEx ); ok( GetFocus() == hEdit, "got %p\n", GetFocus() ); DestroyWindow(hComboEx); }
static void test_VarWeekdayName(void) { char buff[256]; BSTR out = NULL; HRESULT hres; int iWeekday, fAbbrev, iFirstDay; BSTR dayNames[7][2]; /* Monday-Sunday, full/abbr */ DWORD defaultFirstDay; int firstDay; int day; int size; DWORD localeValue; CHECKPTR(VarWeekdayName); SetLastError(0xdeadbeef); GetLocaleInfoW(LOCALE_USER_DEFAULT, 0, NULL, 0); if (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) { win_skip("GetLocaleInfoW is not implemented\n"); return; } /* Initialize days' names */ for (day = 0; day <= 6; ++day) { for (fAbbrev = 0; fAbbrev <= 1; ++fAbbrev) { localeValue = fAbbrev ? LOCALE_SABBREVDAYNAME1 : LOCALE_SDAYNAME1; localeValue += day; size = GetLocaleInfoW(LOCALE_USER_DEFAULT, localeValue, NULL, 0); dayNames[day][fAbbrev] = SysAllocStringLen(NULL, size - 1); GetLocaleInfoW(LOCALE_USER_DEFAULT, localeValue, dayNames[day][fAbbrev], size); } } /* Get the user's first day of week. 0=Monday, .. */ GetLocaleInfoW( LOCALE_USER_DEFAULT, LOCALE_IFIRSTDAYOFWEEK | LOCALE_RETURN_NUMBER, (LPWSTR)&defaultFirstDay, sizeof(defaultFirstDay) / sizeof(WCHAR)); /* Check invalid arguments */ VARWDN_F(0, 0, 4, 0, E_INVALIDARG); VARWDN_F(8, 0, 4, 0, E_INVALIDARG); VARWDN_F(4, 0, -1, 0, E_INVALIDARG); VARWDN_F(4, 0, 8, 0, E_INVALIDARG); hres = pVarWeekdayName(1, 0, 0, 0, NULL); ok(E_INVALIDARG == hres, "Null pointer: expected E_INVALIDARG, got 0x%08x\n", hres); /* Check all combinations */ pVarBstrCmp = (void*)GetProcAddress(hOleaut32, "VarBstrCmp"); if (pVarBstrCmp) for (iWeekday = 1; iWeekday <= 7; ++iWeekday) { for (fAbbrev = 0; fAbbrev <= 1; ++fAbbrev) { /* 0 = Default, 1 = Sunday, 2 = Monday, .. */ for (iFirstDay = 0; iFirstDay <= 7; ++iFirstDay) { VARWDN_O(iWeekday, fAbbrev, iFirstDay, 0); if (iFirstDay == 0) firstDay = defaultFirstDay; else /* Translate from 0=Sunday to 0=Monday in the modulo 7 space */ firstDay = iFirstDay - 2; day = (7 + iWeekday - 1 + firstDay) % 7; ok(VARCMP_EQ == pVarBstrCmp(out, dayNames[day][fAbbrev], LOCALE_USER_DEFAULT, 0), "VarWeekdayName(%d,%d,%d): got wrong dayname: '%s'\n", iWeekday, fAbbrev, iFirstDay, buff); SysFreeString(out); } } } /* Cleanup */ for (day = 0; day <= 6; ++day) { for (fAbbrev = 0; fAbbrev <= 1; ++fAbbrev) { SysFreeString(dayNames[day][fAbbrev]); } } }
static void test_strftime(void) { static const wchar_t cW[] = { '%','c',0 }; static const char expected[] = "01/01/70 00:00:00"; time_t gmt; struct tm* gmt_tm; char buf[256], bufA[256]; WCHAR bufW[256]; long retA, retW; if (!p_strftime || !p_wcsftime || !p_gmtime) { win_skip("strftime, wcsftime or gmtime is not available\n"); return; } setlocale(LC_TIME, "C"); gmt = 0; gmt_tm = p_gmtime(&gmt); ok(gmt_tm != NULL, "gmtime failed\n"); errno = 0xdeadbeef; retA = strftime(NULL, 0, "copy", gmt_tm); ok(retA == 0, "expected 0, got %ld\n", retA); ok(errno==EINVAL || broken(errno==0xdeadbeef), "errno = %d\n", errno); retA = strftime(bufA, 256, "copy", NULL); ok(retA == 4, "expected 4, got %ld\n", retA); ok(!strcmp(bufA, "copy"), "got %s\n", bufA); retA = strftime(bufA, 256, "copy it", gmt_tm); ok(retA == 7, "expected 7, got %ld\n", retA); ok(!strcmp(bufA, "copy it"), "got %s\n", bufA); errno = 0xdeadbeef; retA = strftime(bufA, 2, "copy", gmt_tm); ok(retA == 0, "expected 0, got %ld\n", retA); ok(!strcmp(bufA, "") || broken(!strcmp(bufA, "copy it")), "got %s\n", bufA); ok(errno==ERANGE || errno==0xdeadbeef, "errno = %d\n", errno); errno = 0xdeadbeef; retA = strftime(bufA, 256, "a%e", gmt_tm); ok(retA==0 || broken(retA==1), "expected 0, got %ld\n", retA); ok(!strcmp(bufA, "") || broken(!strcmp(bufA, "a")), "got %s\n", bufA); ok(errno==EINVAL || broken(errno==0xdeadbeef), "errno = %d\n", errno); if(0) { /* crashes on Win2k */ errno = 0xdeadbeef; retA = strftime(bufA, 256, "%c", NULL); ok(retA == 0, "expected 0, got %ld\n", retA); ok(!strcmp(bufA, ""), "got %s\n", bufA); ok(errno == EINVAL, "errno = %d\n", errno); } retA = strftime(bufA, 256, "e%#%e", gmt_tm); ok(retA == 3, "expected 3, got %ld\n", retA); ok(!strcmp(bufA, "e%e"), "got %s\n", bufA); retA = strftime(bufA, 256, "%c", gmt_tm); ok(retA == 17, "expected 17, got %ld\n", retA); ok(strcmp(bufA, expected) == 0, "expected %s, got %s\n", expected, bufA); retW = wcsftime(bufW, 256, cW, gmt_tm); ok(retW == 17, "expected 17, got %ld\n", retW); ok(retA == retW, "expected %ld, got %ld\n", retA, retW); buf[0] = 0; retA = WideCharToMultiByte(CP_ACP, 0, bufW, retW, buf, 256, NULL, NULL); buf[retA] = 0; ok(strcmp(bufA, buf) == 0, "expected %s, got %s\n", bufA, buf); retA = strftime(bufA, 256, "%x", gmt_tm); ok(retA == 8, "expected 8, got %ld\n", retA); ok(!strcmp(bufA, "01/01/70"), "got %s\n", bufA); retA = strftime(bufA, 256, "%X", gmt_tm); ok(retA == 8, "expected 8, got %ld\n", retA); ok(!strcmp(bufA, "00:00:00"), "got %s\n", bufA); retA = strftime(bufA, 256, "%a", gmt_tm); ok(retA == 3, "expected 3, got %ld\n", retA); ok(!strcmp(bufA, "Thu"), "got %s\n", bufA); retA = strftime(bufA, 256, "%A", gmt_tm); ok(retA == 8, "expected 8, got %ld\n", retA); ok(!strcmp(bufA, "Thursday"), "got %s\n", bufA); retA = strftime(bufA, 256, "%b", gmt_tm); ok(retA == 3, "expected 3, got %ld\n", retA); ok(!strcmp(bufA, "Jan"), "got %s\n", bufA); retA = strftime(bufA, 256, "%B", gmt_tm); ok(retA == 7, "expected 7, got %ld\n", retA); ok(!strcmp(bufA, "January"), "got %s\n", bufA); retA = strftime(bufA, 256, "%d", gmt_tm); ok(retA == 2, "expected 2, got %ld\n", retA); ok(!strcmp(bufA, "01"), "got %s\n", bufA); retA = strftime(bufA, 256, "%#d", gmt_tm); ok(retA == 1, "expected 1, got %ld\n", retA); ok(!strcmp(bufA, "1"), "got %s\n", bufA); retA = strftime(bufA, 256, "%H", gmt_tm); ok(retA == 2, "expected 2, got %ld\n", retA); ok(!strcmp(bufA, "00"), "got %s\n", bufA); retA = strftime(bufA, 256, "%I", gmt_tm); ok(retA == 2, "expected 2, got %ld\n", retA); ok(!strcmp(bufA, "12"), "got %s\n", bufA); retA = strftime(bufA, 256, "%j", gmt_tm); ok(retA == 3, "expected 3, got %ld\n", retA); ok(!strcmp(bufA, "001"), "got %s\n", bufA); retA = strftime(bufA, 256, "%m", gmt_tm); ok(retA == 2, "expected 2, got %ld\n", retA); ok(!strcmp(bufA, "01"), "got %s\n", bufA); retA = strftime(bufA, 256, "%#M", gmt_tm); ok(retA == 1, "expected 1, got %ld\n", retA); ok(!strcmp(bufA, "0"), "got %s\n", bufA); retA = strftime(bufA, 256, "%p", gmt_tm); ok(retA == 2, "expected 2, got %ld\n", retA); ok(!strcmp(bufA, "AM"), "got %s\n", bufA); retA = strftime(bufA, 256, "%U", gmt_tm); ok(retA == 2, "expected 2, got %ld\n", retA); ok(!strcmp(bufA, "00"), "got %s\n", bufA); retA = strftime(bufA, 256, "%W", gmt_tm); ok(retA == 2, "expected 2, got %ld\n", retA); ok(!strcmp(bufA, "00"), "got %s\n", bufA); gmt_tm->tm_wday = 0; retA = strftime(bufA, 256, "%U", gmt_tm); ok(retA == 2, "expected 2, got %ld\n", retA); ok(!strcmp(bufA, "01"), "got %s\n", bufA); retA = strftime(bufA, 256, "%W", gmt_tm); ok(retA == 2, "expected 2, got %ld\n", retA); ok(!strcmp(bufA, "00"), "got %s\n", bufA); gmt_tm->tm_yday = 365; retA = strftime(bufA, 256, "%U", gmt_tm); ok(retA == 2, "expected 2, got %ld\n", retA); ok(!strcmp(bufA, "53"), "got %s\n", bufA); retA = strftime(bufA, 256, "%W", gmt_tm); ok(retA == 2, "expected 2, got %ld\n", retA); ok(!strcmp(bufA, "52"), "got %s\n", bufA); gmt_tm->tm_mon = 1; gmt_tm->tm_mday = 30; retA = strftime(bufA, 256, "%c", gmt_tm); todo_wine { ok(retA == 17, "expected 17, got %ld\n", retA); ok(!strcmp(bufA, "02/30/70 00:00:00"), "got %s\n", bufA); } }
static void test_VerifyVersionInfo(void) { OSVERSIONINFOEXA info; BOOL ret; DWORD servicepack, error; if(!pVerifyVersionInfoA || !pVerSetConditionMask) { win_skip("Needed functions not available\n"); return; } /* Before we start doing some tests we should check what the version of * the ServicePack is. Tests on a box with no ServicePack will fail otherwise. */ info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA); GetVersionExA((OSVERSIONINFOA *)&info); servicepack = info.wServicePackMajor; /* Win8.1+ returns Win8 version in GetVersionEx when there's no app manifest targeting 8.1 */ if (info.dwMajorVersion == 6 && info.dwMinorVersion == 2) { RTL_OSVERSIONINFOEXW rtlinfo; rtlinfo.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOEXW); ok(SUCCEEDED(pRtlGetVersion(&rtlinfo)), "RtlGetVersion failed\n"); if (rtlinfo.dwMajorVersion != 6 || rtlinfo.dwMinorVersion != 2) { win_skip("GetVersionEx and VerifyVersionInfo are faking values\n"); return; } } memset(&info, 0, sizeof(info)); ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION, pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL)); ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError()); SetLastError(0xdeadbeef); ret = pVerifyVersionInfoA(&info, VER_BUILDNUMBER | VER_MAJORVERSION | VER_MINORVERSION/* | VER_PLATFORMID | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR | VER_SUITENAME | VER_PRODUCT_TYPE */, pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL)); error = GetLastError(); ok(!ret, "VerifyVersionInfoA succeeded\n"); ok(error == ERROR_OLD_WIN_VERSION, "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error); /* tests special handling of VER_SUITENAME */ ret = pVerifyVersionInfoA(&info, VER_SUITENAME, pVerSetConditionMask(0, VER_SUITENAME, VER_AND)); ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError()); ret = pVerifyVersionInfoA(&info, VER_SUITENAME, pVerSetConditionMask(0, VER_SUITENAME, VER_OR)); ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError()); /* test handling of version numbers */ /* v3.10 is always less than v4.x even * if the minor version is tested */ info.dwMajorVersion = 3; info.dwMinorVersion = 10; ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL), VER_MAJORVERSION, VER_GREATER_EQUAL)); ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError()); info.dwMinorVersion = 0; info.wServicePackMajor = 10; ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL), VER_MAJORVERSION, VER_GREATER_EQUAL)); ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError()); info.wServicePackMajor = 0; info.wServicePackMinor = 10; ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, pVerSetConditionMask(pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL), VER_MAJORVERSION, VER_GREATER_EQUAL)); ok(ret, "VerifyVersionInfoA failed with error %d\n", GetLastError()); info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA); GetVersionExA((OSVERSIONINFOA *)&info); info.wServicePackMinor++; SetLastError(0xdeadbeef); ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL)); error = GetLastError(); ok(!ret, "VerifyVersionInfoA succeeded\n"); ok(error == ERROR_OLD_WIN_VERSION || broken(error == ERROR_BAD_ARGUMENTS) /* some wink2 */, "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error); if (servicepack == 0) { skip("There is no ServicePack on this system\n"); } else { info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA); GetVersionExA((OSVERSIONINFOA *)&info); info.wServicePackMajor--; ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER)); ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError()); info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA); GetVersionExA((OSVERSIONINFOA *)&info); info.wServicePackMajor--; ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL)); ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError()); } info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA); GetVersionExA((OSVERSIONINFOA *)&info); info.wServicePackMajor++; ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, pVerSetConditionMask(0, VER_MINORVERSION, VER_LESS)); ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError()); info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA); GetVersionExA((OSVERSIONINFOA *)&info); info.wServicePackMajor++; ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, pVerSetConditionMask(0, VER_MINORVERSION, VER_LESS_EQUAL)); ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError()); info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA); GetVersionExA((OSVERSIONINFOA *)&info); info.wServicePackMajor--; SetLastError(0xdeadbeef); ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, pVerSetConditionMask(0, VER_MINORVERSION, VER_EQUAL)); error = GetLastError(); ok(!ret, "VerifyVersionInfoA succeeded\n"); ok(error == ERROR_OLD_WIN_VERSION || broken(error == ERROR_BAD_ARGUMENTS) /* some win2k */, "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error); /* test the failure hierarchy for the four version fields */ info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA); GetVersionExA((OSVERSIONINFOA *)&info); info.wServicePackMajor++; SetLastError(0xdeadbeef); ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL)); error = GetLastError(); ok(!ret, "VerifyVersionInfoA succeeded\n"); ok(error == ERROR_OLD_WIN_VERSION || broken(error == ERROR_BAD_ARGUMENTS) /* some win2k */, "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error); info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA); GetVersionExA((OSVERSIONINFOA *)&info); info.dwMinorVersion++; SetLastError(0xdeadbeef); ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL)); error = GetLastError(); ok(!ret, "VerifyVersionInfoA succeeded\n"); ok(error == ERROR_OLD_WIN_VERSION || broken(error == ERROR_BAD_ARGUMENTS) /* some win2k */, "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error); info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA); GetVersionExA((OSVERSIONINFOA *)&info); info.dwMajorVersion++; SetLastError(0xdeadbeef); ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL)); error = GetLastError(); ok(!ret, "VerifyVersionInfoA succeeded\n"); ok(error == ERROR_OLD_WIN_VERSION || broken(error == ERROR_BAD_ARGUMENTS) /* some win2k */, "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error); ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL)); ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError()); info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA); GetVersionExA((OSVERSIONINFOA *)&info); info.dwBuildNumber++; SetLastError(0xdeadbeef); ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL)); error = GetLastError(); ok(!ret, "VerifyVersionInfoA succeeded\n"); ok(error == ERROR_OLD_WIN_VERSION || broken(error == ERROR_BAD_ARGUMENTS) /* some win2k */, "VerifyVersionInfoA should have failed with ERROR_OLD_WIN_VERSION instead of %d\n", error); ret = pVerifyVersionInfoA(&info, VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, pVerSetConditionMask(0, VER_MINORVERSION, VER_GREATER_EQUAL)); ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError()); /* test bad dwOSVersionInfoSize */ info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEXA); GetVersionExA((OSVERSIONINFOA *)&info); info.dwOSVersionInfoSize = 0; ret = pVerifyVersionInfoA(&info, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, pVerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL)); ok(ret || broken(!ret) /* some win2k */, "VerifyVersionInfoA failed with error %d\n", GetLastError()); }
static void test_gmtime(void) { __time32_t valid, gmt; struct tm* gmt_tm, gmt_tm_s; errno_t err; if(!p_gmtime32) { win_skip("Skipping _gmtime32 tests\n"); return; } gmt_tm = p_gmtime32(NULL); ok(gmt_tm == NULL, "gmt_tm != NULL\n"); gmt = -1; gmt_tm = p_gmtime32(&gmt); ok(gmt_tm==NULL || broken(gmt_tm->tm_year==70 && gmt_tm->tm_sec<0), "gmt_tm != NULL\n"); gmt = valid = 0; gmt_tm = p_gmtime32(&gmt); if(!gmt_tm) { ok(0, "_gmtime32() failed\n"); return; } ok(((gmt_tm->tm_year == 70) && (gmt_tm->tm_mon == 0) && (gmt_tm->tm_yday == 0) && (gmt_tm->tm_mday == 1) && (gmt_tm->tm_wday == 4) && (gmt_tm->tm_hour == 0) && (gmt_tm->tm_min == 0) && (gmt_tm->tm_sec == 0) && (gmt_tm->tm_isdst == 0)), "Wrong date:Year %4d mon %2d yday %3d mday %2d wday %1d hour%2d min %2d sec %2d dst %2d\n", gmt_tm->tm_year, gmt_tm->tm_mon, gmt_tm->tm_yday, gmt_tm->tm_mday, gmt_tm->tm_wday, gmt_tm->tm_hour, gmt_tm->tm_min, gmt_tm->tm_sec, gmt_tm->tm_isdst); if(!p_mkgmtime32) { win_skip("Skipping _mkgmtime32 tests\n"); return; } gmt_tm->tm_wday = gmt_tm->tm_yday = 0; gmt = p_mkgmtime32(gmt_tm); ok(gmt == valid, "gmt = %u\n", gmt); ok(gmt_tm->tm_wday == 4, "gmt_tm->tm_wday = %d\n", gmt_tm->tm_wday); ok(gmt_tm->tm_yday == 0, "gmt_tm->tm_yday = %d\n", gmt_tm->tm_yday); gmt_tm->tm_wday = gmt_tm->tm_yday = 0; gmt_tm->tm_isdst = -1; gmt = p_mkgmtime32(gmt_tm); ok(gmt == valid, "gmt = %u\n", gmt); ok(gmt_tm->tm_wday == 4, "gmt_tm->tm_wday = %d\n", gmt_tm->tm_wday); ok(gmt_tm->tm_yday == 0, "gmt_tm->tm_yday = %d\n", gmt_tm->tm_yday); gmt_tm->tm_wday = gmt_tm->tm_yday = 0; gmt_tm->tm_isdst = 1; gmt = p_mkgmtime32(gmt_tm); ok(gmt == valid, "gmt = %u\n", gmt); ok(gmt_tm->tm_wday == 4, "gmt_tm->tm_wday = %d\n", gmt_tm->tm_wday); ok(gmt_tm->tm_yday == 0, "gmt_tm->tm_yday = %d\n", gmt_tm->tm_yday); gmt = valid = 173921; gmt_tm = p_gmtime32(&gmt); if(!gmt_tm) { ok(0, "_gmtime32() failed\n"); return; } gmt_tm->tm_isdst = -1; gmt = p_mkgmtime32(gmt_tm); ok(gmt == valid, "gmt = %u\n", gmt); ok(gmt_tm->tm_wday == 6, "gmt_tm->tm_wday = %d\n", gmt_tm->tm_wday); ok(gmt_tm->tm_yday == 2, "gmt_tm->tm_yday = %d\n", gmt_tm->tm_yday); gmt_tm->tm_isdst = 1; gmt = p_mkgmtime32(gmt_tm); ok(gmt == valid, "gmt = %u\n", gmt); if(!p_gmtime32_s) { win_skip("Skipping _gmtime32_s tests\n"); return; } errno = 0; gmt = 0; err = p_gmtime32_s(NULL, &gmt); ok(err == EINVAL, "err = %d\n", err); ok(errno == EINVAL, "errno = %d\n", errno); errno = 0; gmt = -1; err = p_gmtime32_s(&gmt_tm_s, &gmt); ok(gmt_tm_s.tm_year == -1 || broken(gmt_tm_s.tm_year == 70 && gmt_tm_s.tm_sec < 0), "tm_year = %d, tm_sec = %d\n", gmt_tm_s.tm_year, gmt_tm_s.tm_sec); if(gmt_tm_s.tm_year == -1) { ok(err==EINVAL, "err = %d\n", err); ok(errno==EINVAL, "errno = %d\n", errno); } }
static void test_StrStrNIW(void) { static const WCHAR emptyW[] = {0}; static const WCHAR deadbeefW[] = {'D','e','A','d','B','e','E','f',0}; static const WCHAR deadW[] = {'D','e','A','d',0}; static const WCHAR dead_lowerW[] = {'d','e','a','d',0}; static const WCHAR adbeW[] = {'A','d','B','e',0}; static const WCHAR adbe_lowerW[] = {'a','d','b','e',0}; static const WCHAR beefW[] = {'B','e','E','f',0}; static const WCHAR beef_lowerW[] = {'b','e','e','f',0}; static const WCHAR cafeW[] = {'c','a','f','e',0}; const struct { const WCHAR *search; const UINT count; const WCHAR *expect; } StrStrNIW_cases[] = { {emptyW, sizeof(deadbeefW)/sizeof(WCHAR), NULL}, {deadW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW}, {dead_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW}, {adbeW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 2}, {adbe_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 2}, {beefW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 4}, {beef_lowerW, sizeof(deadbeefW)/sizeof(WCHAR), deadbeefW + 4}, {cafeW, sizeof(deadbeefW)/sizeof(WCHAR), NULL}, {beefW, 0, NULL}, {beefW, 1, NULL}, {beefW, 2, NULL}, {beefW, 3, NULL}, {beefW, 4, NULL}, {beefW, 5, deadbeefW + 4}, {beefW, 6, deadbeefW + 4}, {beefW, 7, deadbeefW + 4}, {beefW, 8, deadbeefW + 4}, {beefW, 9, deadbeefW + 4}, {beef_lowerW, 0, NULL}, {beef_lowerW, 1, NULL}, {beef_lowerW, 2, NULL}, {beef_lowerW, 3, NULL}, {beef_lowerW, 4, NULL}, {beef_lowerW, 5, deadbeefW + 4}, {beef_lowerW, 6, deadbeefW + 4}, {beef_lowerW, 7, deadbeefW + 4}, {beef_lowerW, 8, deadbeefW + 4}, {beef_lowerW, 9, deadbeefW + 4}, }; LPWSTR ret; UINT i; if (!pStrStrNIW) { win_skip("StrStrNIW() is not available\n"); return; } ret = pStrStrNIW(NULL, NULL, 0); ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret); ret = pStrStrNIW(NULL, NULL, 10); ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret); ret = pStrStrNIW(NULL, emptyW, 10); ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret); ret = pStrStrNIW(emptyW, NULL, 10); ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret); ret = pStrStrNIW(emptyW, emptyW, 10); ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret); for (i = 0; i < sizeof(StrStrNIW_cases)/sizeof(StrStrNIW_cases[0]); i++) { ret = pStrStrNIW(deadbeefW, StrStrNIW_cases[i].search, StrStrNIW_cases[i].count); ok(ret == StrStrNIW_cases[i].expect, "[%d] Expected StrStrNIW to return %p, got %p\n", i, StrStrNIW_cases[i].expect, ret); } /* StrStrNIW accepts counts larger than the search string length but rejects * counts larger than around 2G. The limit seems to change based on the * caller executable itself. */ ret = pStrStrNIW(deadbeefW, beefW, 100); ok(ret == deadbeefW + 4, "Expected StrStrNIW to return deadbeefW + 4, got %p\n", ret); if (0) { ret = pStrStrNIW(deadbeefW, beefW, ~0U); ok(!ret, "Expected StrStrNIW to return NULL, got %p\n", ret); } }
static void test_MessageBoxFontTest(void) { /* This dialog template defines a dialog template which got 0x7fff as its * font size and omits the other font members. On WinNT, passing such a * dialog template to CreateDialogIndirectParamW will result in a dialog * being created which uses the message box font. We test that here. */ static unsigned char dlgTemplate[] = { /* Dialog header */ 0x01,0x00, /* Version */ 0xff,0xff, /* Extended template marker */ 0x00,0x00,0x00,0x00, /* Context Help ID */ 0x00,0x00,0x00,0x00, /* Extended style */ 0xc0,0x00,0xc8,0x80, /* Style (WS_SYSMENU|WS_CAPTION|WS_POPUP|DS_SETFONT|DS_MODALFRAME) */ 0x01,0x00, /* Control count */ 0x00,0x00, /* X */ 0x00,0x00, /* Y */ 0x80,0x00, /* Width */ 0x80,0x00, /* Height */ 0x00,0x00, /* Menu name */ 0x00,0x00, /* Class name */ 'T',0x00,'e',0x00, /* Caption (unicode) */ 's',0x00,'t',0x00, 0x00,0x00, 0xff,0x7f, /* Font height (0x7fff = message box font) */ /* Control #1 */ 0x00,0x00, /* Align to DWORD (header is 42 bytes) */ 0x00,0x00,0x00,0x00, /* Context Help ID */ 0x00,0x00,0x00,0x00, /* Extended style */ 0x00,0x00,0x00,0x50, /* Style (WS_CHILD|WS_VISIBLE) */ 0x00,0x00, /* X */ 0x00,0x00, /* Y */ 0x80,0x00, /* Width */ 0x80,0x00, /* Height */ 0x00,0x01,0x00,0x00, /* Control ID (256) */ 0xff,0xff,0x82,0x00, /* Class (Static) */ 'W',0x00,'I',0x00, /* Caption (unicode) */ 'N',0x00,'E',0x00, ' ',0x00,'d',0x00, 'i',0x00,'a',0x00, 'l',0x00,'o',0x00, 'g',0x00,' ',0x00, 't',0x00,'e',0x00, 's',0x00,'t',0x00, '.',0x00,0x00,0x00, 0x00,0x00, /* Size of extended data */ 0x00,0x00 /* Align to DWORD */ }; HWND hDlg; HFONT hFont; LOGFONTW lfStaticFont; NONCLIENTMETRICSW ncMetrics; /* Check if the dialog can be created from the template. On Win9x, this should fail * because we are calling the W function which is not implemented, but that's what * we want, because passing such a template to CreateDialogIndirectParamA would crash * anyway. */ hDlg = CreateDialogIndirectParamW(g_hinst, (LPCDLGTEMPLATE)dlgTemplate, NULL, messageBoxFontDlgWinProc, 0); if (!hDlg) { win_skip("dialog wasn't created\n"); return; } hFont = (HFONT) SendDlgItemMessageW(hDlg, 256, WM_GETFONT, 0, 0); if (!hFont) { skip("dialog uses system font\n"); DestroyWindow(hDlg); return; } GetObjectW(hFont, sizeof(LOGFONTW), &lfStaticFont); ncMetrics.cbSize = sizeof(NONCLIENTMETRICSW); SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, 0, &ncMetrics, 0); ok( !memcmp(&lfStaticFont, &ncMetrics.lfMessageFont, FIELD_OFFSET(LOGFONTW, lfFaceName)) && !lstrcmpW(lfStaticFont.lfFaceName, ncMetrics.lfMessageFont.lfFaceName), "dialog doesn't use message box font\n"); DestroyWindow(hDlg); }
static void test__itoa_s(void) { errno_t ret; char buffer[33]; if (!p_itoa_s) { win_skip("Skipping _itoa_s tests\n"); return; } if(!p_set_invalid_parameter_handler) { win_skip("_set_invalid_parameter_handler not found\n"); return; } /* _itoa_s (on msvcr90) doesn't set errno (in case of errors) while msvcrt does * as we always set errno in our msvcrt implementation, don't test here that errno * isn't changed */ SET_EXPECT(invalid_parameter_handler); ret = p_itoa_s(0, NULL, 0, 0); ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret); CHECK_CALLED(invalid_parameter_handler); memset(buffer, 'X', sizeof(buffer)); SET_EXPECT(invalid_parameter_handler); ret = p_itoa_s(0, buffer, 0, 0); ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret); ok(buffer[0] == 'X', "Expected the output buffer to be untouched\n"); CHECK_CALLED(invalid_parameter_handler); memset(buffer, 'X', sizeof(buffer)); SET_EXPECT(invalid_parameter_handler); ret = p_itoa_s(0, buffer, sizeof(buffer), 0); ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret); ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n"); CHECK_CALLED(invalid_parameter_handler); memset(buffer, 'X', sizeof(buffer)); SET_EXPECT(invalid_parameter_handler); ret = p_itoa_s(0, buffer, sizeof(buffer), 64); ok(ret == EINVAL, "Expected _itoa_s to return EINVAL, got %d\n", ret); ok(buffer[0] == '\0', "Expected the output buffer to be null terminated\n"); CHECK_CALLED(invalid_parameter_handler); memset(buffer, 'X', sizeof(buffer)); SET_EXPECT(invalid_parameter_handler); ret = p_itoa_s(12345678, buffer, 4, 10); ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret); ok(!memcmp(buffer, "\000765", 4), "Expected the output buffer to be null terminated with truncated output\n"); CHECK_CALLED(invalid_parameter_handler); memset(buffer, 'X', sizeof(buffer)); SET_EXPECT(invalid_parameter_handler); ret = p_itoa_s(12345678, buffer, 8, 10); ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret); ok(!memcmp(buffer, "\0007654321", 8), "Expected the output buffer to be null terminated with truncated output\n"); CHECK_CALLED(invalid_parameter_handler); memset(buffer, 'X', sizeof(buffer)); SET_EXPECT(invalid_parameter_handler); ret = p_itoa_s(-12345678, buffer, 9, 10); ok(ret == ERANGE, "Expected _itoa_s to return ERANGE, got %d\n", ret); ok(!memcmp(buffer, "\00087654321", 9), "Expected the output buffer to be null terminated with truncated output\n"); CHECK_CALLED(invalid_parameter_handler); ret = p_itoa_s(12345678, buffer, 9, 10); ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret); ok(!strcmp(buffer, "12345678"), "Expected output buffer string to be \"12345678\", got \"%s\"\n", buffer); ret = p_itoa_s(43690, buffer, sizeof(buffer), 2); ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret); ok(!strcmp(buffer, "1010101010101010"), "Expected output buffer string to be \"1010101010101010\", got \"%s\"\n", buffer); ret = p_itoa_s(1092009, buffer, sizeof(buffer), 36); ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret); ok(!strcmp(buffer, "nell"), "Expected output buffer string to be \"nell\", got \"%s\"\n", buffer); ret = p_itoa_s(5704, buffer, sizeof(buffer), 18); ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret); ok(!strcmp(buffer, "hag"), "Expected output buffer string to be \"hag\", got \"%s\"\n", buffer); ret = p_itoa_s(-12345678, buffer, sizeof(buffer), 10); ok(ret == 0, "Expected _itoa_s to return 0, got %d\n", ret); ok(!strcmp(buffer, "-12345678"), "Expected output buffer string to be \"-12345678\", got \"%s\"\n", buffer); }