VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTStrVersion.cpp@ 53401

Last change on this file since 53401 was 39176, checked in by vboxsync, 13 years ago

tstRTStrVersion.cpp: A few more tests.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.6 KB
Line 
1/* $Id: tstRTStrVersion.cpp 39176 2011-11-02 13:34:06Z vboxsync $ */
2/** @file
3 * IPRT Testcase - Version String Comparison.
4 */
5
6/*
7 * Copyright (C) 2011 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#include <iprt/string.h>
31
32#include <iprt/test.h>
33#include <iprt/stream.h>
34
35
36int main()
37{
38 RTTEST hTest;
39 int rc = RTTestInitAndCreate("tstRTStrVersion", &hTest);
40 if (rc)
41 return rc;
42 RTTestBanner(hTest);
43
44 RTTestSub(hTest, "RTStrVersionCompare");
45 static struct
46 {
47 const char *pszVer1;
48 const char *pszVer2;
49 int iResult;
50 } const aTests[] =
51 {
52 { "", "", 0 },
53 { "asdf", "", 1 },
54 { "asdf234", "1.4.5", 1 },
55 { "12.foo006", "12.6", 1 },
56 { "1", "1", 0 },
57 { "1", "100", -1},
58 { "100", "1", 1 },
59 { "3", "4", -1},
60 { "1", "0.1", 1 },
61 { "1", "0.0.0.0.10000", 1 },
62 { "0100", "100", 0 },
63 { "1.0.0", "1", 0 },
64 { "1.0.0", "100.0.0", -1},
65 { "1", "1.0.3.0", -1},
66 { "1.4.5", "1.2.3", 1 },
67 { "1.2.3", "1.4.5", -1},
68 { "1.2.3", "4.5.6", -1},
69 { "1.0.4", "1.0.3", 1 },
70 { "0.1", "0.0.1", 1 },
71 { "0.0.1", "0.1.1", -1},
72 { "3.1.0", "3.0.14", 1 },
73 { "2.0.12", "3.0.14", -1},
74 { "3.1", "3.0.22", 1 },
75 { "3.0.14", "3.1.0", -1},
76 { "45.63", "04.560.30", 1 },
77 { "45.006", "45.6", 0 },
78 { "23.206", "23.06", 1 },
79 { "23.2", "23.060", -1},
80
81 { "VirtualBox-2.0.8-Beta2", "VirtualBox-2.0.8_Beta3-r12345", -1 },
82 { "VirtualBox-2.2.4-Beta2", "VirtualBox-2.2.2", 1 },
83 { "VirtualBox-2.2.4-Beta3", "VirtualBox-2.2.2-Beta4", 1 },
84 { "VirtualBox-3.1.8-Alpha1", "VirtualBox-3.1.8-Alpha1-r61454", -1 },
85 { "VirtualBox-3.1.0", "VirtualBox-3.1.2_Beta1", -1 },
86 { "3.1.0_BETA-r12345", "3.1.2", -1 },
87 { "3.1.0_BETA1r12345", "3.1.0", -1 },
88 { "3.1.0_BETAr12345", "3.1.0", -1 },
89 { "3.1.0_BETA-r12345", "3.1.0", -1 },
90 { "3.1.0_BETA-r12345", "3.1.0", -1 },
91 { "3.1.0_BETA-r12345", "3.1.0.0", -1 },
92 { "3.1.0_BETA", "3.1.0.0", -1 },
93 { "3.1.0_BETA1", "3.1.0", -1 },
94 { "3.1.0_BETA-r12345", "3.1.0r12345", -1 },
95 { "3.1.0_BETA1-r12345", "3.1.0_BETA-r12345", 0 },
96 { "3.1.0_BETA1-r12345", "3.1.0_BETA1-r12345", 0 },
97 { "3.1.0_BETA2-r12345", "3.1.0_BETA1-r12345", 1 },
98 { "3.1.0_BETA2-r12345", "3.1.0_BETA999-r12345", -1 },
99 { "3.1.0_BETA2", "3.1.0_ABC", -1 }, /* ABC isn't indicating a prerelease, BETA does. */
100 { "3.1.0_BETA", "3.1.0_ATEB", -1 },
101 { "4.0.0_ALPHAr68482", "4.0.0_ALPHAr68483", -1 },
102 { "4.0.0_ALPHA1r68482", "4.0.0_ALPHAr68482", 0 },
103 { "4.0.0_ALPHA-r68482", "4.0.0_ALPHAr68482", 0 },
104 { "4.0.0_ALPHAr68483", "4.0.0_BETAr68783", -1 },
105 { "4.0.0_ALPHAr68483", "4.0.0_BETA1r68783", -1 },
106 { "4.0.0_ALPHAr68483", "4.0.0_BETA2r68783", -1 },
107 { "4.0.0_ALPHAr68483", "4.0.0_BETA2r68784", -1 },
108 { "4.0.6", "4.0.6_Ubuntu", -1 }, /* Without stripped guest OS string (Ubuntu). */
109 { "4.0.6_Windows", "4.0.6", 1 }, /* Without stripped guest OS string (Windows). */
110 { "4.1.6r74567", "4.1.6r74567", 0 },
111 { "4.1.7r74567", "4.1.6r74567", 1 },
112 { "4.1.5r74567", "4.1.6r74567", -1 },
113 { "4.1.6r74567-ENTERPRISE", "4.1.6r74567", 1 } /* The tagged version is "newer". */
114 };
115 for (unsigned iTest = 0; iTest < RT_ELEMENTS(aTests); iTest++)
116 {
117 int iResult = RTStrVersionCompare(aTests[iTest].pszVer1, aTests[iTest].pszVer2);
118 if (iResult != aTests[iTest].iResult)
119 RTTestFailed(hTest, "#%u: '%s' <-> '%s' -> %d, expected %d",
120 iTest, aTests[iTest].pszVer1, aTests[iTest].pszVer2, iResult, aTests[iTest].iResult);
121
122 iResult = -RTStrVersionCompare(aTests[iTest].pszVer2, aTests[iTest].pszVer1);
123 if (iResult != aTests[iTest].iResult)
124 RTTestFailed(hTest, "#%u: '%s' <-> '%s' -> %d, expected %d [inv]",
125 iTest, aTests[iTest].pszVer1, aTests[iTest].pszVer2, iResult, aTests[iTest].iResult);
126 }
127
128 /*
129 * Summary.
130 */
131 return RTTestSummaryAndDestroy(hTest);
132}
133
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