blob: 1340ff3db8a51df93e8a87219f39655093f1f181 [file] [log] [blame]
Ho Cheungb1dba172023-05-16 22:58:011// Copyright 2023 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <algorithm>
6#include <tuple>
7
8#include "testing/gtest/include/gtest/gtest.h"
9
10namespace {
11
12struct OneType {
13 int some_int;
14};
15
16bool operator<(const OneType& lhs, const OneType& rhs) {
17 return lhs.some_int < rhs.some_int;
18}
19
20struct AnotherType {
21 int some_other_int;
22};
23
24TEST(ClampTest, Death) {
25 EXPECT_DEATH_IF_SUPPORTED(std::ignore = std::clamp(3, 10, 0), "");
26 EXPECT_DEATH_IF_SUPPORTED(std::ignore = std::clamp(3.0, 10.0, 0.0), "");
27
28 OneType one_type_0{0};
29 OneType one_type_3{3};
30 OneType one_type_10{10};
31 AnotherType another_type_0{0};
32 AnotherType another_type_3{3};
33 AnotherType another_type_10{10};
34 auto compare_another_type = [](const auto& lhs, const auto& rhs) {
35 return lhs.some_other_int < rhs.some_other_int;
36 };
37
38 EXPECT_DEATH_IF_SUPPORTED(
39 std::ignore = std::clamp(one_type_3, one_type_10, one_type_0), "");
40 EXPECT_DEATH_IF_SUPPORTED(
41 std::ignore = std::clamp(another_type_3, another_type_10, another_type_0,
42 compare_another_type),
43 "");
44}
45
46} // namespace