Fix some non-standard parts of our test suite. Reported by STL

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@267131 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2016-04-22 10:33:56 +00:00
parent 59f2aea750
commit 5ccbc48774
22 changed files with 45 additions and 31 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,98 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Not a portable test
// Precondition: __x->__right_ != nullptr
// template <class _NodePtr>
// void
// __tree_left_rotate(_NodePtr __x);
#include <__tree>
#include <cassert>
struct Node
{
Node* __left_;
Node* __right_;
Node* __parent_;
Node() : __left_(), __right_(), __parent_() {}
};
void
test1()
{
Node root;
Node x;
Node y;
root.__left_ = &x;
x.__left_ = 0;
x.__right_ = &y;
x.__parent_ = &root;
y.__left_ = 0;
y.__right_ = 0;
y.__parent_ = &x;
std::__tree_left_rotate(&x);
assert(root.__parent_ == 0);
assert(root.__left_ == &y);
assert(root.__right_ == 0);
assert(y.__parent_ == &root);
assert(y.__left_ == &x);
assert(y.__right_ == 0);
assert(x.__parent_ == &y);
assert(x.__left_ == 0);
assert(x.__right_ == 0);
}
void
test2()
{
Node root;
Node x;
Node y;
Node a;
Node b;
Node c;
root.__left_ = &x;
x.__left_ = &a;
x.__right_ = &y;
x.__parent_ = &root;
y.__left_ = &b;
y.__right_ = &c;
y.__parent_ = &x;
a.__parent_ = &x;
b.__parent_ = &y;
c.__parent_ = &y;
std::__tree_left_rotate(&x);
assert(root.__parent_ == 0);
assert(root.__left_ == &y);
assert(root.__right_ == 0);
assert(y.__parent_ == &root);
assert(y.__left_ == &x);
assert(y.__right_ == &c);
assert(x.__parent_ == &y);
assert(x.__left_ == &a);
assert(x.__right_ == &b);
assert(a.__parent_ == &x);
assert(a.__left_ == 0);
assert(a.__right_ == 0);
assert(b.__parent_ == &x);
assert(b.__left_ == 0);
assert(b.__right_ == 0);
assert(c.__parent_ == &y);
assert(c.__left_ == 0);
assert(c.__right_ == 0);
}
int main()
{
test1();
test2();
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,98 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// Not a portable test
// Precondition: __x->__left_ != nullptr
// template <class _NodePtr>
// void
// __tree_right_rotate(_NodePtr __x);
#include <__tree>
#include <cassert>
struct Node
{
Node* __left_;
Node* __right_;
Node* __parent_;
Node() : __left_(), __right_(), __parent_() {}
};
void
test1()
{
Node root;
Node x;
Node y;
root.__left_ = &x;
x.__left_ = &y;
x.__right_ = 0;
x.__parent_ = &root;
y.__left_ = 0;
y.__right_ = 0;
y.__parent_ = &x;
std::__tree_right_rotate(&x);
assert(root.__parent_ == 0);
assert(root.__left_ == &y);
assert(root.__right_ == 0);
assert(y.__parent_ == &root);
assert(y.__left_ == 0);
assert(y.__right_ == &x);
assert(x.__parent_ == &y);
assert(x.__left_ == 0);
assert(x.__right_ == 0);
}
void
test2()
{
Node root;
Node x;
Node y;
Node a;
Node b;
Node c;
root.__left_ = &x;
x.__left_ = &y;
x.__right_ = &c;
x.__parent_ = &root;
y.__left_ = &a;
y.__right_ = &b;
y.__parent_ = &x;
a.__parent_ = &y;
b.__parent_ = &y;
c.__parent_ = &x;
std::__tree_right_rotate(&x);
assert(root.__parent_ == 0);
assert(root.__left_ == &y);
assert(root.__right_ == 0);
assert(y.__parent_ == &root);
assert(y.__left_ == &a);
assert(y.__right_ == &x);
assert(x.__parent_ == &y);
assert(x.__left_ == &b);
assert(x.__right_ == &c);
assert(a.__parent_ == &y);
assert(a.__left_ == 0);
assert(a.__right_ == 0);
assert(b.__parent_ == &x);
assert(b.__left_ == 0);
assert(b.__right_ == 0);
assert(c.__parent_ == &x);
assert(c.__left_ == 0);
assert(c.__right_ == 0);
}
int main()
{
test1();
test2();
}

View File

@@ -0,0 +1,59 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <list>
// template <class T, class Alloc>
// void swap(list<T,Alloc>& x, list<T,Alloc>& y);
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#endif
#include <list>
#include <cassert>
#include <__debug>
#include "min_allocator.h"
int main()
{
#if _LIBCPP_DEBUG >= 1
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
std::list<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
std::list<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
std::list<int>::iterator i1 = c1.begin();
std::list<int>::iterator i2 = c2.begin();
swap(c1, c2);
c1.erase(i2);
c2.erase(i1);
std::list<int>::iterator j = i1;
c1.erase(i1);
assert(false);
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
std::list<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
std::list<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
std::list<int, min_allocator<int>>::iterator i1 = c1.begin();
std::list<int, min_allocator<int>>::iterator i2 = c2.begin();
swap(c1, c2);
c1.erase(i2);
c2.erase(i1);
std::list<int, min_allocator<int>>::iterator j = i1;
c1.erase(i1);
assert(false);
}
#endif
#endif
}

