[libcxx][test][NFC] Extend get_allocator() testing for containers

Add dedicated tests for get_allocator() method for sequence, ordered and
unordered associative containers including constness coverage.

Reviewed by: ldionne, Mordante, rarutyun, #libc

Differential revision: https://reviews.llvm.org/D114785
This commit is contained in:
Konstantin Boyarinov 2021-12-01 16:04:59 +03:00 committed by Ruslan Arutyunyan
parent 0428d44d4c
commit 8d25da78aa
13 changed files with 458 additions and 0 deletions

View File

@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <map>
// class map
// allocator_type get_allocator() const
#include <map>
#include <cassert>
#include <string>
#include "test_allocator.h"
#include "test_macros.h"
int main(int, char**) {
typedef std::pair<const int, std::string> ValueType;
{
std::allocator<ValueType> alloc;
const std::map<int, std::string> m(alloc);
assert(m.get_allocator() == alloc);
}
{
other_allocator<ValueType> alloc(1);
const std::map<int, std::string, std::less<int>,
other_allocator<ValueType> > m(alloc);
assert(m.get_allocator() == alloc);
}
return 0;
}

View File

@ -0,0 +1,37 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <map>
// class multimap
// allocator_type get_allocator() const
#include <map>
#include <cassert>
#include <string>
#include "test_allocator.h"
#include "test_macros.h"
int main(int, char**) {
typedef std::pair<const int, std::string> ValueType;
{
std::allocator<ValueType> alloc;
const std::multimap<int, std::string> m(alloc);
assert(m.get_allocator() == alloc);
}
{
other_allocator<ValueType> alloc(1);
const std::multimap<int, std::string, std::less<int>,
other_allocator<ValueType> > m(alloc);
assert(m.get_allocator() == alloc);
}
return 0;
}

View File

@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <set>
// class multiset
// allocator_type get_allocator() const
#include <set>
#include <cassert>
#include "test_allocator.h"
#include "test_macros.h"
int main(int, char**) {
{
std::allocator<int> alloc;
const std::multiset<int> s(alloc);
assert(s.get_allocator() == alloc);
}
{
other_allocator<int> alloc(1);
const std::multiset<int, std::less<int>, other_allocator<int> > s(alloc);
assert(s.get_allocator() == alloc);
}
return 0;
}

View File

@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <set>
// class set
// allocator_type get_allocator() const
#include <set>
#include <cassert>
#include "test_allocator.h"
#include "test_macros.h"
int main(int, char**) {
{
std::allocator<int> alloc;
const std::set<int> s(alloc);
assert(s.get_allocator() == alloc);
}
{
other_allocator<int> alloc(1);
const std::set<int, std::less<int>, other_allocator<int> > s(alloc);
assert(s.get_allocator() == alloc);
}
return 0;
}

View File

@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <deque>
// class deque
// allocator_type get_allocator() const
#include <deque>
#include <cassert>
#include "test_allocator.h"
#include "test_macros.h"
int main(int, char**) {
{
std::allocator<int> alloc;
const std::deque<int> d(alloc);
assert(d.get_allocator() == alloc);
}
{
other_allocator<int> alloc(1);
const std::deque<int, other_allocator<int> > d(alloc);
assert(d.get_allocator() == alloc);
}
return 0;
}

View File

@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <forward_list>
// class forward_list
// allocator_type get_allocator() const
#include <forward_list>
#include <cassert>
#include "test_allocator.h"
#include "test_macros.h"
int main(int, char**) {
{
std::allocator<int> alloc;
const std::forward_list<int> fl(alloc);
assert(fl.get_allocator() == alloc);
}
{
other_allocator<int> alloc(1);
const std::forward_list<int, other_allocator<int> > fl(alloc);
assert(fl.get_allocator() == alloc);
}
return 0;
}

View File

