[COMCTL32_WINETEST] Sync with Wine Staging 4.18. CORE-16441
[reactos.git] / modules / rostests / winetests / comctl32 / updown.c
index ec0937a..e7ceeff 100644 (file)
@@ -28,7 +28,6 @@
  *   - check UDM_SETBUDDY message
  *   - check UDM_GETBUDDY message
  *   - up-down control and buddy control must have the same parent
- *   - up-down control notifies its parent window when its position changes with UDN_DELTAPOS + WM_VSCROLL or WM_HSCROLL
  *   - check UDS_ALIGN[LEFT,RIGHT]...check that width of buddy window is decreased
  *   - check that UDS_SETBUDDYINT sets the caption of the buddy window when it is changed
  *   - check that the thousands operator is set for large numbers
  *   - more stuff to test
  */
 
-#include "precomp.h"
+#include <windows.h>
+#include <commctrl.h>
+#include <stdio.h>
+
+#include "wine/test.h"
+#include "msg.h"
 
 #define expect(EXPECTED,GOT) ok((GOT)==(EXPECTED), "Expected %d, got %d\n", (EXPECTED), (GOT))
 
@@ -58,6 +62,8 @@
 
 static HWND parent_wnd, g_edit;
 
+static HWND (WINAPI *pCreateUpDownControl)(DWORD, INT, INT, INT, INT,
+    HWND, INT, HINSTANCE, HWND, INT, INT, INT);
 static BOOL (WINAPI *pSetWindowSubclass)(HWND, SUBCLASSPROC, UINT_PTR, DWORD_PTR);
 
 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
@@ -158,6 +164,32 @@ static const struct message test_updown_pos_nochange_seq[] = {
     { 0 }
 };
 
+static const struct message test_updown_pos_notifications_seq[] = {
+    { WM_CTLCOLOREDIT, sent|optional },
+    { WM_COMMAND, sent|wparam, MAKELONG(0, EN_SETFOCUS) },
+    { WM_NOTIFY, sent|id, 0, 0, UDN_DELTAPOS },
+    { WM_COMMAND, sent|wparam, MAKELONG(0, EN_UPDATE) },
+    { WM_COMMAND, sent|wparam, MAKELONG(0, EN_CHANGE) },
+    { WM_VSCROLL, sent|wparam, MAKELONG(SB_THUMBPOSITION, 51) },
+    { WM_CTLCOLOREDIT, sent|optional },
+    { WM_VSCROLL, sent|wparam, MAKELONG(SB_ENDSCROLL, 51) },
+    /* no WM_NOTIFY(NM_RELEASEDCAPTURE) message */
+    { 0 }
+};
+
+static const struct message test_updown_pos_notifications_horz_seq[] = {
+    { WM_CTLCOLOREDIT, sent|optional },
+    { WM_COMMAND, sent|wparam, MAKELONG(0, EN_SETFOCUS) },
+    { WM_NOTIFY, sent|id, 0, 0, UDN_DELTAPOS },
+    { WM_COMMAND, sent|wparam, MAKELONG(0, EN_UPDATE) },
+    { WM_COMMAND, sent|wparam, MAKELONG(0, EN_CHANGE) },
+    { WM_HSCROLL, sent|wparam, MAKELONG(SB_THUMBPOSITION, 51) },
+    { WM_CTLCOLOREDIT, sent|optional },
+    { WM_HSCROLL, sent|wparam, MAKELONG(SB_ENDSCROLL, 51) },
+    /* no WM_NOTIFY(NM_RELEASEDCAPTURE) message */
+    { 0 }
+};
+
 static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
     static LONG defwndproc_counter = 0;
@@ -179,6 +211,8 @@ static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LP
         if (defwndproc_counter) msg.flags |= defwinproc;
         msg.wParam = wParam;
         msg.lParam = lParam;
+        if (message == WM_NOTIFY && lParam)
+            msg.id = ((NMHDR*)lParam)->code;
         add_message(sequences, PARENT_SEQ_INDEX, &msg);
     }
 
@@ -690,13 +724,13 @@ static void test_updown_base(void)
     r = SendMessageA(updown, UDM_SETPOS, 0, 10);
     expect(50, r);
 
-    GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
+    GetWindowTextA(g_edit, text, ARRAY_SIZE(text));
     ok(lstrcmpA(text, "10") == 0, "Expected '10', got '%s'\n", text);
 
     r = SendMessageA(updown, UDM_SETBASE, 16, 0);
     expect(10, r);
 
-    GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
+    GetWindowTextA(g_edit, text, ARRAY_SIZE(text));
     /* FIXME: currently hex output isn't properly formatted, but for this
        test only change from initial text matters */
     ok(lstrcmpA(text, "10") != 0, "Expected '0x000A', got '%s'\n", text);
@@ -830,20 +864,20 @@ static void test_UDS_SETBUDDYINT(void)
     style = GetWindowLongA(updown, GWL_STYLE);
     ok(style & UDS_SETBUDDYINT, "Expected UDS_SETBUDDY to be set\n");
     SendMessageA(updown, UDM_SETPOS, 0, 20);
-    GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
+    GetWindowTextA(g_edit, text, ARRAY_SIZE(text));
     ok(lstrlenA(text) == 0, "Expected empty string\n");
     DestroyWindow(updown);
 
     /* creating with UDS_SETBUDDYINT */
     updown = create_updown_control(UDS_SETBUDDYINT | UDS_ALIGNRIGHT, g_edit);
