summaryrefslogtreecommitdiffstats
path: root/mfbt/tests/TestVector.cpp
diff options
context:
space:
mode:
authorwolfbeast <mcwerewolf@gmail.com>2018-02-06 00:48:16 +0100
committerwolfbeast <mcwerewolf@gmail.com>2018-02-06 00:48:16 +0100
commit7c9b585349c985df0cf6ace83da5dadba8b5c677 (patch)
treef22acdd5995354fa704855a57cc09d54392d902e /mfbt/tests/TestVector.cpp
parente8417003899a4ec9274815be30352c1328fc32e9 (diff)
parenta9b44dbcb33cd98b163f8a21223643f2cf3829cd (diff)
downloadUXP-7c9b585349c985df0cf6ace83da5dadba8b5c677.tar
UXP-7c9b585349c985df0cf6ace83da5dadba8b5c677.tar.gz
UXP-7c9b585349c985df0cf6ace83da5dadba8b5c677.tar.lz
UXP-7c9b585349c985df0cf6ace83da5dadba8b5c677.tar.xz
UXP-7c9b585349c985df0cf6ace83da5dadba8b5c677.zip
Merge branch 'ported-upstream'
Diffstat (limited to 'mfbt/tests/TestVector.cpp')
-rw-r--r--mfbt/tests/TestVector.cpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/mfbt/tests/TestVector.cpp b/mfbt/tests/TestVector.cpp
index d969bcbc2..e28b432d6 100644
--- a/mfbt/tests/TestVector.cpp
+++ b/mfbt/tests/TestVector.cpp
@@ -22,6 +22,7 @@ struct mozilla::detail::VectorTesting
static void testReverse();
static void testExtractRawBuffer();
static void testExtractOrCopyRawBuffer();
+ static void testInsert();
};
void
@@ -141,6 +142,15 @@ struct S
destructCount++;
}
+ S& operator=(S&& rhs) {
+ j = rhs.j;
+ rhs.j = 0;
+ k = Move(rhs.k);
+ rhs.k.reset();
+ moveCount++;
+ return *this;
+ }
+
S(const S&) = delete;
S& operator=(const S&) = delete;
};
@@ -346,6 +356,47 @@ mozilla::detail::VectorTesting::testExtractOrCopyRawBuffer()
free(buf);
}
+void
+mozilla::detail::VectorTesting::testInsert()
+{
+ S::resetCounts();
+
+ Vector<S, 8> vec;
+ MOZ_RELEASE_ASSERT(vec.reserve(8));
+ for (size_t i = 0; i < 7; i++) {
+ vec.infallibleEmplaceBack(i, i * i);
+ }
+
+ MOZ_RELEASE_ASSERT(vec.length() == 7);
+ MOZ_ASSERT(vec.reserved() == 8);
+ MOZ_RELEASE_ASSERT(S::constructCount == 7);
+ MOZ_RELEASE_ASSERT(S::moveCount == 0);
+ MOZ_RELEASE_ASSERT(S::destructCount == 0);
+
+ S s(42, 43);
+ MOZ_RELEASE_ASSERT(vec.insert(vec.begin() + 4, Move(s)));
+
+ for (size_t i = 0; i < vec.length(); i++) {
+ const S& s = vec[i];
+ MOZ_RELEASE_ASSERT(s.k);
+ if (i < 4) {
+ MOZ_RELEASE_ASSERT(s.j == i && *s.k == i * i);
+ } else if (i == 4) {
+ MOZ_RELEASE_ASSERT(s.j == 42 && *s.k == 43);
+ } else {
+ MOZ_RELEASE_ASSERT(s.j == i - 1 && *s.k == (i - 1) * (i - 1));
+ }
+ }
+
+ MOZ_RELEASE_ASSERT(vec.length() == 8);
+ MOZ_ASSERT(vec.reserved() == 8);
+ MOZ_RELEASE_ASSERT(S::constructCount == 8);
+ MOZ_RELEASE_ASSERT(S::moveCount == 1 /* move in insert() call */ +
+ 1 /* move the back() element */ +
+ 3 /* elements to shift */);
+ MOZ_RELEASE_ASSERT(S::destructCount == 1);
+}
+
int
main()
{
@@ -355,4 +406,5 @@ main()
VectorTesting::testReverse();
VectorTesting::testExtractRawBuffer();
VectorTesting::testExtractOrCopyRawBuffer();
+ VectorTesting::testInsert();
}