VirtualBox

source: vbox/trunk/src/VBox/Main/testcase/tstBstr.cpp@ 106061

Last change on this file since 106061 was 106061, checked in by vboxsync, 3 months ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 21.7 KB
Line 
1/* $Id: tstBstr.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * API Glue Testcase - Bstr.
4 */
5
6/*
7 * Copyright (C) 2019-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#include <VBox/com/string.h>
33
34#include <iprt/mem.h>
35#include <iprt/string.h>
36#include <iprt/test.h>
37#include <iprt/uni.h>
38
39
40/*********************************************************************************************************************************
41* Defined Constants And Macros *
42*********************************************************************************************************************************/
43#define CHECK_BSTR(a_Expr, a_bstr, a_szExpected) \
44 do { \
45 a_Expr; \
46 size_t cchExpect = RTStrCalcUtf16Len(a_szExpected); \
47 if ((a_bstr).length() != cchExpect) \
48 RTTestFailed(hTest, "line %u: length() -> %zu, expected %zu (%ls vs %s)", \
49 __LINE__, (a_bstr).length(), cchExpect, (a_bstr).raw(), a_szExpected); \
50 else \
51 { \
52 int iDiff = (a_bstr).compareUtf8(a_szExpected); \
53 if (iDiff) \
54 RTTestFailed(hTest, "line %u: compareUtf8() -> %d: %ls vs %s", \
55 __LINE__, iDiff, (a_bstr).raw(), a_szExpected); \
56 } \
57 } while (0)
58
59
60
61static void testBstrPrintf(RTTEST hTest)
62{
63 RTTestSub(hTest, "Bstr::printf");
64
65 com::Bstr bstr1;
66 CHECK_BSTR(bstr1.printf(""), bstr1, "");
67 CHECK_BSTR(bstr1.printf("1234098694"), bstr1, "1234098694");
68 CHECK_BSTR(bstr1.printf("%u-%u-%u-%s-%u", 42, 999, 42, "asdkfhjasldfk0", 42),
69 bstr1, "42-999-42-asdkfhjasldfk0-42");
70
71 com::Bstr bstr2;
72 CHECK_BSTR(bstr2.printf("%ls-%ls-%ls-%ls-%ls-%ls-%ls-%ls-%ls-%ls::%ls-%ls-%ls-%ls-%ls-%ls-%ls-%ls-%ls-%ls::%ls-%ls-%ls-%ls-%ls-%ls-%ls-%ls-%ls-%ls",
73 bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(),
74 bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(),
75 bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw(), bstr1.raw()),
76 bstr2, "42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42::42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42::42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42");
77 CHECK_BSTR(bstr2.appendPrintf("-9999998888888777776666655554443322110!"),
78 bstr2, "42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42::42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42::42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-9999998888888777776666655554443322110!");
79 CHECK_BSTR(bstr2.appendPrintf("!"),
80 bstr2, "42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42::42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42::42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-42-999-42-asdkfhjasldfk0-42-9999998888888777776666655554443322110!!");
81}
82
83static void testBstrAppend(RTTEST hTest)
84{
85 RTTestSub(hTest, "Bstr::append");
86
87 /* C-string source: */
88 com::Bstr bstr1;
89 CHECK_BSTR(bstr1.append("1234"), bstr1, "1234");
90 CHECK_BSTR(bstr1.append("56"), bstr1, "123456");
91 CHECK_BSTR(bstr1.append("7"), bstr1, "1234567");
92 CHECK_BSTR(bstr1.append("89abcdefghijklmnopqrstuvwxyz"), bstr1, "123456789abcdefghijklmnopqrstuvwxyz");
93 CHECK_BSTR(bstr1.append("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), bstr1, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
94 CHECK_BSTR(bstr1.append("123456789abcdefghijklmnopqrstuvwxyz"), bstr1, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz");
95 CHECK_BSTR(bstr1.append("_"), bstr1, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_");
96 CHECK_BSTR(bstr1.append(""), bstr1, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_");
97
98 com::Bstr bstr2;
99 CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(""), VINF_SUCCESS), bstr2, "");
100 CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow("1234"), VINF_SUCCESS), bstr2, "1234");
101 CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow("56"), VINF_SUCCESS), bstr2, "123456");
102 CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow("7"), VINF_SUCCESS), bstr2, "1234567");
103 CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow("89abcdefghijklmnopqrstuvwxyz"), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyz");
104 CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
105 CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow("123456789abcdefghijklmnopqrstuvwxyz"), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz");
106 CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow("_"), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_");
107 CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(""), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_");
108
109 /* Bstr source: */
110 CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(bstr1), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_");
111 CHECK_BSTR(RTTESTI_CHECK_RC(bstr1.appendNoThrow(bstr2), VINF_SUCCESS), bstr1, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_");
112
113 com::Bstr const bstrWord1("word");
114 CHECK_BSTR(bstr1.setNull(), bstr1, "");
115 CHECK_BSTR(bstr1.append(bstr2, 5, 10), bstr1, "6789abcdef");
116 CHECK_BSTR(bstr1.append(bstr2, 4096, 10), bstr1, "6789abcdef");
117 CHECK_BSTR(bstr1.append(bstrWord1, 1), bstr1, "6789abcdeford");
118 CHECK_BSTR(bstr1.append(bstrWord1, 1,1), bstr1, "6789abcdefordo");
119 CHECK_BSTR(bstr1.append(bstrWord1, 1,2), bstr1, "6789abcdefordoor");
120 CHECK_BSTR(bstr1.append(bstrWord1, 1,3), bstr1, "6789abcdefordoorord");
121 CHECK_BSTR(bstr1.append(bstrWord1, 1,4), bstr1, "6789abcdefordoorordord");
122 CHECK_BSTR(bstr1.append(bstrWord1, 3,1), bstr1, "6789abcdefordoorordordd");
123 CHECK_BSTR(bstr1.append(bstrWord1, 3,2), bstr1, "6789abcdefordoorordorddd");
124 CHECK_BSTR(bstr1.append(bstrWord1, 3), bstr1, "6789abcdefordoorordordddd");
125
126 com::Bstr bstr3;
127 CHECK_BSTR(bstr3.setNull(), bstr3, "");
128 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstr2, 5, 10), VINF_SUCCESS), bstr3, "6789abcdef");
129 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstr2, 4096, 10),VINF_SUCCESS), bstr3, "6789abcdef");
130 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstrWord1, 1), VINF_SUCCESS), bstr3, "6789abcdeford");
131 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstrWord1, 1,1), VINF_SUCCESS), bstr3, "6789abcdefordo");
132 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstrWord1, 1,2), VINF_SUCCESS), bstr3, "6789abcdefordoor");
133 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstrWord1, 1,3), VINF_SUCCESS), bstr3, "6789abcdefordoorord");
134 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstrWord1, 1,4), VINF_SUCCESS), bstr3, "6789abcdefordoorordord");
135 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstrWord1, 3,1), VINF_SUCCESS), bstr3, "6789abcdefordoorordordd");
136 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstrWord1, 3,2), VINF_SUCCESS), bstr3, "6789abcdefordoorordorddd");
137 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstrWord1, 3), VINF_SUCCESS), bstr3, "6789abcdefordoorordordddd");
138 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstrWord1, 3), VINF_SUCCESS), bstr3, "6789abcdefordoorordorddddd");
139 com::Bstr const bstrWord2("-SEP-");
140 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstrWord2, 0), VINF_SUCCESS), bstr3, "6789abcdefordoorordorddddd-SEP-");
141
142 /* CBSTR source: */
143 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(bstr1.raw()), VINF_SUCCESS), bstr3, "6789abcdefordoorordorddddd-SEP-6789abcdefordoorordordddd");
144 CHECK_BSTR(RTTESTI_CHECK_RC(bstr1.appendNoThrow(bstr3.raw()), VINF_SUCCESS), bstr1, "6789abcdefordoorordordddd6789abcdefordoorordorddddd-SEP-6789abcdefordoorordordddd");
145
146 CBSTR const pwsz2 = bstr2.raw();
147 CBSTR const pwszWord1 = bstrWord1.raw();
148 CHECK_BSTR(bstr1.setNull(), bstr1, "");
149 CHECK_BSTR(bstr1.append(pwsz2 + 5, 10), bstr1, "6789abcdef");
150 CHECK_BSTR(bstr1.append(pwszWord1 + 1), bstr1, "6789abcdeford");
151 CHECK_BSTR(bstr1.append(pwszWord1 + 1, 1), bstr1, "6789abcdefordo");
152 CHECK_BSTR(bstr1.append(pwszWord1 + 1, 2), bstr1, "6789abcdefordoor");
153 CHECK_BSTR(bstr1.append(pwszWord1 + 1, 3), bstr1, "6789abcdefordoorord");
154 CHECK_BSTR(bstr1.append(pwszWord1 + 1, 4), bstr1, "6789abcdefordoorordord");
155 CHECK_BSTR(bstr1.append(pwszWord1 + 3, 1), bstr1, "6789abcdefordoorordordd");
156 CHECK_BSTR(bstr1.append(pwszWord1 + 3, 2), bstr1, "6789abcdefordoorordorddd");
157 CHECK_BSTR(bstr1.append(pwszWord1 + 3), bstr1, "6789abcdefordoorordordddd");
158
159 CHECK_BSTR(bstr3.setNull(), bstr3, "");
160 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(pwsz2 + 5, 10), VINF_SUCCESS), bstr3, "6789abcdef");
161 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(pwszWord1 + 1), VINF_SUCCESS), bstr3, "6789abcdeford");
162 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(pwszWord1 + 1, 1), VINF_SUCCESS), bstr3, "6789abcdefordo");
163 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(pwszWord1 + 1, 2), VINF_SUCCESS), bstr3, "6789abcdefordoor");
164 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(pwszWord1 + 1, 3), VINF_SUCCESS), bstr3, "6789abcdefordoorord");
165 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(pwszWord1 + 1, 4), VINF_SUCCESS), bstr3, "6789abcdefordoorordord");
166 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(pwszWord1 + 3, 1), VINF_SUCCESS), bstr3, "6789abcdefordoorordordd");
167 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(pwszWord1 + 3, 2), VINF_SUCCESS), bstr3, "6789abcdefordoorordorddd");
168 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(pwszWord1 + 3), VINF_SUCCESS), bstr3, "6789abcdefordoorordordddd");
169 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(pwszWord1 + 3), VINF_SUCCESS), bstr3, "6789abcdefordoorordorddddd");
170
171 /* RTCString source: */
172 bstr1.setNull();
173 CHECK_BSTR(bstr1.append(RTCString("1234")), bstr1, "1234");
174 CHECK_BSTR(bstr1.append(RTCString("56")), bstr1, "123456");
175 CHECK_BSTR(bstr1.append(RTCString("7")), bstr1, "1234567");
176 CHECK_BSTR(bstr1.append(RTCString("89abcdefghijklmnopqrstuvwxyz")), bstr1, "123456789abcdefghijklmnopqrstuvwxyz");
177 CHECK_BSTR(bstr1.append(RTCString("ABCDEFGHIJKLMNOPQRSTUVWXYZ")), bstr1, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
178 CHECK_BSTR(bstr1.append(RTCString("123456789abcdefghijklmnopqrstuvwxyz")), bstr1, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz");
179 CHECK_BSTR(bstr1.append(RTCString("_")), bstr1, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_");
180 CHECK_BSTR(bstr1.append(RTCString()), bstr1, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_");
181
182 bstr2.setNull();
183 CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(RTCString("")), VINF_SUCCESS), bstr2, "");
184 CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(RTCString("1234")), VINF_SUCCESS), bstr2, "1234");
185 CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(RTCString("56")), VINF_SUCCESS), bstr2, "123456");
186 CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(RTCString("7")), VINF_SUCCESS), bstr2, "1234567");
187 CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(RTCString("89abcdefghijklmnopqrstuvwxyz")), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyz");
188 CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(RTCString("ABCDEFGHIJKLMNOPQRSTUVWXYZ")), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
189 CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(RTCString("123456789abcdefghijklmnopqrstuvwxyz")), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz");
190 CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(RTCString("_")), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_");
191 CHECK_BSTR(RTTESTI_CHECK_RC(bstr2.appendNoThrow(RTCString("")), VINF_SUCCESS), bstr2, "123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz_");
192
193 RTCString const strWord1 = "word";
194 CHECK_BSTR(bstr1.setNull(), bstr1, "");
195 CHECK_BSTR(bstr1.append(com::Utf8Str(bstr2), 5, 10), bstr1, "6789abcdef");
196 CHECK_BSTR(bstr1.append(com::Utf8Str(bstr2), 4096, 10), bstr1, "6789abcdef");
197 CHECK_BSTR(bstr1.append(strWord1, 1), bstr1, "6789abcdeford");
198 CHECK_BSTR(bstr1.append(strWord1, 1,1), bstr1, "6789abcdefordo");
199 CHECK_BSTR(bstr1.append(strWord1, 1,2), bstr1, "6789abcdefordoor");
200 CHECK_BSTR(bstr1.append(strWord1, 1,3), bstr1, "6789abcdefordoorord");
201 CHECK_BSTR(bstr1.append(strWord1, 1,4), bstr1, "6789abcdefordoorordord");
202 CHECK_BSTR(bstr1.append(strWord1, 3,1), bstr1, "6789abcdefordoorordordd");
203 CHECK_BSTR(bstr1.append(strWord1, 3,2), bstr1, "6789abcdefordoorordorddd");
204 CHECK_BSTR(bstr1.append(strWord1, 3), bstr1, "6789abcdefordoorordordddd");
205
206 CHECK_BSTR(bstr3.setNull(), bstr3, "");
207 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(com::Utf8Str(bstr2), 5, 10), VINF_SUCCESS), bstr3, "6789abcdef");
208 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(com::Utf8Str(bstr2), 4096, 10),VINF_SUCCESS), bstr3, "6789abcdef");
209 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(strWord1, 1), VINF_SUCCESS), bstr3, "6789abcdeford");
210 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(strWord1, 1,1), VINF_SUCCESS), bstr3, "6789abcdefordo");
211 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(strWord1, 1,2), VINF_SUCCESS), bstr3, "6789abcdefordoor");
212 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(strWord1, 1,3), VINF_SUCCESS), bstr3, "6789abcdefordoorord");
213 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(strWord1, 1,4), VINF_SUCCESS), bstr3, "6789abcdefordoorordord");
214 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(strWord1, 3,1), VINF_SUCCESS), bstr3, "6789abcdefordoorordordd");
215 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(strWord1, 3,2), VINF_SUCCESS), bstr3, "6789abcdefordoorordorddd");
216 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(strWord1, 3), VINF_SUCCESS), bstr3, "6789abcdefordoorordordddd");
217 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow(strWord1, 3), VINF_SUCCESS), bstr3, "6789abcdefordoorordorddddd");
218
219 /* char: */
220 CHECK_BSTR(bstr1.setNull(), bstr1, "");
221 CHECK_BSTR(bstr1.append('-'), bstr1, "-");
222 CHECK_BSTR(bstr1.append('a'), bstr1, "-a");
223 CHECK_BSTR(bstr1.append('b'), bstr1, "-ab");
224 CHECK_BSTR(bstr1.append('Z'), bstr1, "-abZ");
225 CHECK_BSTR(bstr1.append('-'), bstr1, "-abZ-");
226
227 CHECK_BSTR(bstr3.setNull(), bstr3, "");
228 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow('-'), VINF_SUCCESS), bstr3, "-");
229 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow('a'), VINF_SUCCESS), bstr3, "-a");
230 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow('b'), VINF_SUCCESS), bstr3, "-ab");
231 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow('Z'), VINF_SUCCESS), bstr3, "-abZ");
232 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendNoThrow('-'), VINF_SUCCESS), bstr3, "-abZ-");
233
234 /* unicode codepoint: */
235 CHECK_BSTR(bstr1.setNull(), bstr1, "");
236 CHECK_BSTR(bstr1.appendCodePoint('-'), bstr1, "-");
237 CHECK_BSTR(bstr1.appendCodePoint('a'), bstr1, "-a");
238 CHECK_BSTR(bstr1.appendCodePoint('b'), bstr1, "-ab");
239 CHECK_BSTR(bstr1.appendCodePoint('Z'), bstr1, "-abZ");
240 CHECK_BSTR(bstr1.appendCodePoint('-'), bstr1, "-abZ-");
241 CHECK_BSTR(bstr1.appendCodePoint(0x39f), bstr1, "-abZ-\xce\x9f");
242 CHECK_BSTR(bstr1.appendCodePoint(0x1f50), bstr1, "-abZ-\xce\x9f\xe1\xbd\x90");
243 CHECK_BSTR(bstr1.appendCodePoint(0x3c7), bstr1, "-abZ-\xce\x9f\xe1\xbd\x90\xcf\x87");
244 CHECK_BSTR(bstr1.appendCodePoint(0x1f76), bstr1, "-abZ-\xce\x9f\xe1\xbd\x90\xcf\x87\xe1\xbd\xb6");
245
246 CHECK_BSTR(bstr3.setNull(), bstr3, "");
247 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendCodePointNoThrow('-'), VINF_SUCCESS), bstr3, "-");
248 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendCodePointNoThrow('a'), VINF_SUCCESS), bstr3, "-a");
249 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendCodePointNoThrow('b'), VINF_SUCCESS), bstr3, "-ab");
250 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendCodePointNoThrow('Z'), VINF_SUCCESS), bstr3, "-abZ");
251 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendCodePointNoThrow('-'), VINF_SUCCESS), bstr3, "-abZ-");
252 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendCodePointNoThrow(0x39f), VINF_SUCCESS), bstr3, "-abZ-\xce\x9f");
253 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendCodePointNoThrow(0x1f50), VINF_SUCCESS), bstr3, "-abZ-\xce\x9f\xe1\xbd\x90");
254 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendCodePointNoThrow(0x3c7), VINF_SUCCESS), bstr3, "-abZ-\xce\x9f\xe1\xbd\x90\xcf\x87");
255 CHECK_BSTR(RTTESTI_CHECK_RC(bstr3.appendCodePointNoThrow(0x1f76), VINF_SUCCESS), bstr3, "-abZ-\xce\x9f\xe1\xbd\x90\xcf\x87\xe1\xbd\xb6");
256}
257
258
259static void testBstrErase(RTTEST hTest)
260{
261 RTTestSub(hTest, "Bstr::erase");
262
263 com::Bstr bstr1;
264 CHECK_BSTR(bstr1.erase(), bstr1, "");
265 CHECK_BSTR(bstr1.erase(99), bstr1, "");
266 CHECK_BSTR(bstr1.erase(99,999), bstr1, "");
267
268 CHECK_BSTR(bstr1 = "asdlfjhasldfjhaldfhjalhjsdf", bstr1, "asdlfjhasldfjhaldfhjalhjsdf");
269 CHECK_BSTR(bstr1.erase(8, 9), bstr1, "asdlfjhafhjalhjsdf");
270 CHECK_BSTR(bstr1.erase(17, 20), bstr1, "asdlfjhafhjalhjsd");
271 CHECK_BSTR(bstr1.erase(16, 1), bstr1, "asdlfjhafhjalhjs");
272 CHECK_BSTR(bstr1.erase(15, 0), bstr1, "asdlfjhafhjalhjs");
273 CHECK_BSTR(bstr1.erase(13, 3), bstr1, "asdlfjhafhjal");
274 CHECK_BSTR(bstr1.erase(3, 3), bstr1, "asdhafhjal");
275 CHECK_BSTR(bstr1.erase(), bstr1, "");
276}
277
278
279int main()
280{
281 RTTEST hTest;
282 RTEXITCODE rcExit = RTTestInitAndCreate("tstBstr", &hTest);
283 if (rcExit == RTEXITCODE_SUCCESS)
284 {
285 RTTestBanner(hTest);
286
287 testBstrPrintf(hTest);
288 testBstrAppend(hTest);
289 testBstrErase(hTest);
290
291 rcExit = RTTestSummaryAndDestroy(hTest);
292 }
293 return rcExit;
294}
295
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette