tstRTStrVersion.cpp revision c72f00ff9f31a65845a8722126d37708b61bb6ae
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync/* $Id$ */
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync/** @file
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * IPRT Testcase - Version String Comparison.
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync */
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync/*
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * Copyright (C) 2009 Sun Microsystems, Inc.
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync *
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * available from http://www.virtualbox.org. This file is free software;
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync *
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * The contents of this file may alternatively be used under the terms
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * of the Common Development and Distribution License Version 1.0
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * VirtualBox OSE distribution, in which case the provisions of the
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * CDDL are applicable instead of those of the GPL.
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync *
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * You may elect to license modified versions of this file under the
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * terms and conditions of either the GPL or the CDDL or both.
f84cd77241a1c4b9106a92280611c659243e10d1vboxsync *
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync * additional information or have any questions.
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync */
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync/*******************************************************************************
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync* Header Files *
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync*******************************************************************************/
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync#include <iprt/string.h>
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync
134a71c1528b56afe4db843ab63ec5a5b849535bvboxsync#include <iprt/test.h>
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync#include <iprt/stream.h>
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync
134a71c1528b56afe4db843ab63ec5a5b849535bvboxsyncint main()
134a71c1528b56afe4db843ab63ec5a5b849535bvboxsync{
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync RTTEST hTest;
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync int rc = RTTestInitAndCreate("tstRTStrVersion", &hTest);
134a71c1528b56afe4db843ab63ec5a5b849535bvboxsync if (rc)
134a71c1528b56afe4db843ab63ec5a5b849535bvboxsync return rc;
289060a0c3cb1d509f2cb01fca060796212376f6vboxsync RTTestBanner(hTest);
289060a0c3cb1d509f2cb01fca060796212376f6vboxsync
289060a0c3cb1d509f2cb01fca060796212376f6vboxsync RTTestSub(hTest, "RTStrVersionCompare");
289060a0c3cb1d509f2cb01fca060796212376f6vboxsync static struct
611910c4ba57eb6db5c0d508ca7b923efd654aecvboxsync {
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync const char *pszVer1;
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync const char *pszVer2;
6420f75ffc86ab6494eb5e95418f0c95e71e8068vboxsync int iResult;
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync } const aTests[] =
6420f75ffc86ab6494eb5e95418f0c95e71e8068vboxsync {
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync { "", "", 0 },
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync { "asdf", "", 1 },
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync { "asdf234", "1.4.5", 1 },
6420f75ffc86ab6494eb5e95418f0c95e71e8068vboxsync { "12.foo006", "12.6", 1 },
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync { "1", "1", 0 },
faf968cea88f2ab4bcc3325b17bc8b095a8e3642vboxsync { "1", "100", -1},
6420f75ffc86ab6494eb5e95418f0c95e71e8068vboxsync { "100", "1", 1 },
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync { "3", "4", -1},
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync { "1", "0.1", 1 },
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync { "1", "0.0.0.0.10000", 1 },
faf968cea88f2ab4bcc3325b17bc8b095a8e3642vboxsync { "0100", "100", 0 },
3609dfc9f2733f4dc836c6a6bb3745398f280fcevboxsync { "1.0.0", "1", 0 },
faf968cea88f2ab4bcc3325b17bc8b095a8e3642vboxsync { "1.0.0", "100.0.0", -1},
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync { "1", "1.0.3.0", -1},
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync { "1.4.5", "1.2.3", 1 },
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync { "1.2.3", "1.4.5", -1},
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync { "1.2.3", "4.5.6", -1},
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync { "1.0.4", "1.0.3", 1 },
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync { "0.1", "0.0.1", 1 },
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync { "0.0.1", "0.1.1", -1},
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync { "3.1.0", "3.0.14", 1 },
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync { "2.0.12", "3.0.14", -1},
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync { "3.1", "3.0.22", 1 },
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync { "3.0.14", "3.1.0", -1},
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync { "45.63", "04.560.30", 1 },
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync { "45.006", "45.6", 0 },
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync { "23.206", "23.06", 1 },
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync { "23.2", "23.060", -1},
f94f82d66536c7332c347dd9a3a9f0f8c79247f4vboxsync
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync { "VirtualBox-2.0.8-Beta2", "VirtualBox-2.0.8_Beta3-r12345", -1 },
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync { "VirtualBox-2.2.4-Beta2", "VirtualBox-2.2.2", 1 },
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync { "VirtualBox-2.2.4-Beta3", "VirtualBox-2.2.2-Beta4", 1 },
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync { "VirtualBox-3.1.8-Alpha1", "VirtualBox-3.1.8-Alpha1-r61454", -1 },
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync { "VirtualBox-3.1.0", "VirtualBox-3.1.2_Beta1", -1 },
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync { "3.1.0_BETA-r12345", "3.1.2", -1 },
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync { "3.1.0_BETA-r12345", "3.1.0", -1 },
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync { "3.1.0_BETA-r12345", "3.1.0", -1 },
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync { "3.1.0_BETA-r12345", "3.1.0r12345", -1 },
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync };
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync for (unsigned iTest = 0; iTest < RT_ELEMENTS(aTests); iTest++)
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync {
436b5c616e019c5e62053657c52d3ab5562ecbbfvboxsync int iResult = RTStrVersionCompare(aTests[iTest].pszVer1, aTests[iTest].pszVer2);
0d4bc23ca3867d6dbedd76d5b1e3725c766adb75vboxsync if (iResult != aTests[iTest].iResult)
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync RTTestFailed(hTest, "#%u: '%s' <-> '%s' -> %d, expected %d",
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync iTest, aTests[iTest].pszVer1, aTests[iTest].pszVer2, iResult, aTests[iTest].iResult);
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync }
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync /*
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync * Summary.
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync */
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync return RTTestSummaryAndDestroy(hTest);
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync}
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync
ff78b877ed7acd25e2d384570a938441455d6a95vboxsync