Electroneum
epee::tests Namespace Reference

Classes

struct  port_test_struct
 
struct  port_test_struct_sub
 
struct  some_pod_struct
 
struct  test_struct
 

Functions

bool operator!= (const port_test_struct_sub &a, const port_test_struct_sub &b)
 
bool operator== (const port_test_struct &a, const port_test_struct &b)
 
void fill_struct_with_test_values (port_test_struct &s)
 
bool test_portable_storages (const std::string &tests_folder)
 
bool operator== (const test_struct &a, const test_struct &b)
 
test_struct get_test_struct ()
 
bool test_storages (const std::string &tests_folder)
 

Function Documentation

◆ fill_struct_with_test_values()

void epee::tests::fill_struct_with_test_values ( port_test_struct s)

Definition at line 155 of file portable_storages_test.h.

156  {
157  s.m_str = "zuzuzuzuzuz";
158  s.m_uint64 = 111111111111111;
159  s.m_uint32 = 2222222;
160  s.m_uint16 = 2222;
161  s.m_uint8 = 22;
162  s.m_int64 = -111111111111111;
163  s.m_int32 = -2222222;
164  s.m_int16 = -2222;
165  s.m_int8 = -24;
166  s.m_double = 0.11111;
167  s.m_bool = true;
168  s.m_pod.a = 32342342342342;
169  s.m_pod.b = -342342;
170  s.m_list_of_str.push_back("1112121");
171  s.m_list_of_uint64_t.push_back(1111111111);
172  s.m_list_of_uint64_t.push_back(2222222222);
173  s.m_list_of_uint32_t.push_back(1111111);
174  s.m_list_of_uint32_t.push_back(2222222);
175  s.m_list_of_uint16_t.push_back(1111);
176  s.m_list_of_uint16_t.push_back(2222);
177  s.m_list_of_uint8_t.push_back(11);
178  s.m_list_of_uint8_t.push_back(22);
179 
180 
181  s.m_list_of_int64_t.push_back(-1111111111);
182  s.m_list_of_int64_t.push_back(-222222222);
183  s.m_list_of_int32_t.push_back(-1111111);
184  s.m_list_of_int32_t.push_back(-2222222);
185  s.m_list_of_int16_t.push_back(-1111);
186  s.m_list_of_int16_t.push_back(-2222);
187  s.m_list_of_int8_t.push_back(-11);
188  s.m_list_of_int8_t.push_back(-22);
189 
190  s.m_list_of_double.push_back(0.11111);
191  s.m_list_of_double.push_back(0.22222);
192  s.m_list_of_bool.push_back(true);
193  s.m_list_of_bool.push_back(false);
194 
195  s.m_subobj.m_str = "subszzzzzzzz";
196  s.m_list_of_self.push_back(s);
197  }
Here is the caller graph for this function:

◆ get_test_struct()

test_struct epee::tests::get_test_struct ( )
inline

Definition at line 76 of file storage_tests.h.

77  {
78  test_struct t = boost::value_initialized<test_struct>();
79  t.m_bool = true;
80  t.m_str = "ackamdc'kmecemcececmacmecmcm[aicm[oeicm[oeicm[qaicm[qoe";
81  t.m_uint = 233242;
82  for(int i = 0; i!=500; i++)
83  t.m_list_of_int.push_back(i);
84 
85  for(int i = 0; i!=500; i++)
86  t.m_list_of_str.push_back("ssccd");
87 
88  for(int i = 0; i!=5; i++)
89  {
90  t.m_list_of_self.push_back(t);
91  }
92  return t;
93  }
Here is the caller graph for this function:

◆ operator!=()

bool epee::tests::operator!= ( const port_test_struct_sub a,
const port_test_struct_sub b 
)

Definition at line 117 of file portable_storages_test.h.

118  {
119  return b.m_str != a.m_str;
120  }
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124

◆ operator==() [1/2]

bool epee::tests::operator== ( const test_struct a,
const test_struct b 
)

Definition at line 63 of file storage_tests.h.

64  {
65  if( b.m_str != a.m_str
66  || b.m_uint != a.m_uint
67  || b.m_bool != a.m_bool
68  || b.m_list_of_str != a.m_list_of_str
69  || b.m_list_of_int != a.m_list_of_int
70  || b.m_list_of_self != a.m_list_of_self
71  )
72  return false;
73  return true;
74  }
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124

◆ operator==() [2/2]

bool epee::tests::operator== ( const port_test_struct a,
const port_test_struct b 
)

Definition at line 122 of file portable_storages_test.h.

