28#include "../../binary.h"
29#include "../../bitset.h"
31#include "dccl/logger.h"
35int main(
int argc,
char* argv[])
38 for (
int i = 1; i < argc; ++i)
40 if (argv[i] && argv[i][0] ==
'-' && argv[i][1] ==
'v' && argv[i][2] ==
'\0')
44 dccl::dlog.
connect(verbose ? dccl::logger::ALL :
dccl::logger::WARN_PLUS, &std::cerr);
47 unsigned long value = 23;
49 std::string s = bits.to_string();
50 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << bits << std::endl;
51 assert(s == std::string(
"00010111"));
55 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << bits << std::endl;
57 assert(s == std::string(
"01011100"));
60 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << bits << std::endl;
62 assert(s == std::string(
"00101110"));
64 s = (bits << 3).to_string();
65 assert(s == std::string(
"01110000"));
67 s = (bits >> 2).to_string();
68 assert(s == std::string(
"00001011"));
71 unsigned long v1 = 14, v2 = 679;
72 Bitset bits1(15, v1), bits2(15, v2);
74 assert((bits1 & bits2).to_ulong() == (v1 & v2));
75 assert((bits1 | bits2).to_ulong() == (v1 | v2));
76 assert((bits1 ^ bits2).to_ulong() == (v1 ^ v2));
78 assert((bits < bits1) == (value < v1));
79 assert((bits1 < bits2) == (v1 < v2));
80 assert((bits2 < bits1) == (v2 < v1));
82 using namespace std::rel_ops;
84 assert((bits1 > bits2) == (v1 > v2));
85 assert((bits1 >= bits2) == (v1 >= v2));
86 assert((bits1 <= bits2) == (v1 <= v2));
87 assert((bits1 != bits2) == (v1 != v2));
95 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << bits2.size() <<
": " << bits2 << std::endl;
96 assert(bits2.to_ulong() == 0x02a512);
100 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << std::endl;
102 Bitset child(4, 0, &parent);
104 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"parent: " << parent << std::endl;
105 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"child: " << child << std::endl;
107 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"get more bits: 4" << std::endl;
108 child.get_more_bits(4);
110 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"parent: " << parent << std::endl;
111 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"child: " << child << std::endl;
113 assert(child.size() == 8);
114 assert(parent.size() == 4);
116 assert(child.to_ulong() == 0x10);
117 assert(parent.to_ulong() == 0xD);
121 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << std::endl;
122 Bitset grandparent(8, 0xD1);
123 Bitset parent(8, 0x02, &grandparent);
124 Bitset child(4, 0, &parent);
126 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"grandparent: " << grandparent << std::endl;
127 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"parent: " << parent << std::endl;
128 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"child: " << child << std::endl;
130 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"get more bits: 4" << std::endl;
131 child.get_more_bits(4);
133 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"grandparent: " << grandparent << std::endl;
134 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"parent: " << parent << std::endl;
135 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"child: " << child << std::endl;
137 assert(child.size() == 8);
138 assert(parent.size() == 4);
139 assert(grandparent.size() == 8);
141 assert(child.to_ulong() == 0x20);
142 assert(parent.to_ulong() == 0x0);
143 assert(grandparent.to_ulong() == 0xD1);
147 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog << std::endl;
148 Bitset grandparent(8, 0xD1);
149 Bitset parent(&grandparent);
150 Bitset child(4, 0, &parent);
152 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"grandparent: " << grandparent << std::endl;
153 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"parent: " << parent << std::endl;
154 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"child: " << child << std::endl;
156 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"get more bits: 4" << std::endl;
157 child.get_more_bits(4);
159 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"grandparent: " << grandparent << std::endl;
160 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"parent: " << parent << std::endl;
161 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"child: " << child << std::endl;
163 assert(child.size() == 8);
164 assert(parent.size() == 0);
165 assert(grandparent.size() == 4);
167 assert(child.to_ulong() == 0x10);
168 assert(parent.to_ulong() == 0x0);
169 assert(grandparent.to_ulong() == 0xD);
172 dccl::dlog.
is(dccl::logger::INFO) && dccl::dlog <<
"all tests passed" << std::endl;
A variable size container of bits (subclassed from std::deque<bool>) with an optional hierarchy....
bool is(logger::Verbosity verbosity, logger::Group group=logger::GENERAL)
Indicates the verbosity of the Logger until the next std::flush or std::endl. The boolean return is u...
void connect(int verbosity_mask, Slot slot)
Connect the output of one or more given verbosities to a slot (function pointer or similar)
Dynamic Compact Control Language namespace.
void hex_encode(CharIterator begin, CharIterator end, std::string *out, bool upper_case=false)
Encodes a (little-endian) hexadecimal string from a byte string. Index 0 of begin is written to index...
void hex_decode(const std::string &in, std::string *out)
Decodes a (little-endian) hexadecimal string to a byte string. Index 0 and 1 (first byte) of in are w...