llvm-project
89 строк · 2.0 Кб
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03
10// ADDITIONAL_COMPILE_FLAGS: -Wno-unused-function
11
12#include <cassert>
13#include <utility>
14
15#include "../src/demangle/ItaniumDemangle.h"
16
17void testPODSmallVector() {
18{ // {push/pop}_back
19itanium_demangle::PODSmallVector<int, 1> PSV;
20PSV.push_back(0);
21PSV.push_back(1);
22PSV.push_back(2);
23PSV.push_back(3);
24for (int i = 0; i < 4; ++i)
25assert(PSV[i] == i);
26PSV.pop_back();
27for (int i = 0; i < 3; ++i)
28assert(PSV[i] == i);
29PSV.pop_back();
30PSV.pop_back();
31assert(!PSV.empty() && PSV.size() == 1);
32PSV.pop_back();
33assert(PSV.empty() && PSV.size() == 0);
34}
35
36{
37itanium_demangle::PODSmallVector<int, 1> PSV1;
38PSV1.push_back(1);
39PSV1.push_back(2);
40PSV1.push_back(3);
41
42itanium_demangle::PODSmallVector<int, 1> PSV2;
43std::swap(PSV1, PSV2);
44assert(PSV1.size() == 0);
45assert(PSV2.size() == 3);
46int i = 1;
47for (int x : PSV2) {
48assert(x == i);
49++i;
50}
51assert(i == 4);
52std::swap(PSV1, PSV2);
53assert(PSV1.size() == 3);
54assert(PSV2.size() == 0);
55i = 1;
56for (int x : PSV1) {
57assert(x == i);
58++i;
59}
60assert(i == 4);
61}
62
63{
64itanium_demangle::PODSmallVector<int, 10> PSV1;
65itanium_demangle::PODSmallVector<int, 10> PSV2;
66PSV1.push_back(0);
67PSV1.push_back(1);
68PSV1.push_back(2);
69assert(PSV1.size() == 3);
70assert(PSV2.size() == 0);
71std::swap(PSV1, PSV2);
72assert(PSV1.size() == 0);
73assert(PSV2.size() == 3);
74int i = 0;
75for (int x : PSV2) {
76assert(x == i);
77++i;
78}
79for (int x : PSV1) {
80assert(false);
81(void)x;
82}
83}
84}
85
86int main(int, char**) {
87testPODSmallVector();
88return 0;
89}
90