Dylan Smith : richedit: Return number of bytes read for EM_STREAMIN with SF_TEXT.
Alexandre Julliard
julliard at winehq.org
Mon Sep 26 16:15:08 CDT 2011
Module: wine
Branch: master
Commit: e060272de73d909fb39c7a8a1952a2fbd75141c0
URL: http://source.winehq.org/git/wine.git/?a=commit;h=e060272de73d909fb39c7a8a1952a2fbd75141c0
Author: Dylan Smith <dylan.ah.smith at gmail.com>
Date: Sun Sep 25 22:17:19 2011 -0400
richedit: Return number of bytes read for EM_STREAMIN with SF_TEXT.
---
dlls/riched20/editor.c | 17 +++++++++------
dlls/riched20/tests/editor.c | 46 ++++++++++++++++++++++++++++++++---------
2 files changed, 46 insertions(+), 17 deletions(-)
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 3c409e4..8051889 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -285,9 +285,10 @@ static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStrea
{
WCHAR wszText[STREAMIN_BUFFER_SIZE+1];
WCHAR *pText;
-
+ LRESULT total_bytes_read = 0;
+
TRACE("%08x %p\n", dwFormat, stream);
-
+
do {
LONG nWideChars = 0;
@@ -298,8 +299,9 @@ static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStrea
break;
if (!stream->dwSize)
break;
+ total_bytes_read += stream->dwSize;
}
-
+
if (!(dwFormat & SF_UNICODE))
{
/* FIXME? this is doomed to fail on true MBCS like UTF-8, luckily they're unlikely to be used as CP_ACP */
@@ -311,13 +313,13 @@ static LRESULT ME_StreamInText(ME_TextEditor *editor, DWORD dwFormat, ME_InStrea
nWideChars = stream->dwSize >> 1;
pText = (WCHAR *)stream->buffer;
}
-
+
ME_InsertTextFromCursor(editor, 0, pText, nWideChars, style);
if (stream->dwSize == 0)
break;
stream->dwSize = 0;
} while(1);
- return 0;
+ return total_bytes_read;
}
static void ME_ApplyBorderProperties(RTF_Info *info,
@@ -1390,6 +1392,7 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre
ME_InStream inStream;
BOOL invalidRTF = FALSE;
ME_Cursor *selStart, *selEnd;
+ LRESULT num_read = 0; /* bytes read for SF_TEXT, non-control chars inserted for SF_RTF */
TRACE("stream==%p editor==%p format==0x%X\n", stream, editor, format);
editor->nEventMask = 0;
@@ -1564,7 +1567,7 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre
style = parser.style;
}
else if (format & SF_TEXT)
- ME_StreamInText(editor, format, &inStream, style);
+ num_read = ME_StreamInText(editor, format, &inStream, style);
else
ERR("EM_STREAMIN without SF_TEXT or SF_RTF\n");
/* put the cursor at the top */
@@ -1594,7 +1597,7 @@ static LRESULT ME_StreamIn(ME_TextEditor *editor, DWORD format, EDITSTREAM *stre
ME_SendSelChange(editor);
ME_SendRequestResize(editor, FALSE);
- return 0;
+ return num_read;
}
diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c
index 77ce09e..5058b7a 100644
--- a/dlls/riched20/tests/editor.c
+++ b/dlls/riched20/tests/editor.c
@@ -5040,20 +5040,29 @@ static void test_EM_STREAMIN(void)
const char * streamText3 = "RichEdit1";
- struct StringWithLength cookieForStream4;
const char * streamText4 =
"This text just needs to be long enough to cause run to be split onto "
"two separate lines and make sure the null terminating character is "
"handled properly.\0";
int length4 = strlen(streamText4) + 1;
- cookieForStream4.buffer = (char *)streamText4;
- cookieForStream4.length = length4;
+ struct StringWithLength cookieForStream4 = {
+ length4,
+ (char *)streamText4,
+ };
+
+ const WCHAR streamText5[] = { 'T', 'e', 's', 't', 'S', 'o', 'm', 'e', 'T', 'e', 'x', 't' };
+ int length5 = sizeof(streamText5) / sizeof(WCHAR);
+ struct StringWithLength cookieForStream5 = {
+ sizeof(streamText5),
+ (char *)streamText5,
+ };
/* Minimal test without \par at the end */
es.dwCookie = (DWORD_PTR)&streamText0;
es.dwError = 0;
es.pfnCallback = test_EM_STREAMIN_esCallback;
- SendMessage(hwndRichEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
+ result = SendMessage(hwndRichEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
+ todo_wine ok(result == 12, "got %ld, expected %d\n", result, 12);
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok (result == 12,
@@ -5067,7 +5076,8 @@ static void test_EM_STREAMIN(void)
es.dwCookie = (DWORD_PTR)&streamText0a;
es.dwError = 0;
es.pfnCallback = test_EM_STREAMIN_esCallback;
- SendMessage(hwndRichEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
+ result = SendMessage(hwndRichEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
+ todo_wine ok(result == 12, "got %ld, expected %d\n", result, 12);
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok (result == 12,
@@ -5081,7 +5091,8 @@ static void test_EM_STREAMIN(void)
es.dwCookie = (DWORD_PTR)&streamText0b;
es.dwError = 0;
es.pfnCallback = test_EM_STREAMIN_esCallback;
- SendMessage(hwndRichEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
+ result = SendMessage(hwndRichEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
+ todo_wine ok(result == 13, "got %ld, expected %d\n", result, 13);
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok (result == 14,
@@ -5094,7 +5105,8 @@ static void test_EM_STREAMIN(void)
es.dwCookie = (DWORD_PTR)&streamText1;
es.dwError = 0;
es.pfnCallback = test_EM_STREAMIN_esCallback;
- SendMessage(hwndRichEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
+ result = SendMessage(hwndRichEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
+ todo_wine ok(result == 12, "got %ld, expected %d\n", result, 12);
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok (result == 12,
@@ -5106,7 +5118,8 @@ static void test_EM_STREAMIN(void)
es.dwCookie = (DWORD_PTR)&streamText2;
es.dwError = 0;
- SendMessage(hwndRichEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
+ result = SendMessage(hwndRichEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
+ ok(result == 0, "got %ld, expected %d\n", result, 0);
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok (result == 0,
@@ -5117,7 +5130,8 @@ static void test_EM_STREAMIN(void)
es.dwCookie = (DWORD_PTR)&streamText3;
es.dwError = 0;
- SendMessage(hwndRichEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
+ result = SendMessage(hwndRichEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
+ ok(result == 0, "got %ld, expected %d\n", result, 0);
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok (result == 0,
@@ -5129,13 +5143,25 @@ static void test_EM_STREAMIN(void)
es.dwCookie = (DWORD_PTR)&cookieForStream4;
es.dwError = 0;
es.pfnCallback = test_EM_STREAMIN_esCallback2;
- SendMessage(hwndRichEdit, EM_STREAMIN, SF_TEXT, (LPARAM)&es);
+ result = SendMessage(hwndRichEdit, EM_STREAMIN, SF_TEXT, (LPARAM)&es);
+ ok(result == length4, "got %ld, expected %d\n", result, length4);
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok (result == length4,
"EM_STREAMIN: Test 4 returned %ld, expected %d\n", result, length4);
ok(es.dwError == 0, "EM_STREAMIN: Test 4 set error %d, expected %d\n", es.dwError, 0);
+ es.dwCookie = (DWORD_PTR)&cookieForStream5;
+ es.dwError = 0;
+ es.pfnCallback = test_EM_STREAMIN_esCallback2;
+ result = SendMessage(hwndRichEdit, EM_STREAMIN, SF_TEXT | SF_UNICODE, (LPARAM)&es);
+ ok(result == sizeof(streamText5), "got %ld, expected %u\n", result, (UINT)sizeof(streamText5));
+
+ result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
+ ok (result == length5,
+ "EM_STREAMIN: Test 4 returned %ld, expected %d\n", result, length5);
+ ok(es.dwError == 0, "EM_STREAMIN: Test 5 set error %d, expected %d\n", es.dwError, 0);
+
DestroyWindow(hwndRichEdit);
}
More information about the wine-cvs
mailing list