ReactOS  0.4.13-dev-544-gede3fdd
CComBSTR.cpp File Reference
#include <apitest.h>
#include <atlbase.h>
#include "resource.h"
Include dependency graph for CComBSTR.cpp:

Go to the source code of this file.

Macros

#define verify_str   (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : verify_str_imp
 
#define verify_str2   (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : verify_str_imp2
 

Functions

static void verify_str_imp2 (const CComBSTR &comstr, PCWSTR expected, size_t ExpectedLength)
 
static void verify_str_imp (const CComBSTR &comstr, PCWSTR expected)
 
void test_construction ()
 
void test_copyassignment ()
 
void test_fromguid ()
 
void test_loadres ()
 
 START_TEST (CComBSTR)
 

Macro Definition Documentation

◆ verify_str

#define verify_str   (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : verify_str_imp

Definition at line 13 of file CComBSTR.cpp.

◆ verify_str2

#define verify_str2   (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : verify_str_imp2

Definition at line 14 of file CComBSTR.cpp.

Function Documentation

◆ START_TEST()

START_TEST ( CComBSTR  )

Definition at line 143 of file CComBSTR.cpp.

144 {
147  test_fromguid();
148  test_loadres();
149 }
void test_fromguid()
Definition: CComBSTR.cpp:119
void test_loadres()
Definition: CComBSTR.cpp:129
void test_construction()
Definition: CComBSTR.cpp:47
void test_copyassignment()
Definition: CComBSTR.cpp:71

◆ test_construction()

void test_construction ( )

Definition at line 47 of file CComBSTR.cpp.

48 {
49  CComBSTR empty1, empty2;
50  CComBSTR happyW(L"I am a happy BSTR");
51  CComBSTR happyA("I am a happy BSTR");
52  CComBSTR happyW4(4, L"I am a happy BSTR");
53  CComBSTR fromlen1(1), fromlen10(10);
54  CComBSTR fromBSTRW(happyW), fromBSTRA(happyA), fromBSTRW4(happyW4);
55  CComBSTR fromBSTRlen1(fromlen1), fromBSTRlen10(fromlen10);
56 
57  verify_str(empty1, NULL);
58  verify_str(empty2, NULL);
59  verify_str(happyW, L"I am a happy BSTR");
60  verify_str(happyA, L"I am a happy BSTR");
61  verify_str(happyW4, L"I am");
62  verify_str2(fromlen1, NULL, 1);
63  verify_str2(fromlen10, NULL, 10);
64  verify_str(fromBSTRW, L"I am a happy BSTR");
65  verify_str(fromBSTRA, L"I am a happy BSTR");
66  verify_str(fromBSTRW4, L"I am");
67  verify_str2(fromBSTRlen1, NULL, 1);
68  verify_str2(fromBSTRlen10, NULL, 10);
69 }
#define verify_str
Definition: CComBSTR.cpp:13
#define verify_str2
Definition: CComBSTR.cpp:14
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR L[]
Definition: oid.c:1250

Referenced by START_TEST().

◆ test_copyassignment()

void test_copyassignment ( )

Definition at line 71 of file CComBSTR.cpp.

72 {
73  CComBSTR happy(L"I am a happy BSTR"), empty, odd;
74  CComBSTR happyCopy1, happyCopy2, emptyCopy, oddCopy;
75 
76  odd = ::SysAllocStringByteLen("aaaaa", 3);
77 
78  happyCopy1 = happy.Copy();
79  happyCopy2 = happy; // Calls happyW.Copy()
80  emptyCopy = empty.Copy();
81  oddCopy = odd.Copy();
82 
83  verify_str(happy, L"I am a happy BSTR");
85  verify_str2(odd, L"\u6161a", 2);
86  verify_str(happyCopy1, L"I am a happy BSTR");
87  verify_str(happyCopy2, L"I am a happy BSTR");
88  verify_str(emptyCopy, NULL);
89  verify_str2(oddCopy, L"\u6161a", 2);
90  ok((BSTR)happy != (BSTR)happyCopy1, "Expected pointers to be different\n");
91  ok((BSTR)happy != (BSTR)happyCopy2, "Expected pointers to be different\n");
92 
93 
94  happyCopy1 = (LPCOLESTR)NULL;
95  happyCopy2 = (LPCSTR)NULL;
96 
97  verify_str(happyCopy1, NULL);
98  verify_str(happyCopy2, NULL);
99 
100  HRESULT hr = happy.CopyTo(&happyCopy1);
101  ok(hr == S_OK, "Expected hr to be E_POINTER, was: %08lx\n", hr);
102 
103 #if 0
104  // This asserts
105  hr = happy.CopyTo((BSTR*)NULL);
106  ok(hr == E_POINTER, "Expected hr to be E_POINTER, was: %u\n");
107 #endif
108 
109  BSTR RawPtr = ::SysAllocString(L"TEST--");
110  happy.Attach(RawPtr);
111  ok_ptr(happy.m_str, RawPtr);
112  verify_str(happy, L"TEST--");
113  happyCopy1.Attach(happy.Detach());
114  ok_ptr(happyCopy1.m_str, RawPtr);
115  verify_str(happyCopy1, L"TEST--");
116  ok_ptr(happy.m_str, NULL);
117 }
HRESULT hr
Definition: shlfolder.c:183
static const WCHAR empty[]
Definition: main.c:49
#define verify_str
Definition: CComBSTR.cpp:13
Definition: unary.h:11
OLECHAR * BSTR
Definition: compat.h:1934
#define verify_str2
Definition: CComBSTR.cpp:14
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:241
const char * LPCSTR
Definition: xmlstorage.h:183
BSTR WINAPI DECLSPEC_HOTPATCH SysAllocStringByteLen(LPCSTR str, UINT len)
Definition: oleaut.c:431
LONG HRESULT
Definition: typedefs.h:77
#define ok_ptr(expression, result)
Definition: test.h:773
static const WCHAR L[]
Definition: oid.c:1250
#define S_OK
Definition: intsafe.h:59
#define E_POINTER
Definition: winerror.h:2365
#define odd(x)
Definition: bidi.c:51

