From 16d1b3b0261eed9e8881890783c26a214185dd0c Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Wed, 13 Feb 2013 18:57:38 +0100 Subject: [PATCH] oleaut32: Added some SysFreeString tests. --- dlls/oleaut32/tests/vartype.c | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/dlls/oleaut32/tests/vartype.c b/dlls/oleaut32/tests/vartype.c index 58b30b1c892..8ad549e5712 100644 --- a/dlls/oleaut32/tests/vartype.c +++ b/dlls/oleaut32/tests/vartype.c @@ -6072,6 +6072,47 @@ static void test_ChangeType_keep_dst(void) SysFreeString(bstr); } +/* This tests assumes an empty cache, so it needs to be ran early in the test. */ +static void test_bstr_cache(void) +{ + BSTR str, str2, strs[20]; + unsigned i; + + static const WCHAR testW[] = {'t','e','s','t',0}; + + str = SysAllocString(testW); + /* This should put the string into cache */ + SysFreeString(str); + /* The string is in cache, this won't touch it */ + SysFreeString(str); + + ok(SysStringLen(str) == 4, "unexpected len\n"); + ok(!lstrcmpW(str, testW), "string changed\n"); + + str2 = SysAllocString(testW); + ok(str == str2, "str != str2\n"); + SysFreeString(str2); + + /* Fill the bucket with cached entries. */ + for(i=0; i < sizeof(strs)/sizeof(*strs); i++) + strs[i] = SysAllocStringLen(NULL, 24); + for(i=0; i < sizeof(strs)/sizeof(*strs); i++) + SysFreeString(strs[i]); + + /* Following allocation will be made from cache */ + str = SysAllocStringLen(NULL, 24); + ok(str == strs[0], "str != strs[0]\n"); + + /* Smaller buffers may also use larget cached buffers */ + str2 = SysAllocStringLen(NULL, 16); + ok(str2 == strs[1], "str2 != strs[1]\n"); + + SysFreeString(str); + SysFreeString(str2); + SysFreeString(str); + SysFreeString(str2); +} + START_TEST(vartype) { hOleaut32 = GetModuleHandleA("oleaut32.dll"); @@ -6079,6 +6120,8 @@ START_TEST(vartype) trace("LCIDs: System=0x%08x, User=0x%08x\n", GetSystemDefaultLCID(), GetUserDefaultLCID()); + test_bstr_cache(); + test_VarI1FromI2(); test_VarI1FromI4(); test_VarI1FromI8();