Michael Stefaniuc : mshtml/tests: Get rid of a2bstr() in xmlhttprequest.c.
Alexandre Julliard
julliard at winehq.org
Wed Feb 12 16:21:06 CST 2020
Module: wine
Branch: master
Commit: da3a53ab205ea4dfe96cc34132ef874eae5e4245
URL: https://source.winehq.org/git/wine.git/?a=commit;h=da3a53ab205ea4dfe96cc34132ef874eae5e4245
Author: Michael Stefaniuc <mstefani at winehq.org>
Date: Wed Feb 12 00:32:49 2020 +0100
mshtml/tests: Get rid of a2bstr() in xmlhttprequest.c.
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/mshtml/tests/xmlhttprequest.c | 77 ++++++++++++++++----------------------
1 file changed, 33 insertions(+), 44 deletions(-)
diff --git a/dlls/mshtml/tests/xmlhttprequest.c b/dlls/mshtml/tests/xmlhttprequest.c
index 63df66ebe0..9280246b3c 100644
--- a/dlls/mshtml/tests/xmlhttprequest.c
+++ b/dlls/mshtml/tests/xmlhttprequest.c
@@ -28,18 +28,6 @@
#include "objsafe.h"
#include "wine/test.h"
-static BSTR a2bstr(const char *str)
-{
- BSTR ret;
- int len;
-
- len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
- ret = SysAllocStringLen(NULL, len);
- MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
-
- return ret;
-}
-
#define DEFINE_EXPECT(func) \
static BOOL expect_ ## func = FALSE, called_ ## func = FALSE
@@ -374,7 +362,7 @@ static void pump_msgs(BOOL *b)
struct HEADER_TYPE {
- const char *key;
+ const WCHAR *key;
const WCHAR *value;
};
@@ -428,16 +416,17 @@ static void test_header(const struct HEADER_TYPE expect[], int num)
for(i = 0; i < num; ++i) {
text = NULL;
- key = a2bstr(expect[i].key);
+ key = SysAllocString(expect[i].key);
hres = IHTMLXMLHttpRequest_getResponseHeader(xhr, key, &text);
ok(hres == S_OK, "getResponseHeader failed, got %08x\n", hres);
ok(text != NULL, "text == NULL\n");
ok(!lstrcmpW(text, expect[i].value),
- "Expect %s: %s, got %s\n", expect[i].key, wine_dbgstr_w(expect[i].value), wine_dbgstr_w(text));
+ "Expect %s: %s, got %s\n", wine_dbgstr_w(expect[i].key), wine_dbgstr_w(expect[i].value),
+ wine_dbgstr_w(text));
SysFreeString(key);
SysFreeString(text);
- wsprintfW(buf, L"%S: %s", expect[i].key, expect[i].value);
+ wsprintfW(buf, L"%s: %s", expect[i].key, expect[i].value);
ok(wcsstr(all, buf) != NULL, "AllResponseHeaders(%s) don't have expected substr(%s)\n",
wine_dbgstr_w(all), wine_dbgstr_w(buf));
}
@@ -485,9 +474,9 @@ static void test_illegal_xml(IXMLDOMDocument *xmldom)
}
#define set_request_header(a,b,c) _set_request_header(__LINE__,a,b,c)
-static void _set_request_header(unsigned line, IHTMLXMLHttpRequest *xhr, const char *header_a, const char *value_a)
+static void _set_request_header(unsigned line, IHTMLXMLHttpRequest *xhr, const WCHAR *header_w, const WCHAR *value_w)
{
- BSTR header = a2bstr(header_a), value = a2bstr(value_a);
+ BSTR header = SysAllocString(header_w), value = SysAllocString(value_w);
HRESULT hres;
hres = IHTMLXMLHttpRequest_setRequestHeader(xhr, header, value);
@@ -534,10 +523,10 @@ static void test_responseXML(const WCHAR *expect_text)
}
#define xhr_open(a,b) _xhr_open(__LINE__,a,b)
-static HRESULT _xhr_open(unsigned line, const char *url_a, const char *method_a)
+static HRESULT _xhr_open(unsigned line, const WCHAR *url_w, const WCHAR *method_w)
{
- BSTR method = a2bstr(method_a);
- BSTR url = a2bstr(url_a);
+ BSTR method = SysAllocString(method_w);
+ BSTR url = SysAllocString(url_w);
VARIANT async, empty;
HRESULT hres;
@@ -574,7 +563,7 @@ static void _test_response_text(unsigned line, const WCHAR *expect_text)
SysFreeString(text);
}
-static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url, const WCHAR *expect_text)
+static void test_sync_xhr(IHTMLDocument2 *doc, const WCHAR *xml_url, const WCHAR *expect_text)
{
VARIANT vbool, vempty, var;
BSTR method, url;
@@ -582,8 +571,8 @@ static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url, const WCHAR
LONG val;
HRESULT hres;
static const struct HEADER_TYPE expect_headers[] = {
- {"Content-Length", L"51"},
- {"Content-Type", L"application/xml"}
+ {L"Content-Length", L"51"},
+ {L"Content-Type", L"application/xml"}
};
trace("test_sync_xhr\n");
@@ -641,8 +630,8 @@ static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url, const WCHAR
ok(hres == E_FAIL, "got %08x\n", hres);
ok(text == NULL, "text = %p\n", text);
- method = a2bstr("GET");
- url = a2bstr(xml_url);
+ method = SysAllocString(L"GET");
+ url = SysAllocString(xml_url);
V_VT(&vbool) = VT_BOOL;
V_BOOL(&vbool) = VARIANT_FALSE;
V_VT(&vempty) = VT_EMPTY;
@@ -685,7 +674,7 @@ static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url, const WCHAR
ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
ok(val == 1, "Expect OPENED, got %d\n", val);
- set_request_header(xhr, "x-wine-test", "sync-test");
+ set_request_header(xhr, L"x-wine-test", L"sync-test");
SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
SET_EXPECT(xmlhttprequest_onreadystatechange_headers_received);
@@ -733,15 +722,15 @@ static void test_sync_xhr(IHTMLDocument2 *doc, const char *xml_url, const WCHAR
xhr = NULL;
}
-static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url, const WCHAR *expect_text)
+static void test_async_xhr(IHTMLDocument2 *doc, const WCHAR *xml_url, const WCHAR *expect_text)
{
VARIANT var, vempty;
BSTR text;
LONG val;
HRESULT hres;
static const struct HEADER_TYPE expect_headers[] = {
- {"Content-Length", L"51"},
- {"Content-Type", L"application/xml"}
+ {L"Content-Length", L"51"},
+ {L"Content-Type", L"application/xml"}
};
create_xmlhttprequest(doc);
@@ -798,7 +787,7 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url, const WCHAR
ok(val == 0, "Expect UNSENT, got %d\n", val);
SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
- hres = xhr_open(xml_url, "GET");
+ hres = xhr_open(xml_url, L"GET");
CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
if(FAILED(hres)) {
@@ -831,7 +820,7 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url, const WCHAR
ok(hres == S_OK, "get_readyState failed: %08x\n", hres);
ok(val == 1, "Expect OPENED, got %d\n", val);
- set_request_header(xhr, "x-wine-test", "async-test");
+ set_request_header(xhr, L"x-wine-test", L"async-test");
SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
SET_EXPECT(xmlhttprequest_onreadystatechange_headers_received);
@@ -891,7 +880,7 @@ static void test_async_xhr(IHTMLDocument2 *doc, const char *xml_url, const WCHAR
xhr = NULL;
}
-static void test_async_xhr_abort(IHTMLDocument2 *doc, const char *xml_url)
+static void test_async_xhr_abort(IHTMLDocument2 *doc, const WCHAR *xml_url)
{
VARIANT vempty, var;
LONG val;
@@ -909,7 +898,7 @@ static void test_async_xhr_abort(IHTMLDocument2 *doc, const char *xml_url)
hres = IHTMLXMLHttpRequest_put_onreadystatechange(xhr, var);
SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
- xhr_open(xml_url, "GET");
+ xhr_open(xml_url, L"GET");
CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
hres = IHTMLXMLHttpRequest_abort(xhr);
@@ -933,7 +922,7 @@ static void test_async_xhr_abort(IHTMLDocument2 *doc, const char *xml_url)
hres = IHTMLXMLHttpRequest_put_onreadystatechange(xhr, var);
SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
- xhr_open(xml_url, "GET");
+ xhr_open(xml_url, L"GET");
CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
loading_cnt = 0;
@@ -980,13 +969,13 @@ static void test_xhr_post(IHTMLDocument2 *doc)
ok(hres == S_OK, "put_onreadystatechange failed: %08x\n", hres);
SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
- xhr_open("http://test.winehq.org/tests/post.php", "POST");
+ xhr_open(L"http://test.winehq.org/tests/post.php", L"POST");
CHECK_CALLED(xmlhttprequest_onreadystatechange_opened);
- set_request_header(xhr, "Content-Type", "application/x-www-form-urlencoded");
+ set_request_header(xhr, L"Content-Type", L"application/x-www-form-urlencoded");
V_VT(&v) = VT_BSTR;
- V_BSTR(&v) = a2bstr("X=Testing");
+ V_BSTR(&v) = SysAllocString(L"X=Testing");
loading_cnt = 0;
SET_EXPECT(xmlhttprequest_onreadystatechange_opened);
@@ -1013,7 +1002,7 @@ static void test_xhr_post(IHTMLDocument2 *doc)
xhr = NULL;
}
-static IHTMLDocument2 *create_doc_from_url(const char *start_url)
+static IHTMLDocument2 *create_doc_from_url(const WCHAR *start_url)
{
BSTR url;
IBindCtx *bc;
@@ -1025,7 +1014,7 @@ static IHTMLDocument2 *create_doc_from_url(const char *start_url)
hres = CreateBindCtx(0, &bc);
ok(hres == S_OK, "CreateBindCtx failed: 0x%08x\n", hres);
- url = a2bstr(start_url);
+ url = SysAllocString(start_url);
hres = CreateURLMoniker(NULL, url, &url_mon);
ok(hres == S_OK, "CreateURLMoniker failed: 0x%08x\n", hres);
@@ -1058,14 +1047,14 @@ static IHTMLDocument2 *create_doc_from_url(const char *start_url)
START_TEST(xmlhttprequest)
{
IHTMLDocument2 *doc;
- static const char start_url[] = "http://test.winehq.org/tests/hello.html";
- static const char xml_url[] = "http://test.winehq.org/tests/xmltest.xml";
- static const char large_page_url[] = "http://test.winehq.org/tests/data.php";
+ static const WCHAR start_url[] = L"http://test.winehq.org/tests/hello.html";
+ static const WCHAR xml_url[] = L"http://test.winehq.org/tests/xmltest.xml";
+ static const WCHAR large_page_url[] = L"http://test.winehq.org/tests/data.php";
static const WCHAR expect_response_text[] = L"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<a>TEST</a>";
CoInitialize(NULL);
- content_type = a2bstr("Content-Type");
+ content_type = SysAllocString(L"Content-Type");
doc = create_doc_from_url(start_url);
if(doc) {
test_sync_xhr(doc, xml_url, expect_response_text);
More information about the wine-cvs
mailing list