Referenced by START_TEST().

◆ test_fromguid()

void test_fromguid ( )

Definition at line 119 of file CComBSTR.cpp.

120 {
121  GUID guid = { 0x12345678, 0x9abc, 0xdef0, { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0} };
122  CComBSTR fromGuid(guid), empty;
123  verify_str(fromGuid, L"{12345678-9ABC-DEF0-1234-56789ABCDEF0}");
125  empty = fromGuid;
126  verify_str(empty, L"{12345678-9ABC-DEF0-1234-56789ABCDEF0}");
127 }
static const WCHAR empty[]
Definition: main.c:49
#define verify_str
Definition: CComBSTR.cpp:13
const GUID * guid
smooth NULL
Definition: ftsmooth.c:416
static const WCHAR L[]
Definition: oid.c:1250

Referenced by START_TEST().

◆ test_loadres()

void test_loadres ( )

Definition at line 129 of file CComBSTR.cpp.

130 {
131  CComBSTR test1, test2, test3;
133 
134  ok(true == test1.LoadString(mod, IDS_TEST1), "Expected LoadString to succeed\n");
135  ok(true == test2.LoadString(mod, IDS_TEST2), "Expected LoadString to succeed\n");
136  ok(false == test3.LoadString(mod, IDS_TEST2 + 1), "Expected LoadString to fail\n");
137 
138  verify_str(test1, L"Test string one.");
139  verify_str(test2, L"I am a happy BSTR");
141 }
void test3(void)
Definition: hivetest.c:423
#define verify_str
Definition: CComBSTR.cpp:13
#define ok(value,...)
smooth NULL
Definition: ftsmooth.c:416
void test1(void)
Definition: hivetest.c:366
static const WCHAR L[]
Definition: oid.c:1250
void test2(void)
Definition: regtest.c:173
#define GetModuleHandle
Definition: winbase.h:3641
#define IDS_TEST1
Definition: resource.h:2
#define IDS_TEST2
Definition: resource.h:3
static int mod
Definition: i386-dis.c:1273

Referenced by START_TEST().

◆ verify_str_imp()

static void verify_str_imp ( const CComBSTR &  comstr,
PCWSTR  expected 
)
static

Definition at line 42 of file CComBSTR.cpp.

43 {
45 }
static void verify_str_imp2(const CComBSTR &comstr, PCWSTR expected, size_t ExpectedLength)
Definition: CComBSTR.cpp:17
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
BOOL expected
Definition: store.c:2063

◆ verify_str_imp2()

static void verify_str_imp2 ( const CComBSTR &  comstr,
PCWSTR  expected,
size_t  ExpectedLength 
)
static

Definition at line 17 of file CComBSTR.cpp.

18 {
19  BSTR str = (BSTR)comstr;
20  if (expected || ExpectedLength)
21  {
22  winetest_ok(str != NULL, "Expected str to be a valid pointer\n");
23  if (str)
24  {
25  if (expected)
26  {
27  winetest_ok(!wcscmp(str, expected), "Expected the string to be '%s', was '%s'\n", wine_dbgstr_w(expected), wine_dbgstr_w(str));
28  }
29  size_t Length = comstr.Length();
30  winetest_ok(Length == ExpectedLength, "Expected Length to be %u, was: %u\n", ExpectedLength, Length);
31  Length = comstr.ByteLength();
32  ExpectedLength *= sizeof(WCHAR);
33  winetest_ok(Length == ExpectedLength, "Expected ByteLength to be %u, was: %u\n", ExpectedLength, Length);
34  }
35  }
36  else
37  {
38  winetest_ok(str == NULL || str[0] == '\0', "Expected str to be empty, was: '%s'\n", wine_dbgstr_w(str));
39  }
40 }
#define wine_dbgstr_w
Definition: kernel32.h:34
OLECHAR * BSTR
Definition: compat.h:1934
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
void __winetest_cdecl winetest_ok(int condition, const char *msg,...)
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
BOOL expected
Definition: store.c:2063

Referenced by verify_str_imp().