From 48fab6fe7280a30bd60a2f8372d68121226e5839 Mon Sep 17 00:00:00 2001
From: James McKenzie <jjmckenzie51@earthlink.net>
Date: Sun, 20 Jun 2010 16:55:28 -0700
Subject: richedit: Add EM_FINDWORDBREAK tests
 Based on code submitted in 2006 by Brian Chang.

---
 dlls/riched20/tests/editor.c |   92 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 92 insertions(+), 0 deletions(-)

diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c
index 685eead..74f7267 100644
--- a/dlls/riched20/tests/editor.c
+++ b/dlls/riched20/tests/editor.c
@@ -7062,6 +7062,97 @@ static void test_dialogmode(void)
     DestroyWindow(hwParent);
 }
 
+static void test_EM_FINDWORDBREAK(void)
+{
+    HWND hwndRichEdit = new_richedit(NULL);
+    long result;
+    static const char text[] = "Text for wordbreak proc!!!    test.member ...";
+    /*                          012345678901234567890123456789012345678901234
+     *                                   10        20        30        40
+     */
+    GETTEXTLENGTHEX gtl;
+    int len;
+
+    SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text);
+
+    gtl.flags = GTL_NUMCHARS | GTL_PRECISE;
+    gtl.codepage = CP_ACP;
+    len = SendMessageA(hwndRichEdit, EM_GETTEXTLENGTHEX, (WPARAM)&gtl, 0);
+
+    /* starting position of 'for' */
+    result = SendMessage(hwndRichEdit, EM_FINDWORDBREAK, WB_MOVEWORDRIGHT, 0);
+    todo_wine {
+      ok(result == 5, "EM_FINDWORDBREAK: expected: 5 actual: %ld\n", result);
+    }
+
+    /* strating position of '!!!' */
+    result = SendMessage(hwndRichEdit, EM_FINDWORDBREAK, WB_MOVEWORDRIGHT, 21);
+    todo_wine {
+      ok(result == 23, "EM_FINDWORDBREAK: expected: 23 actual: %ld\n", result);
+    }
+
+    /* starting position of 'test' */
+    result = SendMessage(hwndRichEdit, EM_FINDWORDBREAK, WB_MOVEWORDRIGHT, 27);
+    todo_wine {
+      ok(result == 30, "EM_FINDWORDBREAK: expected: 30 actual: %ld\n", result);
+    }
+
+    /* position right before 'member' */
+    result = SendMessage(hwndRichEdit, EM_FINDWORDBREAK, WB_MOVEWORDRIGHT, 31);
+    todo_wine {
+      ok(result == 34, "EM_FINDWORDBREAK: expected: 34 actual: %ld\n", result);
+    }
+
+    /* the position of null char */
+    result = SendMessage(hwndRichEdit, EM_FINDWORDBREAK, WB_MOVEWORDRIGHT, 42);
+    todo_wine {
+      ok(result == 45, "EM_FINDWORDBREAK: expected: 45 actual: %ld\n", result);
+    }
+
+    /* starting position of '...' */
+    result = SendMessage(hwndRichEdit, EM_FINDWORDBREAK, WB_MOVEWORDLEFT, 44);
+    todo_wine {
+      ok(result == 42, "EM_FINDWORDBREAK: expected: 42 actual: %ld\n", result);
+    }
+
+    /* position right after 'test.' */
+    result = SendMessage(hwndRichEdit, EM_FINDWORDBREAK, WB_MOVEWORDLEFT, 36);
+    todo_wine {
+      ok(result == 35, "EM_FINDWORDBREAK: expected: 35 actual: %ld\n", result);
+    }
+
+    /* position right after 'proc' */
+    result = SendMessage(hwndRichEdit, EM_FINDWORDBREAK, WB_MOVEWORDLEFT, 27);
+    todo_wine {
+      ok(result == 23, "EM_FINDWORDBREAK: expected: 23 actual: %ld\n", result);
+    }
+
+    /* beginning position */
+    result = SendMessage(hwndRichEdit, EM_FINDWORDBREAK, WB_MOVEWORDLEFT, 5);
+    todo_wine {
+      ok(result == 0, "EM_FINDWORDBREAK: expected: 0 actual: %ld\n", result);
+    }
+
+    /* position right after beginning */
+    result = SendMessage(hwndRichEdit, EM_FINDWORDBREAK, WB_MOVEWORDLEFT, 3);
+    todo_wine {
+      ok(result == 0, "EM_FINDWORDBREAK: expected: 0 actual: %ld\n", result);
+    }
+
+    /* Test underflow/overflow conditions per Dan Kegal msg 16 March 2006 */
+    result = SendMessage(hwndRichEdit, EM_FINDWORDBREAK, WB_MOVEWORDLEFT, -2);
+    todo_wine {
+       ok(result == 0,"EM_FINDWORDBREAK: expected: 0 actual: %ld\n", result);
+    }
+
+    result = SendMessage(hwndRichEdit, EM_FINDWORDBREAK, WB_MOVEWORDRIGHT, len+2);
+    todo_wine {
+      ok(result == len+1,"EM_FINDWORDBREAK: expected: %d actual: %ld\n", len+1, result);
+    }
+
+    DestroyWindow(hwndRichEdit);
+}
+
 START_TEST( editor )
 {
   /* Must explicitly LoadLibrary(). The test has no references to functions in
@@ -7119,6 +7210,7 @@ START_TEST( editor )
   test_WM_GETDLGCODE();
   test_zoom();
   test_dialogmode();
+  test_EM_FINDWORDBREAK();
 
   /* Set the environment variable WINETEST_RICHED20 to keep windows
    * responsive and open for 30 seconds. This is useful for debugging.
-- 
1.7.1