View File

@@ -0,0 +1,51 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// REQUIRES: long_tests
// Not a portable test
// <__hash_table>
// size_t __next_prime(size_t n);
// If n == 0, return 0, else return the lowest prime greater than or equal to n
#include <__hash_table>
#include <cassert>
bool
is_prime(size_t n)
{
switch (n)
{
case 0:
case 1:
return false;
}
for (size_t i = 2; i*i <= n; ++i)
{
if (n % i == 0)
return false;
}
return true;
}
int main()
{
assert(std::__next_prime(0) == 0);
for (std::size_t n = 1; n <= 100000; ++n)
{
std::size_t p = std::__next_prime(n);
assert(p >= n);
for (std::size_t i = n; i < p; ++i)
assert(!is_prime(i));
assert(is_prime(p));
}
}

View File

@@ -0,0 +1,60 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <unordered_map>
// Increment iterator past end.
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <unordered_map>
#include <string>
#include <cassert>
#include <iterator>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
typedef std::unordered_map<int, std::string> C;
C c;
c.insert(std::make_pair(1, "one"));
C::iterator i = c.begin();
++i;
assert(i == c.end());
++i;
assert(false);
}
#if __cplusplus >= 201103L
{
typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
min_allocator<std::pair<const int, std::string>>> C;
C c;
c.insert(std::make_pair(1, "one"));
C::iterator i = c.begin();
++i;
assert(i == c.end());
++i;
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

View File

@@ -0,0 +1,56 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <unordered_map>
// Dereference non-dereferenceable iterator.
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <unordered_map>
#include <string>
#include <cassert>
#include <iterator>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
typedef std::unordered_map<int, std::string> C;
C c;
c.insert(std::make_pair(1, "one"));
C::iterator i = c.end();
C::value_type j = *i;
assert(false);
}
#if __cplusplus >= 201103L
{
typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
min_allocator<std::pair<const int, std::string>>> C;
C c;
c.insert(std::make_pair(1, "one"));
C::iterator i = c.end();
C::value_type j = *i;
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

View File

@@ -0,0 +1,57 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <unordered_map>
// Increment local_iterator past end.
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <unordered_map>
#include <string>
#include <cassert>
#include <iterator>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
typedef std::unordered_map<int, std::string> C;
C c(1);
C::local_iterator i = c.begin(0);
++i;
++i;
assert(false);
}
#if __cplusplus >= 201103L
{
typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
min_allocator<std::pair<const int, std::string>>> C;
C c(1);
C::local_iterator i = c.begin(0);
++i;
++i;
assert(false);
}
#endif
}
#else
int main()
{
}
#endif

View File

@@ -0,0 +1,54 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <unordered_map>
// Dereference non-dereferenceable iterator.
#if _LIBCPP_DEBUG >= 1
#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
#include <unordered_map>
#include <string>
#include <cassert>
#include <iterator>
#include <exception>
#include <cstdlib>
#include "min_allocator.h"
int main()
{
{
typedef std::unordered_map<int, std::string> C;
C c(1);
C::local_iterator i = c.end(0);
C::value_type j = *i;
assert(false);
}
#if __cplusplus >= 201103L
{
typedef std::unordered_map<int, std::string, std::hash<int>, std::equal_to<int>,
min_allocator<std::pair<const int, std::string>>> C;
C c(1);
C::local_iterator i = c.end(0);
C::value_type j = *i;
assert(false);
}
#endif
}
#else
int main()
{
}
#endif