/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// This is a cppunittest, rather than a gtest, in order to assert that no // additional DLL needs to be linked in to use the function(s) tested herein.
// Introduce iostream output operators for std::optional, for convenience's // sake. // // (This is technically undefined behavior per [namespace.std], but it's // unlikely to have any surprising effects when confined to this compilation // unit.) namespace std { template <typename T>
std::ostream& operator<<(std::ostream& o, std::optional<T> const& s) { if (s) { return o << "std::optional{" << s.value() << "}";
} return o << "std::nullopt";
}
std::ostream& operator<<(std::ostream& o, std::nullopt_t const& s) { return o << "std::nullopt";
}
} // namespace std
// EXPECT_EQ // // Assert that two expressions are equal. Print them, and their values, on // failure. (Based on the GTest macro of the same name.) template <typename X, typename Y, size_t Xn, size_t Yn> void AssertEqualImpl_(X&& x, Y&& y, constchar* file, size_t line, constchar (&xStr)[Xn], constchar (&yStr)[Yn], constchar* explanation = nullptr) { if (MOZ_LIKELY(x == y)) return;
#define EXPECT_EQ(x, y) \ do { \
AssertEqualImpl_(x, y, __FILE__, __LINE__, #x, #y); \
} while (0)
// STATIC_ASSERT_VALUE_IS_OF_TYPE // // Assert that a value `v` is of type `t` (ignoring cv-qualification). #define STATIC_ASSERT_VALUE_IS_OF_TYPE(v, t) \
static_assert(std::is_same_v<std::remove_cv_t<decltype(v)>, t>)
// MockSleep // // Mock replacement for ::Sleep that merely logs its calls. struct MockSleep {
size_t calls = 0;
size_t sum = 0;
voidoperator()(size_t val) {
++calls;
sum += val;
}
// semantic test: stalls as requested but still yields a value, // up until it doesn't for (size_t i = 0; i < 20; ++i) {
MockSleep sleep; autoconst ret =
stall.StallAndRetry(sleep, MockAlloc<int>{.count = i, .value = 5});
STATIC_ASSERT_VALUE_IS_OF_TYPE(ret, std::optional<int>);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.