rippled
Loading...
Searching...
No Matches
/libxrpl/protocol_autogen/TestHelpers.h
1#pragma once
2
3#include <xrpl/basics/Number.h>
4#include <xrpl/basics/Slice.h>
5#include <xrpl/protocol/AccountID.h>
6#include <xrpl/protocol/Asset.h>
7#include <xrpl/protocol/Issue.h>
8#include <xrpl/protocol/SField.h>
9#include <xrpl/protocol/STAmount.h>
10#include <xrpl/protocol/STArray.h>
11#include <xrpl/protocol/STBlob.h>
12#include <xrpl/protocol/STNumber.h>
13#include <xrpl/protocol/STObject.h>
14#include <xrpl/protocol/STPathSet.h>
15#include <xrpl/protocol/STVector256.h>
16#include <xrpl/protocol/STXChainBridge.h>
17#include <xrpl/protocol/UintTypes.h>
18
19#include <gtest/gtest.h>
20
21#include <array>
22#include <cstdint>
23#include <functional>
24#include <type_traits>
25#include <vector>
26
27namespace xrpl {
28
29// Typed field canonical values
30
32inline Uint8Value
34{
35 return Uint8Value{1};
36}
37
39inline Uint16Value
41{
42 return Uint16Value{1};
43}
44
46inline Uint32Value
48{
49 return Uint32Value{1};
50}
51
53inline Uint64Value
55{
56 return Uint64Value{1};
57}
58
60inline Uint128Value
62{
63 return Uint128Value{1};
64}
65
67inline Uint160Value
69{
70 return Uint160Value{1};
71}
72
74inline Uint192Value
76{
77 return Uint192Value{1};
78}
79
81inline Uint256Value
83{
84 return Uint256Value{1};
85}
86
88inline Int32Value
90{
91 return Int32Value{42};
92}
93
95inline NumberValue
97{
98 return NumberValue{123};
99}
100
102inline AmountValue
104{
105 return AmountValue{XRPAmount{1}};
106}
107
109inline AccountValue
111{
112 return xrpAccount();
113}
114
116inline CurrencyValue
118{
119 return xrpCurrency();
120}
121
123inline IssueValue
125{
126 return IssueValue{xrpIssue()};
127}
128
130inline Vector256Value
132{
133 return Vector256Value{uint256{1}};
134}
135
137inline BlobValue
139{
140 static constexpr std::array<std::uint8_t, 3> data{{'a', 'b', 'c'}};
141 return BlobValue{data.data(), data.size()};
142}
143
150
151// Untyped field canonical values
152
153inline STArray
155{
156 return STArray{};
157}
158
159inline STObject
161{
162 return STObject{sfGeneric};
163}
164
165inline STPathSet
167{
168 STPathSet result{};
169 result.push_back(STPath{});
170 return result;
171}
172
173// Field comparison helpers for generated tests
174
175template <class T>
176void
177expectEqualField(T const& expected, T const& actual, char const* fieldName)
178{
179 EXPECT_EQ(expected, actual) << "Field " << fieldName << " mismatch";
180}
181
182// Specialization for STObject (no operator==, use isEquivalent)
183template <>
184inline void
185expectEqualField<STObject>(STObject const& expected, STObject const& actual, char const* fieldName)
186{
187 EXPECT_TRUE(expected.isEquivalent(actual)) << "Field " << fieldName << " mismatch";
188}
189
190// Specialization for STPathSet (no operator==, use isEquivalent)
191template <>
192inline void
194 STPathSet const& expected,
195 STPathSet const& actual,
196 char const* fieldName)
197{
198 EXPECT_TRUE(expected.isEquivalent(actual)) << "Field " << fieldName << " mismatch";
199}
200
201// Overloads for std::reference_wrapper (used by optional ARRAY/PATHSET fields)
202template <class T>
203void
204expectEqualField(T const& expected, std::reference_wrapper<T const> actual, char const* fieldName)
205{
206 expectEqualField(expected, actual.get(), fieldName);
207}
208
209} // namespace xrpl
bool isEquivalent(STBase const &t) const override
Definition STObject.cpp:342
void push_back(STPath const &e)
Definition STPathSet.h:486
bool isEquivalent(STBase const &t) const override
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
Issue const & xrpIssue()
Returns an asset specifier that represents XRP.
Definition Issue.h:97
void expectEqualField< STPathSet >(STPathSet const &expected, STPathSet const &actual, char const *fieldName)
Vector256Value canonical_VECTOR256()
SField const sfGeneric
XChainBridgeValue canonical_XCHAIN_BRIDGE()
Currency const & xrpCurrency()
XRP currency.
Definition UintTypes.cpp:98
void expectEqualField< STObject >(STObject const &expected, STObject const &actual, char const *fieldName)
CurrencyValue canonical_CURRENCY()
AccountID const & xrpAccount()
Compute AccountID from public key.
void expectEqualField(T const &expected, T const &actual, char const *fieldName)