chromium/base/allocator/partition_allocator/src/partition_alloc/pointers/raw_ptr_test_support.h

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef PARTITION_ALLOC_POINTERS_RAW_PTR_TEST_SUPPORT_H_
#define PARTITION_ALLOC_POINTERS_RAW_PTR_TEST_SUPPORT_H_

#include <optional>

#include "testing/gmock/include/gmock/gmock.h"

// Struct intended to be used with designated initializers and passed
// to the `CountersMatch()` matcher.
//
// TODO(tsepez): Although we only want one kind of these, the class is still
// a template to circumvent the chromium-style out-of-line constructor rule.
// Adding such a constructor would make this no longer be an aggregate and
// that would prohibit designated initiaizers.
template <int IGNORE>
struct CountingRawPtrExpectationTemplate {};
CountingRawPtrExpectations;

#define REPORT_UNEQUAL_RAW_PTR_COUNTER

#define REPORT_UNEQUAL_RAW_PTR_COUNTERS

// Matcher used with `CountingRawPtr`. Provides slightly shorter
// boilerplate for verifying counts. This inner function is detached
// from the `MATCHER`.
inline bool CountersMatchImpl(const CountingRawPtrExpectations& arg,
                              testing::MatchResultListener* result_listener) {}

// Implicit `arg` has type `CountingRawPtrExpectations`, specialized for
// the specific counting impl.
MATCHER(CountersMatch, "counting impl has specified counters") {}

#undef REPORT_UNEQUAL_RAW_PTR_COUNTERS
#undef REPORT_UNEQUAL_RAW_PTR_COUNTER

#endif  // PARTITION_ALLOC_POINTERS_RAW_PTR_TEST_SUPPORT_H_