Android-cuttlefish cvd tool
fake_nfnetlink_socket.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ALLOCD_TEST_FAKE_NFNETLINK_SOCKET_H_
18#define ALLOCD_TEST_FAKE_NFNETLINK_SOCKET_H_
19
20#include <deque>
21#include <memory>
22#include <vector>
23
26
27namespace cuttlefish {
28
29// Records what is sent and returns queued replies. The state is shared so a
30// test can still inspect it after the socket is destroyed.
32 public:
33 struct State {
34 // Everything passed to Transact, in order.
35 std::vector<std::vector<char>> sent;
36 // Replies for the next Transact calls, then empty replies.
37 std::deque<std::vector<char>> replies;
38 };
39
40 explicit FakeNfnetlinkSocket(std::shared_ptr<State> state);
41
43 const std::vector<char>& messages) override;
44
45 private:
46 std::shared_ptr<State> state_;
47};
48
49} // namespace cuttlefish
50
51#endif // ALLOCD_TEST_FAKE_NFNETLINK_SOCKET_H_
Definition: fake_nfnetlink_socket.h:31
Result< std::vector< char > > Transact(const std::vector< char > &messages) override
Definition: fake_nfnetlink_socket.cc:30
FakeNfnetlinkSocket(std::shared_ptr< State > state)
Definition: fake_nfnetlink_socket.cc:27
std::shared_ptr< State > state_
Definition: fake_nfnetlink_socket.h:46
Definition: nfnetlink_socket.h:27
Definition: alloc_driver.h:21
tl::expected< T, StackTraceError< E > > Result
Definition: result_type.h:30
Definition: fake_nfnetlink_socket.h:33
std::vector< std::vector< char > > sent
Definition: fake_nfnetlink_socket.h:35
std::deque< std::vector< char > > replies
Definition: fake_nfnetlink_socket.h:37