Pigweed
 
Loading...
Searching...
No Matches
fake_lease_provider.h
1// Copyright 2025 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14#pragma once
15
16#include "pw_bluetooth_sapphire/lease.h"
17
18namespace pw::bluetooth_sapphire::testing {
19
21class FakeLeaseProvider final : public LeaseProvider {
22 public:
23 FakeLeaseProvider() = default;
24 ~FakeLeaseProvider() override = default;
26 FakeLeaseProvider& operator=(FakeLeaseProvider&&) = delete;
27
28 Result<Lease> Acquire(PW_SAPPHIRE_LEASE_TOKEN_TYPE) override {
29 if (!status_.ok()) {
30 return status_;
31 }
32 lease_count_++;
33 return Lease([this]() { lease_count_--; });
34 }
35
37 uint16_t lease_count() const { return lease_count_; }
38
40 void set_acquire_status(Status status) { status_ = status; }
41
42 private:
43 uint16_t lease_count_ = 0;
44 Status status_ = PW_STATUS_OK;
45};
46
47} // namespace pw::bluetooth_sapphire::testing
Definition: status.h:85
constexpr bool ok() const
Definition: status.h:157
Definition: lease.h:31
A fake LeaseProvider used for dependency injection in unit tests.
Definition: fake_lease_provider.h:21
void set_acquire_status(Status status)
Sets the status to return from the Acquire method.
Definition: fake_lease_provider.h:40
Result< Lease > Acquire(PW_SAPPHIRE_LEASE_TOKEN_TYPE) override
Definition: fake_lease_provider.h:28
uint16_t lease_count() const
Returns the number of active leases.
Definition: fake_lease_provider.h:37