1 | /* $Id: tstIprtMiniList.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT Testcase - RTCList.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2022-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/test.h>
|
---|
42 | #include <iprt/cpp/list.h>
|
---|
43 | #include <iprt/cpp/ministring.h>
|
---|
44 |
|
---|
45 |
|
---|
46 | int main()
|
---|
47 | {
|
---|
48 | RTTEST hTest;
|
---|
49 | RTEXITCODE rcExit = RTTestInitAndCreate("tstIprtMiniList", &hTest);
|
---|
50 | if (rcExit == RTEXITCODE_SUCCESS)
|
---|
51 | {
|
---|
52 | RTTestBanner(hTest);
|
---|
53 |
|
---|
54 | /*
|
---|
55 | * Test == and != operators.
|
---|
56 | */
|
---|
57 | RTCList<uint8_t> u8ListEmpty1(1);
|
---|
58 | RTCList<uint8_t> u8ListEmpty2(2);
|
---|
59 | RTTESTI_CHECK(u8ListEmpty1 == u8ListEmpty2);
|
---|
60 |
|
---|
61 | RTCList<uint8_t *> u8PtrListEmpty1;
|
---|
62 | RTCList<uint8_t *> u8PtrListEmpty2(42);
|
---|
63 | RTTESTI_CHECK(u8PtrListEmpty1 == u8PtrListEmpty2);
|
---|
64 |
|
---|
65 | uint8_t a, b;
|
---|
66 | RTCList<uint8_t *> u8PtrListA; u8PtrListA.append(&a);
|
---|
67 | RTCList<uint8_t *> u8PtrListB; u8PtrListB.append(&b);
|
---|
68 | RTTESTI_CHECK(u8PtrListA == u8PtrListA);
|
---|
69 | RTTESTI_CHECK(u8PtrListA != u8PtrListB);
|
---|
70 |
|
---|
71 | RTCList<RTCString> spList1 = RTCString("##abcdef##abcdef####abcdef##").split("##", RTCString::RemoveEmptyParts);
|
---|
72 | RTCList<RTCString> spList2 = RTCString("##abcdef##abcdef####abcdef##").split("##", RTCString::RemoveEmptyParts);
|
---|
73 | RTCList<RTCString> spList3 = RTCString("").split("##", RTCString::RemoveEmptyParts);
|
---|
74 | RTCList<RTCString> spList4 = RTCString("##abcdef##qwer####abcdef##").split("##", RTCString::RemoveEmptyParts);
|
---|
75 |
|
---|
76 | RTTESTI_CHECK(spList1 == spList1);
|
---|
77 | RTTESTI_CHECK(spList1 == spList2);
|
---|
78 | RTTESTI_CHECK(spList1 != spList3);
|
---|
79 | RTTESTI_CHECK(spList1 != spList4);
|
---|
80 |
|
---|
81 | /*
|
---|
82 | * Test filtering.
|
---|
83 | */
|
---|
84 | /* Basics. */
|
---|
85 | RTCList<RTCString> spListFiltered;
|
---|
86 | spListFiltered.filter(RTCString("").split(",")); /* Empty filter. */
|
---|
87 | /* String list. */
|
---|
88 | spListFiltered = RTCString("filter-out1,filter-out2,foo").split(",");
|
---|
89 | spListFiltered.filter(RTCString("filter-out1,filter-out2").split(","));
|
---|
90 | RTTESTI_CHECK(spListFiltered == RTCString("foo").split(","));
|
---|
91 | /* Repeat. */
|
---|
92 | spListFiltered.filter(RTCString("filter-out1,filter-out2").split(","));
|
---|
93 | RTTESTI_CHECK(spListFiltered == RTCString("foo").split(","));
|
---|
94 | RTTESTI_CHECK(spListFiltered != RTCString("bar").split(","));
|
---|
95 |
|
---|
96 | rcExit = RTTestSummaryAndDestroy(hTest);
|
---|
97 | }
|
---|
98 | return rcExit;
|
---|
99 | }
|
---|
100 |
|
---|