Alexandre Julliard : tests: Make wine_dbgstr_w available in test. h for all tests.
Alexandre Julliard
julliard at winehq.org
Wed Aug 19 11:32:05 CDT 2009
Module: wine
Branch: master
Commit: ee868cce5b412b103ff167deb59c3d5237363199
URL: http://source.winehq.org/git/wine.git/?a=commit;h=ee868cce5b412b103ff167deb59c3d5237363199
Author: Alexandre Julliard <julliard at winehq.org>
Date: Wed Aug 19 13:19:31 2009 +0200
tests: Make wine_dbgstr_w available in test.h for all tests.
---
dlls/kernel32/tests/process.c | 17 --------
dlls/ntdsapi/tests/ntdsapi.c | 9 ----
dlls/oleaut32/tests/tmarshal.c | 80 --------------------------------------
dlls/shell32/tests/shlfolder.c | 9 ----
include/wine/test.h | 83 +++++++++++++++++++++++++++++++++++++++-
5 files changed, 82 insertions(+), 116 deletions(-)
diff --git a/dlls/kernel32/tests/process.c b/dlls/kernel32/tests/process.c
index 21f3c52..5d8f65b 100644
--- a/dlls/kernel32/tests/process.c
+++ b/dlls/kernel32/tests/process.c
@@ -54,23 +54,6 @@
wine_dbgstr_w(expected), wine_dbgstr_w(value)); \
} while (0)
-/* A simpler version of wine_dbgstr_w. Note that the returned buffer will be
- * invalid after 16 calls to this funciton. */
-static const char *wine_dbgstr_w(LPCWSTR wstr)
-{
- static char *buffers[16];
- static int curr_buffer = 0;
-
- int size;
-
- curr_buffer = (curr_buffer + 1) % 16;
- HeapFree(GetProcessHeap(), 0, buffers[curr_buffer]);
- size = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);
- buffers[curr_buffer] = HeapAlloc(GetProcessHeap(), 0, size);
- size = WideCharToMultiByte(CP_ACP, 0, wstr, -1, buffers[curr_buffer], size, NULL, NULL);
- return buffers[curr_buffer];
-}
-
static HINSTANCE hkernel32;
static LPVOID (WINAPI *pVirtualAllocEx)(HANDLE, LPVOID, SIZE_T, DWORD, DWORD);
static BOOL (WINAPI *pVirtualFreeEx)(HANDLE, LPVOID, SIZE_T, DWORD);
diff --git a/dlls/ntdsapi/tests/ntdsapi.c b/dlls/ntdsapi/tests/ntdsapi.c
index 08436ae..8290ed2 100644
--- a/dlls/ntdsapi/tests/ntdsapi.c
+++ b/dlls/ntdsapi/tests/ntdsapi.c
@@ -28,15 +28,6 @@
#include "wine/test.h"
-static const char *wine_dbgstr_w(LPCWSTR str)
-{
- static char buf[512];
- if (!str)
- return "(null)";
- WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
- return buf;
-}
-
static void test_DsMakeSpn(void)
{
DWORD ret;
diff --git a/dlls/oleaut32/tests/tmarshal.c b/dlls/oleaut32/tests/tmarshal.c
index ec23204..80148ff 100644
--- a/dlls/oleaut32/tests/tmarshal.c
+++ b/dlls/oleaut32/tests/tmarshal.c
@@ -44,86 +44,6 @@ const MYSTRUCT MYSTRUCT_ARRAY[5] = {
{0x5a5b5c5d, ULL_CONST(0x5e5f5051, 0x52535455)},
};
-/* Debugging functions from wine/libs/wine/debug.c */
-
-/* allocate some tmp string space */
-/* FIXME: this is not 100% thread-safe */
-static char *get_tmp_space( int size )
-{
- static char *list[32];
- static long pos;
- char *ret;
- int idx;
-
- idx = ++pos % (sizeof(list)/sizeof(list[0]));
- if (list[idx])
- ret = HeapReAlloc( GetProcessHeap(), 0, list[idx], size );
- else
- ret = HeapAlloc( GetProcessHeap(), 0, size );
- if (ret) list[idx] = ret;
- return ret;
-}
-
-/* default implementation of wine_dbgstr_wn */
-static const char *default_dbgstr_wn( const WCHAR *str, int n )
-{
- char *dst, *res;
-
- if (!HIWORD(str))
- {
- if (!str) return "(null)";
- res = get_tmp_space( 6 );
- sprintf( res, "#%04x", LOWORD(str) );
- return res;
- }
- if (n == -1) n = lstrlenW(str);
- if (n < 0) n = 0;
- else if (n > 200) n = 200;
- dst = res = get_tmp_space( n * 5 + 7 );
- *dst++ = 'L';
- *dst++ = '"';
- while (n-- > 0)
- {
- WCHAR c = *str++;
- switch (c)
- {
- case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
- case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
- case '\t': *dst++ = '\\'; *dst++ = 't'; break;
- case '"': *dst++ = '\\'; *dst++ = '"'; break;
- case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
- default:
- if (c >= ' ' && c <= 126)
- *dst++ = (char)c;
- else
- {
- *dst++ = '\\';
- sprintf(dst,"%04x",c);
- dst+=4;
- }
- }
- }
- *dst++ = '"';
- if (*str)
- {
- *dst++ = '.';
- *dst++ = '.';
- *dst++ = '.';
- }
- *dst = 0;
- return res;
-}
-
-const char *wine_dbgstr_wn( const WCHAR *s, int n )
-{
- return default_dbgstr_wn(s, n);
-}
-
-const char *wine_dbgstr_w( const WCHAR *s )
-{
- return default_dbgstr_wn( s, -1 );
-}
-
#define RELEASEMARSHALDATA WM_USER
diff --git a/dlls/shell32/tests/shlfolder.c b/dlls/shell32/tests/shlfolder.c
index 535c9ad..ed3a8b5 100644
--- a/dlls/shell32/tests/shlfolder.c
+++ b/dlls/shell32/tests/shlfolder.c
@@ -81,15 +81,6 @@ static void init_function_pointers(void)
ok(hr == S_OK, "SHGetMalloc failed %08x\n", hr);
}
-static const char *wine_dbgstr_w(LPCWSTR str)
-{
- static char buf[512];
- if (!str)
- return "(null)";
- WideCharToMultiByte(CP_ACP, 0, str, -1, buf, sizeof(buf), NULL, NULL);
- return buf;
-}
-
static void test_ParseDisplayName(void)
{
HRESULT hr;
diff --git a/include/wine/test.h b/include/wine/test.h
index a8f6f03..42a56c0 100644
--- a/include/wine/test.h
+++ b/include/wine/test.h
@@ -62,6 +62,9 @@ extern void winetest_end_todo( const char* platform );
extern int winetest_get_mainargs( char*** pargv );
extern void winetest_wait_child_process( HANDLE process );
+extern const char *wine_dbgstr_wn( const WCHAR *str, int n );
+static inline const char *wine_dbgstr_w( const WCHAR *s ) { return wine_dbgstr_wn( s, -1 ); }
+
#ifdef STANDALONE
#define START_TEST(name) \
static void func_##name(void); \
@@ -196,6 +199,8 @@ typedef struct
int current_line; /* line of current check */
int todo_level; /* current todo nesting level */
int todo_do_loop;
+ char *str_pos; /* position in debug buffer */
+ char strings[2000]; /* buffer for debug strings */
} tls_data;
static DWORD tls_index;
@@ -208,13 +213,33 @@ static tls_data* get_tls_data(void)
data=TlsGetValue(tls_index);
if (!data)
{
- data=HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(tls_data));
+ data=HeapAlloc(GetProcessHeap(), 0, sizeof(tls_data));
+ data->todo_level = 0;
+ data->str_pos = data->strings;
TlsSetValue(tls_index,data);
}
SetLastError(last_error);
return data;
}
+/* allocate some tmp space for a string */
+static char *get_temp_buffer( size_t n )
+{
+ tls_data *data = get_tls_data();
+ char *res = data->str_pos;
+
+ if (res + n >= &data->strings[sizeof(data->strings)]) res = data->strings;
+ data->str_pos = res + n;
+ return res;
+}
+
+/* release extra space that we requested in gimme1() */
+static void release_temp_buffer( char *ptr, size_t size )
+{
+ tls_data *data = get_tls_data();
+ data->str_pos = ptr + size;
+}
+
static void exit_process( int code )
{
fflush( stdout );
@@ -407,6 +432,62 @@ void winetest_wait_child_process( HANDLE process )
}
}
+const char *wine_dbgstr_wn( const WCHAR *str, int n )
+{
+ char *dst, *res;
+ size_t size;
+
+ if (!((ULONG_PTR)str >> 16))
+ {
+ if (!str) return "(null)";
+ res = get_temp_buffer( 6 );
+ sprintf( res, "#%04x", LOWORD(str) );
+ return res;
+ }
+ if (n == -1)
+ {
+ const WCHAR *end = str;
+ while (*end) end++;
+ n = end - str;
+ }
+ if (n < 0) n = 0;
+ size = 12 + min( 300, n * 5 );
+ dst = res = get_temp_buffer( size );
+ *dst++ = 'L';
+ *dst++ = '"';
+ while (n-- > 0 && dst <= res + size - 10)
+ {
+ WCHAR c = *str++;
+ switch (c)
+ {
+ case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
+ case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
+ case '\t': *dst++ = '\\'; *dst++ = 't'; break;
+ case '"': *dst++ = '\\'; *dst++ = '"'; break;
+ case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
+ default:
+ if (c >= ' ' && c <= 126)
+ *dst++ = c;
+ else
+ {
+ *dst++ = '\\';
+ sprintf(dst,"%04x",c);
+ dst+=4;
+ }
+ }
+ }
+ *dst++ = '"';
+ if (n > 0)
+ {
+ *dst++ = '.';
+ *dst++ = '.';
+ *dst++ = '.';
+ }
+ *dst++ = 0;
+ release_temp_buffer( res, dst - res );
+ return res;
+}
+
/* Find a test by name */
static const struct test *find_test( const char *name )
{
More information about the wine-cvs
mailing list