-    GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
+    GetWindowTextA(g_edit, text, ARRAY_SIZE(text));
     /* 50 is initial value here */
     ok(lstrcmpA(text, "50") == 0, "Expected '50', got '%s'\n", text);
     /* now remove style flag */
     style = GetWindowLongA(updown, GWL_STYLE);
     SetWindowLongA(updown, GWL_STYLE, style & ~UDS_SETBUDDYINT);
     SendMessageA(updown, UDM_SETPOS, 0, 20);
-    GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
+    GetWindowTextA(g_edit, text, ARRAY_SIZE(text));
     ok(lstrcmpA(text, "20") == 0, "Expected '20', got '%s'\n", text);
     /* set edit text directly, check position */
     strcpy(text, "10");
@@ -865,7 +899,7 @@ static void test_UDS_SETBUDDYINT(void)
     style = GetWindowLongA(updown, GWL_STYLE);
     SetWindowLongA(updown, GWL_STYLE, style | UDS_SETBUDDYINT);
     SendMessageA(updown, UDM_SETPOS, 0, 30);
-    GetWindowTextA(g_edit, text, sizeof(text)/sizeof(CHAR));
+    GetWindowTextA(g_edit, text, ARRAY_SIZE(text));
     ok(lstrcmpA(text, "30") == 0, "Expected '30', got '%s'\n", text);
     DestroyWindow(updown);
 }
@@ -877,7 +911,7 @@ static void test_CreateUpDownControl(void)
     RECT rect;
 
     GetClientRect(parent_wnd, &rect);
-    updown = CreateUpDownControl(WS_CHILD | WS_BORDER | WS_VISIBLE,
+    updown = pCreateUpDownControl(WS_CHILD | WS_BORDER | WS_VISIBLE,
         0, 0, rect.right, rect.bottom, parent_wnd, 1, GetModuleHandleA(NULL), g_edit, 100, 10, 50);
     ok(updown != NULL, "Failed to create control.\n");
 
@@ -893,13 +927,68 @@ static void test_CreateUpDownControl(void)
     DestroyWindow(updown);
 }
 
-START_TEST(updown)
+static void test_updown_pos_notifications(void)
 {
-    HMODULE mod = GetModuleHandleA("comctl32.dll");
+    HWND updown;
+    RECT rect;
+    UINT x, y;
+    int result;
+
+    /* test updown control notifications without UDS_HORZ style */
+    updown = create_updown_control(UDS_ALIGNRIGHT | UDS_SETBUDDYINT, g_edit);
+    SetFocus(updown);
+    flush_sequences(sequences, NUM_MSG_SEQUENCES);
+
+    /* click on the up-arrow button */
+    GetClientRect(updown, &rect);
+    x = rect.left + (rect.right - rect.left) / 2;
+    y = rect.top + (rect.bottom - rect.top) / 4;
+    result = SendMessageA(updown, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y));
+    expect(result, 0);
+    result = SendMessageA(updown, WM_LBUTTONUP, 0, MAKELPARAM(x, y));
+    expect(result, 0);
+
+    ok_sequence(sequences, PARENT_SEQ_INDEX, test_updown_pos_notifications_seq,
+                "test updown to parent notify (vertical)", FALSE);
 
-    pSetWindowSubclass = (void*)GetProcAddress(mod, (LPSTR)410);
+    DestroyWindow(updown);
+
+    /* test updown control notifications with UDS_HORZ style */
+    updown = create_updown_control(UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_HORZ, g_edit);
+    SetFocus(updown);
+    flush_sequences(sequences, NUM_MSG_SEQUENCES);
+
+    /* click on the right-arrow button */
+    GetClientRect(updown, &rect);
+    x = rect.left + (rect.right - rect.left) * 3 / 4;
+    y = rect.top + (rect.bottom - rect.top) / 2;
+    result = SendMessageA(updown, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y));
+    expect(result, 0);
+    result = SendMessageA(updown, WM_LBUTTONUP, 0, MAKELPARAM(x, y));
+    expect(result, 0);
+
+    ok_sequence(sequences, PARENT_SEQ_INDEX, test_updown_pos_notifications_horz_seq,
+                "test updown to parent notify (horizontal)", FALSE);
+
+    DestroyWindow(updown);
+}
+
+static void init_functions(void)
+{
+    HMODULE hComCtl32 = LoadLibraryA("comctl32.dll");
+
+#define X(f) p##f = (void*)GetProcAddress(hComCtl32, #f);
+#define X2(f, ord) p##f = (void*)GetProcAddress(hComCtl32, (const char *)ord);
+    X(CreateUpDownControl);
+    X2(SetWindowSubclass, 410);
+#undef X
+#undef X2
+}
+
+START_TEST(updown)
+{
+    init_functions();
 
-    InitCommonControls();
     init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
 
     parent_wnd = create_parent_window();
@@ -915,6 +1004,7 @@ START_TEST(updown)
     test_updown_unicode();
     test_UDS_SETBUDDYINT();
     test_CreateUpDownControl();
+    test_updown_pos_notifications();
 
     DestroyWindow(g_edit);
     DestroyWindow(parent_wnd);