From d30df7de0634bd064a7ea7a866e695681a83c4a6 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Thu, 23 Apr 2009 16:10:49 +0400 Subject: [PATCH] comctl32/tests: Existing items aren't resorted after LVS_SORTASCENDING added. --- dlls/comctl32/tests/listview.c | 85 ++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/dlls/comctl32/tests/listview.c b/dlls/comctl32/tests/listview.c index 6482c7453e1..8fcf0f4c6e5 100644 --- a/dlls/comctl32/tests/listview.c +++ b/dlls/comctl32/tests/listview.c @@ -1578,6 +1578,9 @@ static void test_sorting(void) HWND hwnd; LVITEMA item = {0}; DWORD r; + LONG_PTR style; + static CHAR names[][4] = {"A", "B", "C", "D"}; + CHAR buff[10]; hwnd = create_listview_control(0); ok(hwnd != NULL, "failed to create a listview window\n"); @@ -1627,6 +1630,88 @@ static void test_sorting(void) expect(LVIS_SELECTED, r); DestroyWindow(hwnd); + + /* switch to LVS_SORTASCENDING when some items added */ + hwnd = create_listview_control(0); + ok(hwnd != NULL, "failed to create a listview window\n"); + + item.mask = LVIF_TEXT; + item.iItem = 0; + item.iSubItem = 0; + item.pszText = names[1]; + r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item); + expect(0, r); + + item.mask = LVIF_TEXT; + item.iItem = 1; + item.iSubItem = 0; + item.pszText = names[2]; + r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item); + expect(1, r); + + item.mask = LVIF_TEXT; + item.iItem = 2; + item.iSubItem = 0; + item.pszText = names[0]; + r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item); + expect(2, r); + + style = GetWindowLongPtrA(hwnd, GWL_STYLE); + SetWindowLongPtrA(hwnd, GWL_STYLE, style | LVS_SORTASCENDING); + style = GetWindowLongPtrA(hwnd, GWL_STYLE); + ok(style & LVS_SORTASCENDING, "Expected LVS_SORTASCENDING to be set\n"); + + /* no sorting performed when switched to LVS_SORTASCENDING */ + item.mask = LVIF_TEXT; + item.iItem = 0; + item.pszText = buff; + item.cchTextMax = sizeof(buff); + r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item); + expect(TRUE, r); + ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff); + + item.iItem = 1; + r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item); + expect(TRUE, r); + ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff); + + item.iItem = 2; + r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item); + expect(TRUE, r); + ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff); + + /* adding new item doesn't resort list */ + item.mask = LVIF_TEXT; + item.iItem = 3; + item.iSubItem = 0; + item.pszText = names[3]; + r = SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM) &item); + expect(3, r); + + item.mask = LVIF_TEXT; + item.iItem = 0; + item.pszText = buff; + item.cchTextMax = sizeof(buff); + r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item); + expect(TRUE, r); + todo_wine ok(lstrcmp(buff, names[1]) == 0, "Expected '%s', got '%s'\n", names[1], buff); + + item.iItem = 1; + r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item); + expect(TRUE, r); + todo_wine ok(lstrcmp(buff, names[2]) == 0, "Expected '%s', got '%s'\n", names[2], buff); + + item.iItem = 2; + r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item); + expect(TRUE, r); + todo_wine ok(lstrcmp(buff, names[0]) == 0, "Expected '%s', got '%s'\n", names[0], buff); + + item.iItem = 3; + r = SendMessage(hwnd, LVM_GETITEM, 0, (LPARAM) &item); + expect(TRUE, r); + ok(lstrcmp(buff, names[3]) == 0, "Expected '%s', got '%s'\n", names[3], buff); + + DestroyWindow(hwnd); } static void test_ownerdata(void)