rippled
flags.cpp
1 //------------------------------------------------------------------------------
2 /*
3  This file is part of rippled: https://github.com/ripple/rippled
4  Copyright (c) 2012, 2013 Ripple Labs Inc.
5 
6  Permission to use, copy, modify, and/or distribute this software for any
7  purpose with or without fee is hereby granted, provided that the above
8  copyright notice and this permission notice appear in all copies.
9 
10  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18 //==============================================================================
19 
20 #include <ripple/protocol/jss.h>
21 #include <test/jtx/flags.h>
22 
23 namespace ripple {
24 namespace test {
25 namespace jtx {
26 
28 fset(Account const& account, std::uint32_t on, std::uint32_t off)
29 {
30  Json::Value jv;
31  jv[jss::Account] = account.human();
32  jv[jss::TransactionType] = jss::AccountSet;
33  if (on != 0)
34  jv[jss::SetFlag] = on;
35  if (off != 0)
36  jv[jss::ClearFlag] = off;
37  return jv;
38 }
39 
40 void
42 {
43  auto const sle = env.le(account_);
44  if (sle->isFieldPresent(sfFlags))
45  env.test.expect((sle->getFieldU32(sfFlags) & mask_) == mask_);
46  else
47  env.test.expect(mask_ == 0);
48 }
49 
50 void
52 {
53  auto const sle = env.le(account_);
54  if (sle->isFieldPresent(sfFlags))
55  env.test.expect((sle->getFieldU32(sfFlags) & mask_) == 0);
56  else
57  env.test.pass();
58 }
59 
60 } // namespace jtx
61 } // namespace test
62 } // namespace ripple
ripple::test::jtx::nflags::operator()
void operator()(Env &env) const
Definition: flags.cpp:51
ripple::test::jtx::flags::account_
Account account_
Definition: flags.h:111
ripple::test::jtx::detail::flags_helper::mask_
std::uint32_t mask_
Definition: flags.h:50
ripple::test::jtx::nflags::account_
Account account_
Definition: flags.h:128
ripple::test::jtx::fset
Json::Value fset(Account const &account, std::uint32_t on, std::uint32_t off=0)
Add and/or remove flag.
Definition: flags.cpp:28
std::uint32_t
ripple::test::jtx::Env::test
beast::unit_test::suite & test
Definition: Env.h:119
ripple::test::jtx::flags::operator()
void operator()(Env &env) const
Definition: flags.cpp:41
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::sfFlags
const SF_UINT32 sfFlags
ripple::test::jtx::Env::le
std::shared_ptr< SLE const > le(Account const &account) const
Return an account root.
Definition: Env.cpp:216
ripple::test::jtx::Account
Immutable cryptographic account descriptor.
Definition: Account.h:37
ripple::test::jtx::Env
A transaction testing environment.
Definition: Env.h:116
Json::Value
Represents a JSON value.
Definition: json_value.h:145