VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTStrSimplePattern.cpp@ 102335

Last change on this file since 102335 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.5 KB
Line 
1/* $Id: tstRTStrSimplePattern.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * IPRT Testcase - RTStrSimplePattern.
4 */
5
6/*
7 * Copyright (C) 2008-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <iprt/string.h>
42#include <iprt/test.h>
43
44
45int main()
46{
47 RTTEST hTest;
48 RTEXITCODE rcExit = RTTestInitAndCreate("tstRTStrSimplePattern", &hTest);
49 if (rcExit != RTEXITCODE_SUCCESS)
50 return rcExit;
51
52 RTTESTI_CHECK(RTStrSimplePatternMatch("*", ""));
53 RTTESTI_CHECK(RTStrSimplePatternMatch("*", "asdfasdflkjasdlfkj"));
54 RTTESTI_CHECK(RTStrSimplePatternMatch("*?*?*?*?*", "asdfasdflkjasdlfkj"));
55 RTTESTI_CHECK(RTStrSimplePatternMatch("asdf??df", "asdfasdf"));
56 RTTESTI_CHECK(!RTStrSimplePatternMatch("asdf??dq", "asdfasdf"));
57 RTTESTI_CHECK(RTStrSimplePatternMatch("asdf*df", "asdfasdf"));
58 RTTESTI_CHECK(!RTStrSimplePatternMatch("asdf*dq", "asdfasdf"));
59 RTTESTI_CHECK(RTStrSimplePatternMatch("a*", "asdfasdf"));
60 RTTESTI_CHECK(RTStrSimplePatternMatch("a*f", "asdfasdf"));
61 RTTESTI_CHECK(!RTStrSimplePatternMatch("a*q", "asdfasdf"));
62 RTTESTI_CHECK(!RTStrSimplePatternMatch("a*q?", "asdfasdf"));
63 RTTESTI_CHECK(RTStrSimplePatternMatch("?*df", "asdfasdf"));
64
65 RTTESTI_CHECK(RTStrSimplePatternNMatch("*", 1, "", 0));
66 RTTESTI_CHECK(RTStrSimplePatternNMatch("*", ~(size_t)0, "", 0));
67 RTTESTI_CHECK(RTStrSimplePatternNMatch("*", ~(size_t)0, "", ~(size_t)0));
68 RTTESTI_CHECK(RTStrSimplePatternNMatch("*", 1, "asdfasdflkjasdlfkj", ~(size_t)0));
69 RTTESTI_CHECK(RTStrSimplePatternNMatch("*", ~(size_t)0, "asdfasdflkjasdlfkj", ~(size_t)0));
70 RTTESTI_CHECK(RTStrSimplePatternNMatch("*", 1, "asdfasdflkjasdlfkj", 3));
71 RTTESTI_CHECK(RTStrSimplePatternNMatch("*", 2, "asdfasdflkjasdlfkj", 10));
72 RTTESTI_CHECK(RTStrSimplePatternNMatch("*", 15, "asdfasdflkjasdlfkj", 10));
73 RTTESTI_CHECK(RTStrSimplePatternNMatch("*?*?*?*?*", 1, "asdfasdflkjasdlfkj", 128));
74 RTTESTI_CHECK(RTStrSimplePatternNMatch("*?*?*?*?*", 5, "asdfasdflkjasdlfkj", 0));
75 RTTESTI_CHECK(RTStrSimplePatternNMatch("*?*?*?*?*", 5, "asdfasdflkjasdlfkj", ~(size_t)0));
76 RTTESTI_CHECK(RTStrSimplePatternNMatch("*?*?*?*?*", ~(size_t)0, "asdfasdflkjasdlfkj", ~(size_t)0));
77 RTTESTI_CHECK(RTStrSimplePatternNMatch("asdf??df", 8, "asdfasdf", 8));
78 RTTESTI_CHECK(RTStrSimplePatternNMatch("asdf??df", ~(size_t)0, "asdfasdf", 8));
79 RTTESTI_CHECK(RTStrSimplePatternNMatch("asdf??df", ~(size_t)0, "asdfasdf", ~(size_t)0));
80 RTTESTI_CHECK(RTStrSimplePatternNMatch("asdf??df", 7, "asdfasdf", 7));
81 RTTESTI_CHECK(!RTStrSimplePatternNMatch("asdf??df", 7, "asdfasdf", 8));
82 RTTESTI_CHECK(!RTStrSimplePatternNMatch("asdf??dq", 8, "asdfasdf", 8));
83 RTTESTI_CHECK(RTStrSimplePatternNMatch("asdf??dq", 7, "asdfasdf", 7));
84 RTTESTI_CHECK(RTStrSimplePatternNMatch("asdf*df", 8, "asdfasdf", 8));
85 RTTESTI_CHECK(!RTStrSimplePatternNMatch("asdf*dq", 8, "asdfasdf", 8));
86 RTTESTI_CHECK(RTStrSimplePatternNMatch("a*", 10, "asdfasdf", 8));
87 RTTESTI_CHECK(RTStrSimplePatternNMatch("a*f", 3, "asdfasdf", ~(size_t)0));
88 RTTESTI_CHECK(!RTStrSimplePatternNMatch("a*q", 3, "asdfasdf", ~(size_t)0));
89 RTTESTI_CHECK(!RTStrSimplePatternNMatch("a*q?", 4, "asdfasdf", 9));
90 RTTESTI_CHECK(RTStrSimplePatternNMatch("?*df", 4, "asdfasdf", 8));
91
92 size_t offPattern;
93 RTTESTI_CHECK(RTStrSimplePatternMultiMatch("asdq|a*f|a??t", ~(size_t)0, "asdf", 4, NULL));
94 RTTESTI_CHECK(RTStrSimplePatternMultiMatch("asdq|a*f|a??t", ~(size_t)0, "asdf", 4, &offPattern));
95 RTTESTI_CHECK(offPattern == 5);
96 RTTESTI_CHECK(RTStrSimplePatternMultiMatch("asdq|a??t|a??f", ~(size_t)0, "asdf", 4, NULL));
97 RTTESTI_CHECK(RTStrSimplePatternMultiMatch("asdq|a??t|a??f", ~(size_t)0, "asdf", 4, &offPattern));
98 RTTESTI_CHECK(offPattern == 10);
99 RTTESTI_CHECK(RTStrSimplePatternMultiMatch("a*f|a??t|a??f", ~(size_t)0, "asdf", 4, NULL));
100 RTTESTI_CHECK(RTStrSimplePatternMultiMatch("a*f|a??t|a??f", ~(size_t)0, "asdf", 4, &offPattern));
101 RTTESTI_CHECK(offPattern == 0);
102 RTTESTI_CHECK(!RTStrSimplePatternMultiMatch("asdq|a??y|a??x", ~(size_t)0, "asdf", 4, NULL));
103 RTTESTI_CHECK(!RTStrSimplePatternMultiMatch("asdq|a??y|a??x", ~(size_t)0, "asdf", 4, &offPattern));
104 RTTESTI_CHECK(offPattern == ~(size_t)0);
105 RTTESTI_CHECK(RTStrSimplePatternMultiMatch("asdq|a*f|a??t", 9, "asdf", 4, NULL));
106 RTTESTI_CHECK(RTStrSimplePatternMultiMatch("asdq|a*f|a??t", 8, "asdf", 4, NULL));
107 RTTESTI_CHECK(RTStrSimplePatternMultiMatch("asdq|a*f|a??t", 7, "asdf", 4, NULL));
108 RTTESTI_CHECK(!RTStrSimplePatternMultiMatch("asdq|a*f|a??t", 6, "asdf", 4, NULL));
109 RTTESTI_CHECK(!RTStrSimplePatternMultiMatch("asdq|a*f|a??t", 5, "asdf", 4, NULL));
110 RTTESTI_CHECK(!RTStrSimplePatternMultiMatch("asdq|a*f|a??t", 4, "asdf", 4, NULL));
111 RTTESTI_CHECK(!RTStrSimplePatternMultiMatch("asdq|a*f|a??t", 3, "asdf", 4, NULL));
112 RTTESTI_CHECK(RTStrSimplePatternMultiMatch("asdf", 4, "asdf", 4, NULL));
113 RTTESTI_CHECK(RTStrSimplePatternMultiMatch("asdf|", 5, "asdf", 4, NULL));
114
115
116 /*
117 * Summary.
118 */
119 return RTTestSummaryAndDestroy(hTest);
120}
121
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