From 390e1dfa282e1735c86f1d01fc17b5d8d5bda287 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Zalewski?= Date: Mon, 19 Jan 2009 22:29:45 +0100 Subject: [PATCH] comctl32: treeview: Add a test showing that a pszText of NULL is equivalent to LPSTR_CALLBACK. --- dlls/comctl32/tests/treeview.c | 70 ++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/dlls/comctl32/tests/treeview.c b/dlls/comctl32/tests/treeview.c index 5e2746c26d4..0e85014c2de 100644 --- a/dlls/comctl32/tests/treeview.c +++ b/dlls/comctl32/tests/treeview.c @@ -32,6 +32,8 @@ #include "wine/test.h" #include "msg.h" +const char *TEST_CALLBACK_TEXT = "callback_text"; + #define NUM_MSG_SEQUENCES 1 #define LISTVIEW_SEQ_INDEX 0 @@ -264,6 +266,64 @@ static void FillRoot(void) ok(!strcmp(sequence, "AB."), "Item creation\n"); } +static void TestCallback(void) +{ + HTREEITEM hRoot; + HTREEITEM hItem1, hItem2; + TVINSERTSTRUCTA ins; + TVITEM tvi; + CHAR test_string[] = "Test_string"; + CHAR buf[128]; + LRESULT ret; + + TreeView_DeleteAllItems(hTree); + ins.hParent = TVI_ROOT; + ins.hInsertAfter = TVI_ROOT; + U(ins).item.mask = TVIF_TEXT; + U(ins).item.pszText = LPSTR_TEXTCALLBACK; + hRoot = TreeView_InsertItem(hTree, &ins); + assert(hRoot); + + tvi.hItem = hRoot; + tvi.mask = TVIF_TEXT; + tvi.pszText = buf; + tvi.cchTextMax = sizeof(buf)/sizeof(buf[0]); + ret = TreeView_GetItem(hTree, &tvi); + ok(ret == 1, "ret"); + ok(strcmp(tvi.pszText, TEST_CALLBACK_TEXT) == 0, "Callback item text mismatch %s vs %s\n", + tvi.pszText, TEST_CALLBACK_TEXT); + + ins.hParent = hRoot; + ins.hInsertAfter = TVI_FIRST; + U(ins).item.mask = TVIF_TEXT; + U(ins).item.pszText = test_string; + hItem1 = TreeView_InsertItem(hTree, &ins); + assert(hItem1); + + tvi.hItem = hItem1; + TreeView_GetItem(hTree, &tvi); + ok(strcmp(tvi.pszText, test_string) == 0, "Item text mismatch %s vs %s\n", + tvi.pszText, test_string); + + /* undocumented: pszText of NULL also means LPSTR_CALLBACK: */ + tvi.pszText = NULL; + ret = TreeView_SetItem(hTree, &tvi); + ok(ret == 1, "Expected SetItem return 1, got %ld\n", ret); + tvi.pszText = buf; + TreeView_GetItem(hTree, &tvi); + todo_wine ok(strcmp(tvi.pszText, TEST_CALLBACK_TEXT) == 0, "Item text mismatch %s vs %s\n", + tvi.pszText, TEST_CALLBACK_TEXT); + + U(ins).item.pszText = NULL; + hItem2 = TreeView_InsertItem(hTree, &ins); + assert(hItem2); + tvi.hItem = hItem2; + memset(buf, 0, sizeof(buf)); + TreeView_GetItem(hTree, &tvi); + todo_wine ok(strcmp(tvi.pszText, TEST_CALLBACK_TEXT) == 0, "Item text mismatch %s vs %s\n", + tvi.pszText, TEST_CALLBACK_TEXT); +} + static void DoTest1(void) { BOOL r; @@ -664,6 +724,13 @@ static LRESULT CALLBACK MyWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa IdentifyItem(pTreeView->itemOld.hItem); IdentifyItem(pTreeView->itemNew.hItem); return 0; + case TVN_GETDISPINFOA: { + NMTVDISPINFOA *disp = (NMTVDISPINFOA *)lParam; + if (disp->item.mask & TVIF_TEXT) { + lstrcpyn(disp->item.pszText, TEST_CALLBACK_TEXT, disp->item.cchTextMax); + } + return 0; + } } } return 0; @@ -746,6 +813,9 @@ START_TEST(treeview) /* Sequences tested inside due to number */ TestGetSet(); + /* Clears all the previous items */ + TestCallback(); + PostMessageA(hMainWnd, WM_CLOSE, 0, 0); while(GetMessageA(&msg,0,0,0)) { TranslateMessage(&msg);