Scarab  v2.4.11
Project 8 C++ Utility Library
test_param_value.cc
Go to the documentation of this file.
1 /*
2  * test_param_value.cc
3  *
4  * Created on: Jul 13, 2018
5  * Author: N.S. Oblath
6  *
7  * Output should be something like this:
8  *
9 2018-07-13 15:25:14 [ INFO] (tid 0x7fff9c9dc380) t_param_value.cc(18): Bool Value Tests
10 2018-07-13 15:25:14 [ INFO] (tid 0x7fff9c9dc380) t_param_value.cc(21): Bool value via string: true
11 2018-07-13 15:25:14 [ INFO] (tid 0x7fff9c9dc380) t_param_value.cc(23): Int Value Tests
12 2018-07-13 15:25:14 [ INFO] (tid 0x7fff9c9dc380) t_param_value.cc(27): Int value via int: 5
13 2018-07-13 15:25:14 [ INFO] (tid 0x7fff9c9dc380) t_param_value.cc(28): Int value via string: 5
14 2018-07-13 15:25:14 [ INFO] (tid 0x7fff9c9dc380) t_param_value.cc(30): String Value Tests
15 2018-07-13 15:25:14 [ INFO] (tid 0x7fff9c9dc380) t_param_value.cc(32): String value: hello world
16 2018-07-13 15:25:14 [ INFO] (tid 0x7fff9c9dc380) t_param_value.cc(35): String containing a number via as_int: 10
17 2018-07-13 15:25:14 [ INFO] (tid 0x7fff9c9dc380) t_param_value.cc(38): String containing a bool via as_bool: 1
18  *
19  */
20 
21 #include "param_value.hh"
22 
23 #include "logger.hh"
24 
25 LOGGER( testlog, "test_param_value" )
26 
27 using namespace scarab;
28 
29 int main()
30 {
31  LINFO( testlog, "Bool Value Tests" );
32  LINFO( testlog, "================" );
33 
34  param_value bool_val( true );
35 
36  LINFO( testlog, "Bool value via string: " << bool_val );
37 
38  LINFO( testlog, "Int Value Tests" );
39  LINFO( testlog, "===============" );
40 
41  param_value int_val( 5 );
42  int val_out = int_val.as_int();
43 
44  LINFO( testlog, "Int value via int: " << val_out );
45  LINFO( testlog, "Int value via string: " << int_val );
46 
47  LINFO( testlog, "String Value Tests" );
48  LINFO( testlog, "==================" );
49 
50  param_value string_val( "hello world" );
51  LINFO( testlog, "String value: " << string_val );
52 
53  string_val.set( "10" );
54  LINFO( testlog, "String containing a number via as_int: " << string_val.as_int() );
55 
56  string_val.set( "true" );
57  LINFO( testlog, "String containing a bool via as_bool: " << string_val.as_bool() );
58 
59  LINFO( testlog, "Strict Equality Tests" );
60  LINFO( testlog, "=====================" );
61 
62  bool_val = true;
63  param_value bool_val_2( false );
64  LINFO( testlog, bool_val << "(bool) == " << bool_val_2 << "(bool) ?: " << bool_val.strict_is_equal_to(bool_val_2) );
65  bool_val_2 = true;
66  LINFO( testlog, bool_val << "(bool) == " << bool_val_2 << "(bool) ?: " << bool_val.strict_is_equal_to(bool_val_2) );
67 
68  string_val = "hello";
69  param_value string_val_2( "hello" );
70  LINFO( testlog, string_val << "(string) == " << string_val_2 << "(string) ?: " << string_val.strict_is_equal_to(string_val_2) );
71  string_val_2 = "world";
72  LINFO( testlog, string_val << "(string) == " << string_val_2 << "(string) ?: " << string_val.strict_is_equal_to(string_val_2) );
73 
74  int_val = 1;
75  LINFO( testlog, bool_val << "(bool) == " << int_val << "(int) ?: " << bool_val.strict_is_equal_to(int_val) );
76  param_value uint_val( 1U );
77  LINFO( testlog, uint_val << "(uint) == " << int_val << "(int) ?: " << uint_val.strict_is_equal_to(int_val) );
78  string_val = "true";
79  LINFO( testlog, bool_val << "(bool) == " << string_val << "(string) ?: " << bool_val.strict_is_equal_to(string_val) );
80 
81  param_value double_val( 1. );
82  param_value double_val_2( 1. );
83  LINFO( testlog, double_val << "(double) == " << double_val_2 << "(double) ?: " << double_val.strict_is_equal_to(double_val_2) );
84  double_val_2 = 2.;
85  LINFO( testlog, double_val << "(double) == " << double_val_2 << "(double) ?: " << double_val.strict_is_equal_to(double_val_2) );
86  LINFO( testlog, double_val << "(double) == " << int_val << "(int) ?: " << double_val.strict_is_equal_to(int_val) );
87 
88 
89  LINFO( testlog, "Loose Equality Tests" );
90  LINFO( testlog, "====================" );
91 
92  bool_val = true;
93  bool_val_2 = false;
94  LINFO( testlog, bool_val << "(bool) == " << bool_val_2 << "(bool) ?: " << bool_val.loose_is_equal_to(bool_val_2) );
95  bool_val_2 = true;
96  LINFO( testlog, bool_val << "(bool) == " << bool_val_2 << "(bool) ?: " << bool_val.loose_is_equal_to(bool_val_2) );
97 
98  string_val = "hello";
99  string_val_2 = "hello";
100  LINFO( testlog, string_val << "(string) == " << string_val_2 << "(string) ?: " << string_val.loose_is_equal_to(string_val_2) );
101  string_val_2 = "world";
102  LINFO( testlog, string_val << "(string) == " << string_val_2 << "(string) ?: " << string_val.loose_is_equal_to(string_val_2) );
103 
104  int_val = 1;
105  LINFO( testlog, bool_val << "(bool) == " << int_val << "(int) ?: " << bool_val.loose_is_equal_to(int_val) );
106  uint_val = 1U;
107  LINFO( testlog, uint_val << "(uint) == " << int_val << "(int) ?: " << uint_val.loose_is_equal_to(int_val) );
108  string_val = "true";
109  LINFO( testlog, bool_val << "(bool) == " << string_val << "(string) ?: " << bool_val.loose_is_equal_to(string_val) );
110 
111  double_val = 1.;
112  double_val_2 = 1.;
113  LINFO( testlog, double_val << "(double) == " << double_val_2 << "(double) ?: " << double_val.loose_is_equal_to(double_val_2) );
114  double_val_2 = 2.;
115  LINFO( testlog, double_val << "(double) == " << double_val_2 << "(double) ?: " << double_val.loose_is_equal_to(double_val_2) );
116  LINFO( testlog, double_val << "(double) == " << int_val << "(int) ?: " << double_val.loose_is_equal_to(int_val) );
117 
118  return 0;
119 }
int64_t as_int() const
Definition: param_value.hh:522
int main()
#define LOGGER(I, K)
Definition: logger.hh:355
bool strict_is_equal_to(const param_value &rhs) const
Definition: param_value.hh:462
Contains the logger class and macros, based on Kasper&#39;s KLogger class.
bool as_bool() const
Definition: param_value.hh:512
#define LINFO(...)
Definition: logger.hh:367
void set(XValType a_value)
Definition: param_value.hh:543
bool loose_is_equal_to(const param_value &rhs) const
Definition: param_value.hh:467