Changeset 21079 in vbox for trunk/src/VBox
- Timestamp:
- Jun 30, 2009 3:59:22 PM (16 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 16 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/ApplianceImpl.cpp
r21077 r21079 26 26 #include <iprt/file.h> 27 27 #include <iprt/s3.h> 28 #include "iprt/xml_cpp.h" 28 29 29 30 #include <VBox/param.h> … … 39 40 40 41 #include "Logging.h" 41 42 #include "VBox/xml.h"43 42 44 43 using namespace std; … … 234 233 // 235 234 //////////////////////////////////////////////////////////////////////////////// 236 237 static Utf8Str stripFilename(const Utf8Str &strFile)238 {239 Utf8Str str2(strFile);240 RTPathStripFilename(str2.mutableRaw());241 return str2;242 }243 235 244 236 static const struct … … 2246 2238 /* The disk image has to be on the same place as the OVF file. So 2247 2239 * strip the filename out of the full file path. */ 2248 Utf8Str strSrcDir = stripFilename(pAppliance->m->strPath); 2240 Utf8Str strSrcDir(pAppliance->m->strPath); 2241 strSrcDir.stripFilename(); 2249 2242 2250 2243 /* Iterate over all given disk images */ … … 3522 3515 const Utf8Str &strTargetFileNameOnly = pDiskEntry->strOvf; 3523 3516 // target path needs to be composed from where the output OVF is 3524 Utf8Str strTargetFilePath = stripFilename(m->strPath); 3517 Utf8Str strTargetFilePath(m->strPath); 3518 strTargetFilePath.stripFilename(); 3525 3519 strTargetFilePath.append("/"); 3526 3520 strTargetFilePath.append(strTargetFileNameOnly); … … 3721 3715 const Utf8Str &strTargetFileNameOnly = (*itH)->strOvf; 3722 3716 /* Target path needs to be composed from where the output OVF is */ 3723 Utf8Str strTargetFilePath = stripFilename(m->strPath); 3717 Utf8Str strTargetFilePath(m->strPath); 3718 strTargetFilePath.stripFilename(); 3724 3719 strTargetFilePath.append("/"); 3725 3720 strTargetFilePath.append(strTargetFileNameOnly); … … 4736 4731 4737 4732 Utf8Str strTargetVmdkName(bstrName); 4738 RTPathStripExt(strTargetVmdkName.mutableRaw());4733 strTargetVmdkName.stripExt(); 4739 4734 strTargetVmdkName.append(".vmdk"); 4740 4735 -
trunk/src/VBox/Main/ConsoleImpl.cpp
r21077 r21079 1073 1073 for (unsigned i = 0; i < 10 && (VERR_BUFFER_OVERFLOW == vrc); ++i) 1074 1074 { 1075 Utf8Buf. alloc(cchBuf + 1024);1075 Utf8Buf.reserve(cchBuf + 1024); 1076 1076 if (Utf8Buf.isNull()) 1077 1077 return E_OUTOFMEMORY; … … 1081 1081 vrc = mVMMDev->hgcmHostCall ("VBoxGuestPropSvc", ENUM_PROPS_HOST, 3, 1082 1082 &parm[0]); 1083 Utf8Buf.jolt(); 1083 1084 if (parm[2].type != VBOX_HGCM_SVC_PARM_32BIT) 1084 1085 return setError (E_FAIL, tr ("Internal application error")); … … 1717 1718 { 1718 1719 Utf8Str dir = stateFilePath; 1719 RTPathStripFilename (dir.mutableRaw());1720 if (!RTDirExists 1720 dir.stripFilename(); 1721 if (!RTDirExists(dir)) 1721 1722 { 1722 1723 int vrc = RTDirCreateFullPath (dir, 0777); … … 3865 3866 3866 3867 parm[0].type = VBOX_HGCM_SVC_PARM_PTR; 3867 /* To save doing a const cast, we use the mutableRaw() member. */ 3868 parm[0].u.pointer.addr = Utf8Name.mutableRaw(); 3868 parm[0].u.pointer.addr = (void*)Utf8Name.c_str(); 3869 3869 /* The + 1 is the null terminator */ 3870 3870 parm[0].u.pointer.size = (uint32_t)Utf8Name.length() + 1; … … 3882 3882 if (vrc != VERR_NOT_FOUND) 3883 3883 { 3884 size_t iFlags = strlen(pszBuffer) + 1; 3885 Utf8Str(pszBuffer).cloneTo (aValue); 3884 Utf8Str strBuffer(pszBuffer); 3885 strBuffer.cloneTo(aValue); 3886 3886 3887 *aTimestamp = parm[2].u.uint64; 3887 Utf8Str(pszBuffer + iFlags).cloneTo (aFlags); 3888 3889 size_t iFlags = strBuffer.length() + 1; 3890 Utf8Str(pszBuffer + iFlags).cloneTo(aFlags); 3888 3891 } 3889 3892 else … … 3930 3933 3931 3934 parm[0].type = VBOX_HGCM_SVC_PARM_PTR; 3932 /* To save doing a const cast, we use the mutableRaw() member. */ 3933 parm[0].u.pointer.addr = Utf8Name.mutableRaw(); 3935 parm[0].u.pointer.addr = (void*)Utf8Name.c_str(); 3934 3936 /* The + 1 is the null terminator */ 3935 3937 parm[0].u.pointer.size = (uint32_t)Utf8Name.length() + 1; … … 3938 3940 { 3939 3941 parm[1].type = VBOX_HGCM_SVC_PARM_PTR; 3940 /* To save doing a const cast, we use the mutableRaw() member. */ 3941 parm[1].u.pointer.addr = Utf8Value.mutableRaw(); 3942 parm[1].u.pointer.addr = (void*)Utf8Value.c_str(); 3942 3943 /* The + 1 is the null terminator */ 3943 3944 parm[1].u.pointer.size = (uint32_t)Utf8Value.length() + 1; … … 3947 3948 { 3948 3949 parm[2].type = VBOX_HGCM_SVC_PARM_PTR; 3949 /* To save doing a const cast, we use the mutableRaw() member. */ 3950 parm[2].u.pointer.addr = Utf8Flags.mutableRaw(); 3950 parm[2].u.pointer.addr = (void*)Utf8Flags.c_str(); 3951 3951 /* The + 1 is the null terminator */ 3952 3952 parm[2].u.pointer.size = (uint32_t)Utf8Flags.length() + 1; -
trunk/src/VBox/Main/ConsoleImpl2.cpp
r21077 r21079 1814 1814 { 1815 1815 /* Pull over the properties from the server. */ 1816 SafeArray 1817 SafeArray 1818 SafeArray 1819 SafeArray 1816 SafeArray<BSTR> namesOut; 1817 SafeArray<BSTR> valuesOut; 1818 SafeArray<ULONG64> timestampsOut; 1819 SafeArray<BSTR> flagsOut; 1820 1820 hrc = pConsole->mControl->PullGuestProperties(ComSafeArrayAsOutParam(namesOut), 1821 1821 ComSafeArrayAsOutParam(valuesOut), … … 1829 1829 rc = VERR_INVALID_PARAMETER; 1830 1830 1831 std::vector 1832 std::vector 1833 std::vector 1831 std::vector<Utf8Str> utf8Names, utf8Values, utf8Flags; 1832 std::vector<char *> names, values, flags; 1833 std::vector<ULONG64> timestamps; 1834 1834 for (unsigned i = 0; i < cProps && RT_SUCCESS(rc); ++i) 1835 1835 if ( !VALID_PTR(namesOut[i]) -
trunk/src/VBox/Main/MachineImpl.cpp
r21077 r21079 3450 3450 AssertReturn (!mData->mConfigFileFull.isNull(), VERR_GENERAL_FAILURE); 3451 3451 3452 Utf8Str s ettingsDir = mData->mConfigFileFull;3453 3454 RTPathStripFilename (settingsDir.mutableRaw());3455 char folder 3456 int vrc = RTPathAbsEx (settingsDir, aPath, folder, sizeof(folder));3457 if (RT_SUCCESS 3452 Utf8Str strSettingsDir = mData->mConfigFileFull; 3453 3454 strSettingsDir.stripFilename(); 3455 char folder[RTPATH_MAX]; 3456 int vrc = RTPathAbsEx(strSettingsDir, aPath, folder, sizeof(folder)); 3457 if (RT_SUCCESS(vrc)) 3458 3458 aResult = folder; 3459 3459 … … 3483 3483 Utf8Str settingsDir = mData->mConfigFileFull; 3484 3484 3485 RTPathStripFilename (settingsDir.mutableRaw());3486 if (RTPathStartsWith 3485 settingsDir.stripFilename(); 3486 if (RTPathStartsWith(aPath, settingsDir)) 3487 3487 { 3488 3488 /* when assigning, we create a separate Utf8Str instance because both … … 3491 3491 * first, and since its the same as aPath, an attempt to copy garbage 3492 3492 * will be made. */ 3493 aResult = Utf8Str 3493 aResult = Utf8Str(aPath + settingsDir.length() + 1); 3494 3494 } 3495 3495 } … … 5949 5949 /* first, rename the directory if it matches the machine name */ 5950 5950 configDir = configFile; 5951 RTPathStripFilename (configDir.mutableRaw());5951 configDir.stripFilename(); 5952 5952 newConfigDir = configDir; 5953 if (RTPathFilename 5953 if (RTPathFilename(configDir) == name) 5954 5954 { 5955 RTPathStripFilename (newConfigDir.mutableRaw());5955 newConfigDir.stripFilename(); 5956 5956 newConfigDir = Utf8StrFmt ("%s%c%s", 5957 5957 newConfigDir.raw(), RTPATH_DELIMITER, newName.raw()); … … 6078 6078 6079 6079 /* ensure the settings directory exists */ 6080 Utf8Str path = mData->mConfigFileFull;6081 RTPathStripFilename (path.mutableRaw());6082 if (!RTDirExists 6083 { 6084 vrc = RTDirCreateFullPath 6085 if (RT_FAILURE 6080 Utf8Str path(mData->mConfigFileFull); 6081 path.stripFilename(); 6082 if (!RTDirExists(path)) 6083 { 6084 vrc = RTDirCreateFullPath(path, 0777); 6085 if (RT_FAILURE(vrc)) 6086 6086 { 6087 6087 return setError (E_FAIL, … … 7655 7655 * @note Not thread safe (must be called from this object's lock). 7656 7656 */ 7657 bool Machine::isInOwnDir 7657 bool Machine::isInOwnDir(Utf8Str *aSettingsDir /* = NULL */) 7658 7658 { 7659 7659 Utf8Str settingsDir = mData->mConfigFileFull; 7660 RTPathStripFilename (settingsDir.mutableRaw());7661 char *dirName = RTPathFilename 7660 settingsDir.stripFilename(); 7661 char *dirName = RTPathFilename(settingsDir); 7662 7662 7663 7663 AssertReturn (dirName, false); -
trunk/src/VBox/Main/Makefile.kmk
r21077 r21079 519 519 include 520 520 VBoxSettings_SOURCES = \ 521 xml/xml.cpp \522 521 xml/Settings.cpp 523 522 VBoxSettings_LDFLAGS.darwin = -install_name $(VBOX_DYLD_EXECUTABLE_PATH)/$(notdir $(LIB_SETTINGS)) -Wl,-x # no debug info please. -
trunk/src/VBox/Main/SharedFolderImpl.cpp
r21077 r21079 28 28 29 29 #include <iprt/param.h> 30 #include <iprt/cpputils.h> 30 31 #include <iprt/path.h> 31 #include <iprt/cpputils.h>32 32 33 33 // constructor / destructor … … 199 199 ; 200 200 #else 201 if (hostPathLen == 1 && RTPATH_IS_SEP 201 if (hostPathLen == 1 && RTPATH_IS_SEP(hostPath[0])) 202 202 ; 203 203 #endif 204 204 else 205 RTPathStripTrailingSlash (hostPath.mutableRaw());205 hostPath.stripTrailingSlash(); 206 206 207 207 /* Check whether the path is full (absolute) */ -
trunk/src/VBox/Main/VirtualBoxErrorInfoImpl.cpp
r21077 r21079 156 156 AssertComRC (rc); 157 157 Utf8Str message; 158 rc = aInfo->GetMessage (message.asOutParam()); 158 rc = aInfo->GetMessage(message.asOutParam()); 159 message.jolt(); 159 160 AssertComRC (rc); 160 161 mText = message; -
trunk/src/VBox/Main/VirtualBoxImpl.cpp
r21077 r21079 3870 3870 HRESULT VirtualBox::ensureFilePathExists (const char *aFileName) 3871 3871 { 3872 Utf8Str dir = aFileName;3873 RTPathStripFilename (dir.mutableRaw());3874 if (!RTDirExists (dir))3875 { 3876 int vrc = RTDirCreateFullPath (dir, 0777);3872 Utf8Str strDir(aFileName); 3873 strDir.stripFilename(); 3874 if (!RTDirExists(strDir)) 3875 { 3876 int vrc = RTDirCreateFullPath(strDir, 0777); 3877 3877 if (RT_FAILURE (vrc)) 3878 3878 { 3879 3879 return setError (E_FAIL, 3880 3880 tr ("Could not create the directory '%s' (%Rrc)"), 3881 dir.raw(), vrc);3881 strDir.c_str(), vrc); 3882 3882 } 3883 3883 } -
trunk/src/VBox/Main/glue/ErrorInfo.cpp
r21077 r21079 118 118 119 119 Utf8Str message; 120 rc = ex->GetMessage (message.asOutParam()); 120 rc = ex->GetMessage(message.asOutParam()); 121 message.jolt(); 121 122 gotSomething |= NS_SUCCEEDED (rc); 122 123 if (NS_SUCCEEDED (rc)) -
trunk/src/VBox/Main/glue/VirtualBoxErrorInfo.cpp
r21077 r21079 179 179 AssertComRC (rc); 180 180 Utf8Str message; 181 rc = aInfo->GetMessage (message.asOutParam()); 181 rc = aInfo->GetMessage(message.asOutParam()); 182 message.jolt(); 182 183 AssertComRC (rc); 183 184 mText = message; -
trunk/src/VBox/Main/glue/string.cpp
r21077 r21079 26 26 27 27 #include <iprt/err.h> 28 #include <iprt/path.h> 28 29 29 30 namespace com … … 85 86 86 87 size_t cbCopy = psz - pFirst; 87 ret. alloc(cbCopy + 1);88 memcpy(ret. str, pFirst, cbCopy);89 ret. str[cbCopy] = '\0';88 ret.reserve(cbCopy + 1); 89 memcpy(ret.m_psz, pFirst, cbCopy); 90 ret.m_psz[cbCopy] = '\0'; 90 91 } 91 92 } … … 95 96 } 96 97 98 bool Utf8Str::endsWith(const Utf8Str &that, CaseSensitivity cs /*= CaseSensitive*/) const 99 { 100 size_t l1 = length(); 101 if (l1 == 0) 102 return false; 103 104 size_t l2 = that.length(); 105 if (l1 < l2) 106 return false; 107 108 size_t l = l1 - l2; 109 if (cs == CaseSensitive) 110 return ::RTStrCmp(&m_psz[l], that.m_psz) == 0; 111 else 112 return ::RTStrICmp(&m_psz[l], that.m_psz) == 0; 113 } 114 115 bool Utf8Str::startsWith(const Utf8Str &that, CaseSensitivity cs /*= CaseSensitive*/) const 116 { 117 size_t l1 = length(); 118 size_t l2 = that.length(); 119 if (l1 == 0 || l2 == 0) 120 return false; 121 122 if (l1 < l2) 123 return false; 124 125 if (cs == CaseSensitive) 126 return ::RTStrNCmp(m_psz, that.m_psz, l2) == 0; 127 else 128 return ::RTStrNICmp(m_psz, that.m_psz, l2) == 0; 129 } 130 131 bool Utf8Str::contains(const Utf8Str &that, CaseSensitivity cs /*= CaseSensitive*/) const 132 { 133 if (cs == CaseSensitive) 134 return ::RTStrStr(m_psz, that.m_psz) != NULL; 135 else 136 return ::RTStrIStr(m_psz, that.m_psz) != NULL; 137 } 138 139 Utf8Str& Utf8Str::toLower() 140 { 141 if (!isEmpty()) 142 ::RTStrToLower(m_psz); 143 return *this; 144 } 145 146 Utf8Str& Utf8Str::toUpper() 147 { 148 if (!isEmpty()) 149 ::RTStrToUpper(m_psz); 150 return *this; 151 } 152 153 void Utf8Str::stripTrailingSlash() 154 { 155 RTPathStripTrailingSlash(m_psz); 156 jolt(); 157 } 158 159 void Utf8Str::stripFilename() 160 { 161 RTPathStripFilename(m_psz); 162 jolt(); 163 } 164 165 void Utf8Str::stripExt() 166 { 167 RTPathStripExt(m_psz); 168 jolt(); 169 } 170 97 171 int Utf8Str::toInt(uint64_t &i) const 98 172 { 99 if (! str)173 if (!m_psz) 100 174 return VERR_NO_DIGITS; 101 return RTStrToUInt64Ex( str, NULL, 0, &i);175 return RTStrToUInt64Ex(m_psz, NULL, 0, &i); 102 176 } 103 177 104 178 int Utf8Str::toInt(uint32_t &i) const 105 179 { 106 if (! str)180 if (!m_psz) 107 181 return VERR_NO_DIGITS; 108 return RTStrToUInt32Ex( str, NULL, 0, &i);182 return RTStrToUInt32Ex(m_psz, NULL, 0, &i); 109 183 } 110 184 -
trunk/src/VBox/Main/include/ApplianceImpl.h
r21077 r21079 92 92 const ComObjPtr <VirtualBox, ComWeakRef> mVirtualBox; 93 93 94 struct Data; // o bscure, defined in AppliannceImpl.cpp94 struct Data; // opaque, defined in ApplianceImpl.cpp 95 95 Data *m; 96 96 -
trunk/src/VBox/Main/webservice/vboxweb.cpp
r21077 r21079 603 603 * @return 604 604 */ 605 std::string ConvertComString(const com::Guid &bstr) 606 { 605 std::string ConvertComString(const com::Guid &uuid) 606 { 607 com::Bstr bstr(uuid); 607 608 com::Utf8Str ustr(bstr); 608 609 const char *pcsz; -
trunk/src/VBox/Runtime/Makefile.kmk
r21077 r21079 51 51 LIBRARIES += RuntimeR3 52 52 DLLS += VBoxRT 53 54 # Temporary(?) hack.55 VBOX_WITH_LIBXML2_IN_VBOXRT=56 53 57 54 else # !VBOX_ONLY_ADDITIONS && !VBOX_ONLY_DOCS … … 165 162 # 166 163 RuntimeR3_TEMPLATE = VBOXR3STATIC 164 RuntimeR3_SDKS = VBOX_LIBXML2 167 165 RuntimeR3_SDKS.win = WINPSDK W2K3DDK 168 166 RuntimeR3_DEFS = IN_RT_R3 IN_SUP_R3 LDR_WITH_NATIVE LDR_WITH_ELF32 LDR_WITH_PE RT_WITH_VBOX RT_NO_GIP … … 306 304 r3/test.cpp \ 307 305 r3/testi.cpp \ 308 r3/tcp.cpp 306 r3/tcp.cpp \ 307 r3/xml.cpp 309 308 310 309 #if1of ($(KBUILD_TARGET_ARCH),amd64 x86) … … 787 786 # 788 787 VBoxRT_TEMPLATE = VBOXR3 789 ifdef VBOX_WITH_LIBXML2_IN_VBOXRT790 788 VBoxRT_SDKS = VBOX_OPENSSL VBOX_LIBXML2 VBOX_LIBCURL 791 endif792 789 VBoxRT_SDKS.win = WINPSDK W2K3DDK VBOX_NTDLL 793 790 ifeq ($(KBUILD_TARGET)$(VBOX_WITH_HARDENING),darwin) … … 799 796 VBox/VBoxRTDeps.cpp \ 800 797 $(RuntimeR3_SOURCES) 801 if defined(VBOX_WITH_LIBXML2_IN_VBOXRT)802 798 VBoxRT_SOURCES += \ 803 799 common/misc/s3.cpp 804 endif805 800 VBoxRT_SOURCES.$(KBUILD_TARGET) = $(RuntimeR3_SOURCES.$(KBUILD_TARGET)) 806 801 VBoxRT_SOURCES.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH) = $(RuntimeR3_SOURCES.$(KBUILD_TARGET).$(KBUILD_TARGET_ARCH)) … … 818 813 $(PATH_LIB)/VBox-kStuff$(VBOX_SUFF_LIB) 819 814 endif 820 ifdef VBOX_WITH_LIBXML2_IN_VBOXRT 821 ifndef SDK_VBOX_LIBXML2_LIBS 822 VBoxRT_LIBS += \ 815 ifndef SDK_VBOX_LIBXML2_LIBS 816 VBoxRT_LIBS += \ 823 817 $(PATH_LIB)/VBox-libxml2$(VBOX_SUFF_LIB) 824 825 826 818 endif 819 ifndef SDK_VBOX_OPENSSL_LIBS 820 VBoxRT_LIBS += \ 827 821 $(PATH_LIB)/VBox-libcrypto$(VBOX_SUFF_LIB) 828 endif829 822 endif 830 823 VBoxRT_LIBS.darwin = \ … … 851 844 $(PATH_LIB)/RuntimeR3L4$(VBOX_SUFF_LIB) 852 845 853 ifdef VBOX_WITH_LIBXML2_IN_VBOXRT854 VBox/VBoxRTDeps.cpp_DEFS = VBOX_WITH_LIBXML2_IN_VBOXRT855 endif856 857 846 if1of ($(DLLS), VBoxRT) 858 847 $$(VBoxRT_0_OUTDIR)/VBoxRT.def: \ 859 848 $(PATH_SUB_CURRENT)/r3/win/VBoxRT-$$(if-expr $$(KBUILD_TARGET_ARCH) == amd64,win64,win32).def \ 860 $( if-expr defined(VBOX_WITH_LIBXML2_IN_VBOXRT),$(PATH_SUB_CURRENT)/r3/win/$(if $(VBOX_OSE),VBoxRT-openssl-ose.def,VBoxRT-openssl.def),)849 $(PATH_SUB_CURRENT)/r3/win/$(if $(VBOX_OSE),VBoxRT-openssl-ose.def,VBoxRT-openssl.def) 861 850 $(RM) -f -- $@ 862 851 $(REDIRECT) -wto $@ -- $(CAT_EXT) $^ -
trunk/src/VBox/Runtime/VBox/VBoxRTDeps.cpp
r21077 r21079 36 36 #include <iprt/assert.h> 37 37 #include <iprt/asm.h> 38 #ifdef VBOX_WITH_LIBXML2_IN_VBOXRT 38 39 39 # include <libxml/xmlmodule.h> 40 40 # include <libxml/globals.h> … … 44 44 # include <openssl/x509.h> 45 45 # include <openssl/rsa.h> 46 #endif47 46 48 47 … … 55 54 (PFNRT)SUPR3PageAllocEx, 56 55 (PFNRT)SUPSemEventCreate, 57 #ifdef VBOX_WITH_LIBXML2_IN_VBOXRT58 56 (PFNRT)xmlModuleOpen, 59 57 (PFNRT)MD5_Init, … … 65 63 (PFNRT)i2d_X509, 66 64 (PFNRT)RSA_generate_key, 67 #endif68 65 (PFNRT)RTAssertShouldPanic, 69 66 (PFNRT)ASMAtomicReadU64, -
trunk/src/VBox/Runtime/r3/xml.cpp
r21077 r21079 19 19 */ 20 20 21 #include "Logging.h"22 23 21 #include <iprt/cdefs.h> 24 22 #include <iprt/err.h> 25 23 #include <iprt/file.h> 26 24 #include <iprt/lock.h> 27 #include <iprt/ string.h>25 #include <iprt/xml_cpp.h> 28 26 29 27 #include <libxml/tree.h> … … 36 34 #include <libxml/xmlschemas.h> 37 35 38 #include <list>39 36 #include <map> 40 37 #include <boost/shared_ptr.hpp> 41 42 #include "VBox/xml.h"43 38 44 39 //////////////////////////////////////////////////////////////////////////////// … … 991 986 { 992 987 m->copyFrom(x.m); 993 } ;988 } 994 989 995 990 Document& Document::operator=(const Document &x) … … 998 993 m->copyFrom(x.m); 999 994 return *this; 1000 } ;995 } 1001 996 1002 997 Document::~Document() -
trunk/src/VBox/Runtime/testcase/tstUtf8.cpp
r21077 r21079 42 42 #include <iprt/err.h> 43 43 #include <iprt/test.h> 44 #include <iprt/ministring_cpp.h> 44 45 45 46 #include <stdlib.h> /** @todo use our random. */ … … 926 927 927 928 929 void testMinistring(RTTEST hTest) 930 { 931 RTTestSub(hTest, "class ministring"); 932 933 #define CHECK(expr) \ 934 do { \ 935 if (!(expr)) \ 936 RTTestFailed(hTest, "%d: FAILED %s", __LINE__, #expr); \ 937 } while (0) 938 939 #define CHECK_DUMP(expr, value) \ 940 do { \ 941 if (!(expr)) \ 942 RTTestFailed(hTest, "%d: FAILED %s, got \"%s\"", __LINE__, #expr, value); \ 943 } while (0) 944 945 #define CHECK_DUMP_I(expr) \ 946 do { \ 947 if (!(expr)) \ 948 RTTestFailed(hTest, "%d: FAILED %s, got \"%d\"", __LINE__, #expr, expr); \ 949 } while (0) 950 951 ministring empty; 952 CHECK( (empty.length() == 0) ); 953 CHECK( (empty.capacity() == 0) ); 954 955 ministring sixbytes("12345"); 956 CHECK( (sixbytes.length() == 5) ); 957 CHECK( (sixbytes.capacity() == 6) ); 958 959 sixbytes.append("678"); 960 CHECK( (sixbytes.length() == 8) ); 961 CHECK( (sixbytes.capacity() == 9) ); 962 963 char *psz = sixbytes.mutableRaw(); 964 // 12345678 965 // ^ 966 // 0123456 967 psz[6] = '\0'; 968 sixbytes.jolt(); 969 CHECK( (sixbytes.length() == 6) ); 970 CHECK( (sixbytes.capacity() == 7) ); 971 972 ministring morebytes("tobereplaced"); 973 morebytes = "newstring "; 974 morebytes.append(sixbytes); 975 976 CHECK_DUMP( (morebytes == "newstring 123456"), morebytes.c_str() ); 977 978 ministring third(morebytes); 979 third.reserve(100 * 1024); // 100 KB 980 CHECK_DUMP( (third == "newstring 123456"), morebytes.c_str() ); 981 CHECK( (third.capacity() == 100 * 1024) ); 982 CHECK( (third.length() == morebytes.length()) ); // must not have changed 983 984 ministring copy1(morebytes); 985 ministring copy2 = morebytes; 986 CHECK( (copy1 == copy2) ); 987 988 copy1 = NULL; 989 CHECK( (copy1.isNull()) ); 990 991 copy1 = ""; 992 CHECK( (copy1.isEmpty()) ); 993 994 CHECK( (ministring("abc") < ministring("def")) ); 995 CHECK( (ministring("abc") != ministring("def")) ); 996 CHECK_DUMP_I( (ministring("def") > ministring("abc")) ); 997 998 copy2.setNull(); 999 for (int i = 0; 1000 i < 100; 1001 ++i) 1002 { 1003 copy2.reserve(50); // should be ignored after 50 loops 1004 copy2.append("1"); 1005 } 1006 CHECK( (copy2.length() == 100) ); 1007 1008 #undef CHECK 1009 } 1010 928 1011 int main() 929 1012 { … … 946 1029 TstRTStrXCmp(hTest); 947 1030 testStrStr(hTest); 1031 1032 testMinistring(hTest); 1033 948 1034 Benchmarks(hTest); 949 1035
Note:
See TracChangeset
for help on using the changeset viewer.