1 //===----------------------- unittest_demangle.cpp ------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // UNSUPPORTED: c++98, c++03 11 12 #include "../src/cxa_demangle.cpp" 13 14 using namespace __cxxabiv1; 15 16 void testPODSmallVector() { 17 { // {push/pop}_back 18 PODSmallVector<int, 1> PSV; 19 PSV.push_back(0); 20 PSV.push_back(1); 21 PSV.push_back(2); 22 PSV.push_back(3); 23 for (int i = 0; i < 4; ++i) 24 assert(PSV[i] == i); 25 PSV.pop_back(); 26 for (int i = 0; i < 3; ++i) 27 assert(PSV[i] == i); 28 PSV.pop_back(); 29 PSV.pop_back(); 30 assert(!PSV.empty() && PSV.size() == 1); 31 PSV.pop_back(); 32 assert(PSV.empty() && PSV.size() == 0); 33 } 34 35 { 36 PODSmallVector<int, 1> PSV1; 37 PSV1.push_back(1); 38 PSV1.push_back(2); 39 PSV1.push_back(3); 40 41 PODSmallVector<int, 1> PSV2; 42 std::swap(PSV1, PSV2); 43 assert(PSV1.size() == 0); 44 assert(PSV2.size() == 3); 45 int i = 1; 46 for (int x : PSV2) { 47 assert(x == i); 48 ++i; 49 } 50 assert(i == 4); 51 std::swap(PSV1, PSV2); 52 assert(PSV1.size() == 3); 53 assert(PSV2.size() == 0); 54 i = 1; 55 for (int x : PSV1) { 56 assert(x == i); 57 ++i; 58 } 59 assert(i == 4); 60 } 61 62 { 63 PODSmallVector<int, 10> PSV1; 64 PODSmallVector<int, 10> PSV2; 65 PSV1.push_back(0); 66 PSV1.push_back(1); 67 PSV1.push_back(2); 68 assert(PSV1.size() == 3); 69 assert(PSV2.size() == 0); 70 std::swap(PSV1, PSV2); 71 assert(PSV1.size() == 0); 72 assert(PSV2.size() == 3); 73 int i = 0; 74 for (int x : PSV2) { 75 assert(x == i); 76 ++i; 77 } 78 for (int x : PSV1) { 79 assert(false); 80 (void)x; 81 } 82 } 83 } 84 85 int main() { 86 testPODSmallVector(); 87 } 88