123  {
124  if( b.m_str != a.m_str
125  || b.m_uint64 != a.m_uint64
126  || b.m_uint32 != a.m_uint32
127  || b.m_uint16 != a.m_uint16
128  || b.m_uint8 != a.m_uint8
129  || b.m_int64 != a.m_int64
130  || b.m_int32 != a.m_int32
131  || b.m_int16 != a.m_int16
132  || b.m_int8 != a.m_int8
133  || b.m_double != a.m_double
134  || b.m_bool != a.m_bool
135  || b.m_pod.a != a.m_pod.a
136  || b.m_pod.b != a.m_pod.b
137  || b.m_list_of_str != a.m_list_of_str
138  || b.m_list_of_uint64_t != a.m_list_of_uint64_t
139  || b.m_list_of_uint32_t != a.m_list_of_uint32_t
140  || b.m_list_of_uint16_t != a.m_list_of_uint16_t
141  || b.m_list_of_uint8_t != a.m_list_of_uint8_t
142  || b.m_list_of_int64_t != a.m_list_of_int64_t
143  || b.m_list_of_int32_t != a.m_list_of_int32_t
144  || b.m_list_of_int16_t != a.m_list_of_int16_t
145  || b.m_list_of_int8_t != a.m_list_of_int8_t
146  || b.m_list_of_double != a.m_list_of_double
147  || b.m_list_of_bool != a.m_list_of_bool
148  || b.m_subobj != a.m_subobj
149  || b.m_list_of_self != a.m_list_of_self
150  )
151  return false;
152  return true;
153  }
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124

◆ test_portable_storages()

bool epee::tests::test_portable_storages ( const std::string &  tests_folder)

Definition at line 199 of file portable_storages_test.h.

200  {
201  serialization::portable_storage ps, ps2;
202  port_test_struct s1, s2;
204 
205  s1.store(ps);
206  std::string binbuf;
207  bool r = ps.store_to_binary(binbuf);
208 
209  ps2.load_from_binary(binbuf);
210  s2.load(ps2);
211  if(!(s1 == s2))
212  {
213  LOG_ERROR("Portable storage test failed!");
214  return false;
215  }
216 
217 
218  port_test_struct ss1, ss2;
222  if(!(ss1 == ss2))
223  {
224  LOG_ERROR("Portable storage test failed!");
225  return false;
226  }
227 
228  return true;
229  }
::std::string string
Definition: gtest-port.h:1097
bool store_t_to_json(t_struct &str_in, std::string &json_buff, size_t indent=0, bool insert_newlines=true)
void fill_struct_with_test_values(port_test_struct &s)
bool load_t_from_json(t_struct &out, const std::string &json_buff)
#define LOG_ERROR(x)
Definition: misc_log_ex.h:98
Here is the call graph for this function:

◆ test_storages()

bool epee::tests::test_storages ( const std::string &  tests_folder)

Definition at line 95 of file storage_tests.h.

96  {
97 
99  auto s = ps.open_section("zzz", nullptr);
100  uint64_t i = 0;
101  ps.get_value("afdsdf", i, s);
102 
103 
104  LOG_PRINT_L0("Generating test struct...");
105  boost::filesystem::path storage_folder = tests_folder;
106  storage_folder /= "storages";
107 
108 
109  test_struct t = get_test_struct();
110 
111  LOG_PRINT_L0("Loading test struct from storage...");
112  test_struct t2;
113  bool res = epee::StorageNamed::load_struct_from_storage_file(t2, (storage_folder /+ "valid_storage.bin").string());
114  CHECK_AND_ASSERT_MES(res, false, "Failed to load valid_storage.bin");
115 
116  LOG_PRINT_L0("Comparing generated and loaded test struct...");
117  if(!(t == t2))
118  return false;
119 
120  LOG_PRINT_L0("Loading broken archive 1...");
121  test_struct t3;
122  res = epee::StorageNamed::load_struct_from_storage_file(t3, (storage_folder /+ "invalid_storage_1.bin").string());
123  CHECK_AND_ASSERT_MES(!res, false, "invalid_storage_1.bin loaded, but should not ");
124 
125 
126  LOG_PRINT_L0("Loading broken archive 2...");
127  res = epee::StorageNamed::load_struct_from_storage_file(t3, (storage_folder /+ "invalid_storage_2.bin").string());
128  CHECK_AND_ASSERT_MES(!res, false, "invalid_storage_2.bin loaded, but should not ");
129 
130  LOG_PRINT_L0("Loading broken archive 3...");
131  res = epee::StorageNamed::load_struct_from_storage_file(t3, (storage_folder /+ "invalid_storage_3.bin").string());
132  CHECK_AND_ASSERT_MES(!res, false, "invalid_storage_3.bin loaded, but should not ");
133 
134  LOG_PRINT_L0("Loading broken archive 4...");
135  res = epee::StorageNamed::load_struct_from_storage_file(t3, (storage_folder /+ "invalid_storage_4.bin").string());
136  CHECK_AND_ASSERT_MES(!res, false, "invalid_storage_3.bin loaded, but should not ");
137 
138  return true;
139  }
const char * res
Definition: hmac_keccak.cpp:41
test_struct get_test_struct()
Definition: storage_tests.h:76
hsection open_section(const std::string &section_name, hsection hparent_section, bool create_if_notexist=false)
bool get_value(const std::string &value_name, t_value &val, hsection hparent_section)
#define CHECK_AND_ASSERT_MES(expr, fail_ret_val, message)
Definition: misc_log_ex.h:181
#define LOG_PRINT_L0(x)
Definition: misc_log_ex.h:99
t3
Definition: pow225521.h:103
unsigned __int64 uint64_t
Definition: stdint.h:136
t2
Definition: pow22523.h:103
Here is the call graph for this function: