Changeset 25014 in vbox
- Timestamp:
- Nov 26, 2009 3:26:36 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/string.h
r25011 r25014 1053 1053 1054 1054 /** 1055 * Compares two version strings stricmp fashion.1055 * Compares two version strings RTStrICmp fashion. 1056 1056 * 1057 1057 * The version string is split up into sections at punctuation, spaces, … … 1060 1060 * in a numeric or case insesntivie fashion depending on what they are. 1061 1061 * 1062 * The following strings are considered to be equal: "1.0.0", "1.0", "1". 1063 * There aren't: "1.0.0r993", "1.0", "1.0r993", "1.0_Beta3" 1064 * 1065 * @returns integer value indicating the relationship between the versions: 1066 * @retval 0, if both versions are equal. 1067 * @retval 1, if pszVer1 is greater. 1068 * @retval 2, if pszVer2 is greater. 1062 * The following strings are considered to be equal: "1.0.0", "1.00.0", "1.0", 1063 * "1". These aren't: "1.0.0r993", "1.0", "1.0r993", "1.0_Beta3", "1.1" 1064 * 1065 * @returns < 0 if the first string less than the second string. 1066 * @returns 0 if the first string identical to the second string. 1067 * @returns > 0 if the first string greater than the second string. 1069 1068 * 1070 1069 * @param pszVer1 First version string to compare. -
trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibHostVersion.cpp
r25005 r25014 133 133 if (RT_SUCCESS(rc) && *pfUpdate) 134 134 { 135 if (RTStrVersionCompare(*ppszHostVersion, *ppszGuestVersion) == 1) /* Is host version greater than guest add version? */135 if (RTStrVersionCompare(*ppszHostVersion, *ppszGuestVersion) > 0) /* Is host version greater than guest add version? */ 136 136 { 137 137 /* Yay, we have an update! */ -
trunk/src/VBox/Runtime/common/string/strversion.cpp
r25005 r25014 111 111 * Do a parallel parse of the strings. 112 112 */ 113 int iRes = 0;114 113 while (*pszVer1 || *pszVer2) 115 114 { … … 127 126 { 128 127 if (uVal1 != uVal2) 129 { 130 iRes = uVal1 > uVal2 ? 1 : 2; 131 break; 132 } 128 return uVal1 < uVal2 ? -1 : 1; 133 129 } 134 130 else if ( !fNumeric1 && fNumeric2 && uVal2 == 0 && cchBlock1 == 0 … … 144 140 iDiff = cchBlock1 < cchBlock2 ? -1 : 1; 145 141 if (iDiff) 146 { 147 iRes = iDiff > 0 ? 1 : 2; 148 break; 149 } 142 return iDiff < 0 ? -1 : 1; 150 143 } 151 144 } 152 return iRes;145 return 0; 153 146 } 154 147 RT_EXPORT_SYMBOL(RTStrVersionCompare); -
trunk/src/VBox/Runtime/testcase/Makefile.kmk
r24633 r25014 96 96 tstStrSimplePattern \ 97 97 tstStrToNum \ 98 tst StrToVer\98 tstRTStrVersion \ 99 99 tstSystemQueryOsInfo \ 100 100 tstRTTemp \ … … 375 375 tstStrToNum_SOURCES = tstStrToNum.cpp 376 376 377 tstStrToVer_SOURCES = tstStrToVer.cpp 377 tstRTStrVersion_TEMPLATE = VBOXR3TSTEXE 378 tstRTStrVersion_SOURCES = tstRTStrVersion.cpp 378 379 379 380 tstSystemQueryOsInfo_SOURCES = tstSystemQueryOsInfo.cpp -
trunk/src/VBox/Runtime/testcase/tstRTStrVersion.cpp
r25010 r25014 29 29 */ 30 30 31 /******************************************************************************* 32 * Header Files * 33 *******************************************************************************/ 34 #include <iprt/string.h> 31 35 32 #include <iprt/initterm.h> 33 #include <iprt/string.h> 36 #include <iprt/test.h> 34 37 #include <iprt/stream.h> 35 38 36 39 37 struct TstU838 {39 const char *pszVer1;40 const char *pszVer2;41 uint8_t Result;42 };43 44 45 #define TEST(Test, Type, Fmt, Fun, iTest) \46 do \47 { \48 Type Result = Fun(Test.pszVer1, Test.pszVer2); \49 if (Result != Test.Result) \50 { \51 RTPrintf("failure: '%s' <-> '%s' -> " Fmt ", expected " Fmt ". (%s/%u)\n", Test.pszVer1, Test.pszVer2, Result, Test.Result, #Fun, iTest); \52 cErrors++; \53 } \54 } while (0)55 56 #define RUN_TESTS(aTests, Type, Fmt, Fun) \57 do \58 { \59 for (unsigned iTest = 0; iTest < RT_ELEMENTS(aTests); iTest++) \60 { \61 TEST(aTests[iTest], Type, Fmt, Fun, iTest); \62 } \63 } while (0)64 65 40 int main() 66 41 { 67 RTR3Init(); 42 RTTEST hTest; 43 int rc = RTTestInitAndCreate("tstRTStrVersion", &hTest); 44 if (rc) 45 return rc; 46 RTTestBanner(hTest); 68 47 69 int cErrors = 0; 70 static const struct TstU8 aTstU8[] = 48 RTTestSub(hTest, "RTStrVersionCompare"); 49 static struct 50 { 51 const char *pszVer1; 52 const char *pszVer2; 53 int iResult; 54 } const aTests[] = 71 55 { 72 56 { "", "", 0 }, … … 75 59 { "12.foo006", "12.6", 1 }, /* "12.foo006" is bigger than "12.6" */ 76 60 { "1", "1", 0 }, 77 { "1", "100", 2},61 { "1", "100", -1}, 78 62 { "100", "1", 1 }, 79 { "3", "4", 2},63 { "3", "4", -1}, 80 64 { "1", "0.1", 1 }, 81 65 { "1", "0.0.0.0.10000", 1 }, 82 66 { "0100", "100", 0 }, 83 67 { "1.0.0", "1", 0 }, 84 { "1.0.0", "100.0.0", 2},85 { "1", "1.0.3.0", 2},68 { "1.0.0", "100.0.0", -1}, 69 { "1", "1.0.3.0", -1}, 86 70 { "1.4.5", "1.2.3", 1 }, 87 { "1.2.3", "1.4.5", 2},88 { "1.2.3", "4.5.6", 2},71 { "1.2.3", "1.4.5", -1}, 72 { "1.2.3", "4.5.6", -1}, 89 73 { "1.0.4", "1.0.3", 1 }, 90 74 { "0.1", "0.0.1", 1 }, 91 { "0.0.1", "0.1.1", 2},75 { "0.0.1", "0.1.1", -1}, 92 76 { "3.1.0", "3.0.14", 1 }, 93 { "2.0.12", "3.0.14", 2},77 { "2.0.12", "3.0.14", -1}, 94 78 { "3.1", "3.0.22", 1 }, 95 { "3.0.14", "3.1.0", 2},79 { "3.0.14", "3.1.0", -1}, 96 80 { "45.63", "04.560.30", 1 }, 97 81 { "45.006", "45.6", 0 }, 98 82 { "23.206", "23.06", 1 }, 99 { "23.2", "23.060", 2},83 { "23.2", "23.060", -1}, 100 84 101 { "VirtualBox-2.0.8-Beta2", "VirtualBox-2.0.8_Beta3-r12345", 2},85 { "VirtualBox-2.0.8-Beta2", "VirtualBox-2.0.8_Beta3-r12345", -1}, 102 86 { "VirtualBox-2.2.4-Beta2", "VirtualBox-2.2.2", 1 }, 103 87 { "VirtualBox-2.2.4-Beta3", "VirtualBox-2.2.2-Beta4", 1 }, 104 { "VirtualBox-3.1.8-Alpha1", "VirtualBox-3.1.8-Alpha1-r61454", 2},105 { "VirtualBox-3.1.0", "VirtualBox-3.1.2_Beta1", 2},106 { "3.1.0_BETA-r12345", "3.1.2", 2},88 { "VirtualBox-3.1.8-Alpha1", "VirtualBox-3.1.8-Alpha1-r61454", -1}, 89 { "VirtualBox-3.1.0", "VirtualBox-3.1.2_Beta1", -1}, 90 { "3.1.0_BETA-r12345", "3.1.2", -1}, 107 91 }; 108 RUN_TESTS(aTstU8, int, "%#d", RTStrVersionCompare); 92 for (unsigned iTest = 0; iTest < RT_ELEMENTS(aTests); iTest++) 93 { 94 int iResult = RTStrVersionCompare(aTests[iTest].pszVer1, aTests[iTest].pszVer2); 95 if (iResult != aTests[iTest].iResult) 96 RTTestFailed(hTest, "#%u: '%s' <-> '%s' -> %d, expected %d", 97 iTest, aTests[iTest].pszVer1, aTests[iTest].pszVer2, iResult, aTests[iTest].iResult); 98 } 109 99 110 100 /* 111 101 * Summary. 112 102 */ 113 if (!cErrors) 114 RTPrintf("tstStrToVer: SUCCESS\n"); 115 else 116 RTPrintf("tstStrToVer: FAILURE - %d errors\n", cErrors); 117 return !!cErrors; 103 return RTTestSummaryAndDestroy(hTest); 118 104 } 105
Note:
See TracChangeset
for help on using the changeset viewer.