@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <list>
// class list
// allocator_type get_allocator() const
#include <list>
#include <cassert>
#include "test_allocator.h"
#include "test_macros.h"
int main(int, char**) {
{
std::allocator<int> alloc;
const std::list<int> l(alloc);
assert(l.get_allocator() == alloc);
}
{
other_allocator<int> alloc(1);
const std::list<int, other_allocator<int> > l(alloc);
assert(l.get_allocator() == alloc);
}
return 0;
}

View File

@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <vector>
// class vector<bool>
// allocator_type get_allocator() const
#include <vector>
#include <cassert>
#include "test_allocator.h"
#include "test_macros.h"
int main(int, char**) {
{
std::allocator<int> alloc;
const std::vector<bool> vb(alloc);
assert(vb.get_allocator() == alloc);
}
{
other_allocator<int> alloc(1);
const std::vector<bool, other_allocator<int> > vb(alloc);
assert(vb.get_allocator() == alloc);
}
return 0;
}

View File

@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <vector>
// class vector
// allocator_type get_allocator() const
#include <vector>
#include <cassert>
#include "test_allocator.h"
#include "test_macros.h"
int main(int, char**) {
{
std::allocator<int> alloc;
const std::vector<int> v(alloc);
assert(v.get_allocator() == alloc);
}
{
other_allocator<int> alloc(1);
const std::vector<int, other_allocator<int> > v(alloc);
assert(v.get_allocator() == alloc);
}
return 0;
}

View File

@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <unordered_map>
// class unordered_map
// allocator_type get_allocator() const
#include <unordered_map>
#include <cassert>
#include <string>
#include "test_allocator.h"
#include "test_macros.h"
int main(int, char**) {
typedef std::pair<const int, std::string> ValueType;
{
std::allocator<ValueType> alloc;
const std::unordered_map<int, std::string> m(alloc);
assert(m.get_allocator() == alloc);
}
{
other_allocator<ValueType> alloc(1);
const std::unordered_map<int, std::string, std::hash<int>,
std::equal_to<int>,
other_allocator<ValueType> > m(alloc);
assert(m.get_allocator() == alloc);
}
return 0;
}

View File

@ -0,0 +1,38 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <unordered_map>
// class unordered_multimap
// allocator_type get_allocator() const
#include <unordered_map>
#include <cassert>
#include <string>
#include "test_allocator.h"
#include "test_macros.h"
int main(int, char**) {
typedef std::pair<const int, std::string> ValueType;
{
std::allocator<ValueType> alloc;
const std::unordered_multimap<int, std::string> m(alloc);
assert(m.get_allocator() == alloc);
}
{
other_allocator<ValueType> alloc(1);
const std::unordered_multimap<int, std::string, std::hash<int>,
std::equal_to<int>,
other_allocator<ValueType> > m(alloc);
assert(m.get_allocator() == alloc);
}
return 0;
}

View File

@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <unordered_set>
// class unordered_multiset
// allocator_type get_allocator() const
#include <unordered_set>
#include <cassert>
#include "test_allocator.h"
#include "test_macros.h"
int main(int, char**) {
{
std::allocator<int> alloc;
const std::unordered_multiset<int> s(alloc);
assert(s.get_allocator() == alloc);
}
{
other_allocator<int> alloc(1);
const std::unordered_multiset<int, std::hash<int>,
std::equal_to<int>,
other_allocator<int> > s(alloc);
assert(s.get_allocator() == alloc);
}
return 0;
}

View File

@ -0,0 +1,36 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// <unordered_set>
// class unordered_set
// allocator_type get_allocator() const
#include <unordered_set>
#include <cassert>
#include "test_allocator.h"
#include "test_macros.h"
int main(int, char**) {
{
std::allocator<int> alloc;
const std::unordered_set<int> s(alloc);
assert(s.get_allocator() == alloc);
}
{
other_allocator<int> alloc(1);
const std::unordered_set<int, std::hash<int>,
std::equal_to<int>,
other_allocator<int> > s(alloc);
assert(s.get_allocator() == alloc);
}
return 0;
}