VirtualBox

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

Last change on this file since 25014 was 25014, checked in by vboxsync, 15 years ago

RTStrVersionCompare: made it return the same as RTStrICmp (-1,0,1).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/* $Id: tstRTStrVersion.cpp 25014 2009-11-26 15:26:36Z vboxsync $ */
2/** @file
3 * IPRT Testcase - Version String Comparison.
4 */
5
6/*
7 * Copyright (C) 2009 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31/*******************************************************************************
32* Header Files *
33*******************************************************************************/
34#include <iprt/string.h>
35
36#include <iprt/test.h>
37#include <iprt/stream.h>
38
39
40int main()
41{
42 RTTEST hTest;
43 int rc = RTTestInitAndCreate("tstRTStrVersion", &hTest);
44 if (rc)
45 return rc;
46 RTTestBanner(hTest);
47
48 RTTestSub(hTest, "RTStrVersionCompare");
49 static struct
50 {
51 const char *pszVer1;
52 const char *pszVer2;
53 int iResult;
54 } const aTests[] =
55 {
56 { "", "", 0 },
57 { "asdf", "", 1 }, /* "asdf" is bigger than "" */
58 { "asdf234", "1.4.5", 1 },
59 { "12.foo006", "12.6", 1 }, /* "12.foo006" is bigger than "12.6" */
60 { "1", "1", 0 },
61 { "1", "100", -1},
62 { "100", "1", 1 },
63 { "3", "4", -1},
64 { "1", "0.1", 1 },
65 { "1", "0.0.0.0.10000", 1 },
66 { "0100", "100", 0 },
67 { "1.0.0", "1", 0 },
68 { "1.0.0", "100.0.0", -1},
69 { "1", "1.0.3.0", -1},
70 { "1.4.5", "1.2.3", 1 },
71 { "1.2.3", "1.4.5", -1},
72 { "1.2.3", "4.5.6", -1},
73 { "1.0.4", "1.0.3", 1 },
74 { "0.1", "0.0.1", 1 },
75 { "0.0.1", "0.1.1", -1},
76 { "3.1.0", "3.0.14", 1 },
77 { "2.0.12", "3.0.14", -1},
78 { "3.1", "3.0.22", 1 },
79 { "3.0.14", "3.1.0", -1},
80 { "45.63", "04.560.30", 1 },
81 { "45.006", "45.6", 0 },
82 { "23.206", "23.06", 1 },
83 { "23.2", "23.060", -1},
84
85 { "VirtualBox-2.0.8-Beta2", "VirtualBox-2.0.8_Beta3-r12345", -1},
86 { "VirtualBox-2.2.4-Beta2", "VirtualBox-2.2.2", 1 },
87 { "VirtualBox-2.2.4-Beta3", "VirtualBox-2.2.2-Beta4", 1 },
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},
91 };
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 }
99
100 /*
101 * Summary.
102 */
103 return RTTestSummaryAndDestroy(hTest);
104}
105
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