On 4/6/21 5:30 AM, Haoyang Chen wrote:
+static INT WINAPI test_CallBackCompare1(LPARAM first, LPARAM second, LPARAM lParam) +{
- CHAR str1[5];
- CHAR str2[5];
- INT r;
- HWND hwnd = (HWND)lParam;
- LV_ITEMA item = {0};
- if (first == second) return 0;
- item.cchTextMax = 5;
- item.iSubItem = 0;
- item.pszText = str1;
- r = SendMessageA(hwnd, LVM_GETITEMTEXTA, first, (LPARAM)&item);
- expect(TRUE, r);
- item.pszText = str2;
- r = SendMessageA(hwnd, LVM_GETITEMTEXTA, second, (LPARAM)&item);
- expect(TRUE, r);
- return atoi(str1) > atoi(str2) ? 1 : -1;
+}
Compare logic should not rely on your test data.
- hwnd = create_listview_control(LVS_REPORT);
- ok(hwnd != NULL, "failed to create a listview window\n");
- lvc.mask = LVCF_TEXT | LVCF_WIDTH;
- lvc.pszText = names[0];
- lvc.cx = 50;
- SendMessageA(hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM)&lvc);
- SendMessageA(hwnd, LVM_INSERTCOLUMNA, 1, (LPARAM)&lvc);
- item.mask = LVIF_PARAM | LVIF_TEXT;
- item.iSubItem = 0;
- item.cchTextMax = 5;
- for (i = 0; i < sizeof(before_sort_array)/5; i++)
- {
item.iItem = i;
item.lParam = i;
item.pszText = &before_sort_array[i][0];
r = SendMessageA(hwnd, LVM_INSERTITEMA, 0, (LPARAM)&item);
expect(i, r);
- }
- r = SendMessageA(hwnd, LVM_SORTITEMS, (WPARAM)(LPARAM)hwnd, (LPARAM)test_CallBackCompare1);
- expect(TRUE, r);
- for (i = 0; i < sizeof(after_sort_arary)/5; i++)
- {
CHAR str[5];
item.iItem = i;
item.cchTextMax = 5;
item.iSubItem = 0;
item.pszText = str;
r = SendMessageA(hwnd, LVM_GETITEMTEXTA, i, (LPARAM)&item);
expect(TRUE, r);
expect(atoi(after_sort_arary[i]), atoi(str));
- }
What does this test demonstrate?