Blender V4.3
BLI_memory_utils_test.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "testing/testing.h"
6
8#include "BLI_memory_utils.hh"
9
10#include "BLI_strict_flags.h" /* Keep last. */
11
12namespace blender::tests {
13
15 virtual void mymethod(){};
16};
17
19 void mymethod() override {}
20};
21
47
58
61static_assert(is_same_any_v<int, int>);
63static_assert(!is_same_any_v<int, float>);
64static_assert(!is_same_any_v<int>);
65
66TEST(memory_utils, ScopedDefer1)
67{
68 int a = 0;
69 {
70 BLI_SCOPED_DEFER([&]() { a -= 5; });
71 {
72 BLI_SCOPED_DEFER([&]() { a *= 10; });
73 a = 5;
74 }
75 }
76 EXPECT_EQ(a, 45);
77}
78
79TEST(memory_utils, ScopedDefer2)
80{
81 std::string s;
82 {
83 BLI_SCOPED_DEFER([&]() { s += "A"; });
84 BLI_SCOPED_DEFER([&]() { s += "B"; });
85 BLI_SCOPED_DEFER([&]() { s += "C"; });
86 BLI_SCOPED_DEFER([&]() { s += "D"; });
87 }
88 EXPECT_EQ(s, "DCBA");
89}
90
91} // namespace blender::tests
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
#define BLI_SCOPED_DEFER(function_to_defer)
TEST(any, DefaultConstructor)
constexpr bool is_same_any_v
constexpr bool is_convertible_pointer_v
constexpr bool is_span_convertible_pointer_v