[libcxx-commits] [libcxx] 8d25da7 - [libcxx][test][NFC] Extend get_allocator() testing for containers

Ruslan Arutyunyan via libcxx-commits libcxx-commits at lists.llvm.org
Wed Dec 1 05:25:09 PST 2021


Author: Konstantin Boyarinov
Date: 2021-12-01T16:15:19+03:00
New Revision: 8d25da78aad91635f78225edd972feb2de7228cd

URL: https://github.com/llvm/llvm-project/commit/8d25da78aad91635f78225edd972feb2de7228cd
DIFF: https://github.com/llvm/llvm-project/commit/8d25da78aad91635f78225edd972feb2de7228cd.diff

LOG: [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

Added: 
    libcxx/test/std/containers/associative/map/get_allocator.pass.cpp
    libcxx/test/std/containers/associative/multimap/get_allocator.pass.cpp
    libcxx/test/std/containers/associative/multiset/get_allocator.pass.cpp
    libcxx/test/std/containers/associative/set/get_allocator.pass.cpp
    libcxx/test/std/containers/sequences/deque/get_allocator.pass.cpp
    libcxx/test/std/containers/sequences/forwardlist/get_allocator.pass.cpp
    libcxx/test/std/containers/sequences/list/get_allocator.pass.cpp
    libcxx/test/std/containers/sequences/vector.bool/get_allocator.pass.cpp
    libcxx/test/std/containers/sequences/vector/get_allocator.pass.cpp
    libcxx/test/std/containers/unord/unord.map/get_allocator.pass.cpp
    libcxx/test/std/containers/unord/unord.multimap/get_allocator.pass.cpp
    libcxx/test/std/containers/unord/unord.multiset/get_allocator.pass.cpp
    libcxx/test/std/containers/unord/unord.set/get_allocator.pass.cpp

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/libcxx/test/std/containers/associative/map/get_allocator.pass.cpp b/libcxx/test/std/containers/associative/map/get_allocator.pass.cpp
new file mode 100644
index 000000000000..b214e44b41ba
--- /dev/null
+++ b/libcxx/test/std/containers/associative/map/get_allocator.pass.cpp
@@ -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;
+}

diff  --git a/libcxx/test/std/containers/associative/multimap/get_allocator.pass.cpp b/libcxx/test/std/containers/associative/multimap/get_allocator.pass.cpp
new file mode 100644
index 000000000000..41dfaa77c660
--- /dev/null
+++ b/libcxx/test/std/containers/associative/multimap/get_allocator.pass.cpp
@@ -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;
+}

diff  --git a/libcxx/test/std/containers/associative/multiset/get_allocator.pass.cpp b/libcxx/test/std/containers/associative/multiset/get_allocator.pass.cpp
new file mode 100644
index 000000000000..3d0d8a4dcb1f
--- /dev/null
+++ b/libcxx/test/std/containers/associative/multiset/get_allocator.pass.cpp
@@ -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;
+}

diff  --git a/libcxx/test/std/containers/associative/set/get_allocator.pass.cpp b/libcxx/test/std/containers/associative/set/get_allocator.pass.cpp
new file mode 100644
index 000000000000..f6a7d5a97623
--- /dev/null
+++ b/libcxx/test/std/containers/associative/set/get_allocator.pass.cpp
@@ -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;
+}

diff  --git a/libcxx/test/std/containers/sequences/deque/get_allocator.pass.cpp b/libcxx/test/std/containers/sequences/deque/get_allocator.pass.cpp
new file mode 100644
index 000000000000..e42dbb7d7515
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/deque/get_allocator.pass.cpp
@@ -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;
+}

diff  --git a/libcxx/test/std/containers/sequences/forwardlist/get_allocator.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/get_allocator.pass.cpp
new file mode 100644
index 000000000000..9d88e7c0fe87
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/forwardlist/get_allocator.pass.cpp
@@ -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;
+}

diff  --git a/libcxx/test/std/containers/sequences/list/get_allocator.pass.cpp b/libcxx/test/std/containers/sequences/list/get_allocator.pass.cpp
new file mode 100644
index 000000000000..895fc219086a
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/list/get_allocator.pass.cpp
@@ -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;
+}

diff  --git a/libcxx/test/std/containers/sequences/vector.bool/get_allocator.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/get_allocator.pass.cpp
new file mode 100644
index 000000000000..566d1f81bafc
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/vector.bool/get_allocator.pass.cpp
@@ -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;
+}

diff  --git a/libcxx/test/std/containers/sequences/vector/get_allocator.pass.cpp b/libcxx/test/std/containers/sequences/vector/get_allocator.pass.cpp
new file mode 100644
index 000000000000..3734893bfc57
--- /dev/null
+++ b/libcxx/test/std/containers/sequences/vector/get_allocator.pass.cpp
@@ -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;
+}

diff  --git a/libcxx/test/std/containers/unord/unord.map/get_allocator.pass.cpp b/libcxx/test/std/containers/unord/unord.map/get_allocator.pass.cpp
new file mode 100644
index 000000000000..64836abfff03
--- /dev/null
+++ b/libcxx/test/std/containers/unord/unord.map/get_allocator.pass.cpp
@@ -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;
+}

diff  --git a/libcxx/test/std/containers/unord/unord.multimap/get_allocator.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/get_allocator.pass.cpp
new file mode 100644
index 000000000000..2cca55894902
--- /dev/null
+++ b/libcxx/test/std/containers/unord/unord.multimap/get_allocator.pass.cpp
@@ -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;
+}

diff  --git a/libcxx/test/std/containers/unord/unord.multiset/get_allocator.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/get_allocator.pass.cpp
new file mode 100644
index 000000000000..699565cc0378
--- /dev/null
+++ b/libcxx/test/std/containers/unord/unord.multiset/get_allocator.pass.cpp
@@ -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;
+}

diff  --git a/libcxx/test/std/containers/unord/unord.set/get_allocator.pass.cpp b/libcxx/test/std/containers/unord/unord.set/get_allocator.pass.cpp
new file mode 100644
index 000000000000..1b0a6520da04
--- /dev/null
+++ b/libcxx/test/std/containers/unord/unord.set/get_allocator.pass.cpp
@@ -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;
+}


        


More information about the libcxx-commits mailing list