29 #include <gtest/gtest.h>
87 #if (defined(_BIG_ENDIAN)||!defined(_LITTLE_ENDIAN)) && BYTE_ORDER==BIG_ENDIAN
88 EXPECT_EQ(0xefcdab8967452301,
htog((uint64_t)0xefcdab8967452301,
90 EXPECT_EQ(0x1032547698badcfe,
htog((uint64_t)0x1032547698badcfe,
92 EXPECT_EQ(0xb14171b771b01c0b,
htog((uint64_t)0xb14171b771b01c0b,
94 EXPECT_EQ(0xffffffff00000000,
htog((uint64_t)0xffffffff00000000,
96 EXPECT_EQ(0x5555555555555555,
htog((uint64_t)0x5555555555555555,
98 EXPECT_EQ(0xa0a0a0a0a0a0a0a0,
htog((uint64_t)0xa0a0a0a0a0a0a0a0,
100 EXPECT_EQ(0xefcd2301,
htog((uint32_t)0xefcd2301, ByteOrder::big));
101 EXPECT_EQ(0x1032dcfe,
htog((uint32_t)0x1032dcfe, ByteOrder::big));
102 EXPECT_EQ(0xb1411c0b,
htog((uint32_t)0xb1411c0b, ByteOrder::big));
103 EXPECT_EQ(0xffff0000,
htog((uint32_t)0xffff0000, ByteOrder::big));
104 EXPECT_EQ(0x55555555,
htog((uint32_t)0x55555555, ByteOrder::big));
105 EXPECT_EQ(0xa0a0a0a0,
htog((uint32_t)0xa0a0a0a0, ByteOrder::big));
112 EXPECT_EQ(0x0123456789abcdef,
htog((uint64_t)0xefcdab8967452301,
114 EXPECT_EQ(0xfedcba9876543210,
htog((uint64_t)0x1032547698badcfe,
116 EXPECT_EQ(0x0b1cb071b77141b1,
htog((uint64_t)0xb14171b771b01c0b,
118 EXPECT_EQ(0x00000000ffffffff,
htog((uint64_t)0xffffffff00000000,
120 EXPECT_EQ(0x5555555555555555,
htog((uint64_t)0x5555555555555555,
122 EXPECT_EQ(0xa0a0a0a0a0a0a0a0,
htog((uint64_t)0xa0a0a0a0a0a0a0a0,
124 EXPECT_EQ(0x0123cdef,
htog((uint32_t)0xefcd2301, ByteOrder::little));
125 EXPECT_EQ(0xfedc3210,
htog((uint32_t)0x1032dcfe, ByteOrder::little));
126 EXPECT_EQ(0x0b1c41b1,
htog((uint32_t)0xb1411c0b, ByteOrder::little));
127 EXPECT_EQ(0x0000ffff,
htog((uint32_t)0xffff0000, ByteOrder::little));
128 EXPECT_EQ(0x55555555,
htog((uint32_t)0x55555555, ByteOrder::little));
129 EXPECT_EQ(0xa0a0a0a0,
htog((uint32_t)0xa0a0a0a0, ByteOrder::little));
130 EXPECT_EQ(0x01ef,
htog((uint16_t)0xef01, ByteOrder::little));
131 EXPECT_EQ(0xfe10,
htog((uint16_t)0x10fe, ByteOrder::little));
132 EXPECT_EQ(0x0bb1,
htog((uint16_t)0xb10b, ByteOrder::little));
133 EXPECT_EQ(0x00ff,
htog((uint16_t)0xff00, ByteOrder::little));
134 EXPECT_EQ(0x5555,
htog((uint16_t)0x5555, ByteOrder::little));
135 EXPECT_EQ(0xa0a0,
htog((uint16_t)0xa0a0, ByteOrder::little));
136 #elif defined(_LITTLE_ENDIAN) || BYTE_ORDER==LITTLE_ENDIAN
137 EXPECT_EQ(0x0123456789abcdef,
htog((uint64_t)0xefcdab8967452301,
139 EXPECT_EQ(0xfedcba9876543210,
htog((uint64_t)0x1032547698badcfe,
141 EXPECT_EQ(0x0b1cb071b77141b1,
htog((uint64_t)0xb14171b771b01c0b,
143 EXPECT_EQ(0x00000000ffffffff,
htog((uint64_t)0xffffffff00000000,
145 EXPECT_EQ(0x5555555555555555,
htog((uint64_t)0x5555555555555555,
147 EXPECT_EQ(0xa0a0a0a0a0a0a0a0,
htog((uint64_t)0xa0a0a0a0a0a0a0a0,
149 EXPECT_EQ(0x0123cdef,
htog((uint32_t)0xefcd2301, ByteOrder::big));
150 EXPECT_EQ(0xfedc3210,
htog((uint32_t)0x1032dcfe, ByteOrder::big));
151 EXPECT_EQ(0x0b1c41b1,
htog((uint32_t)0xb1411c0b, ByteOrder::big));
152 EXPECT_EQ(0x0000ffff,
htog((uint32_t)0xffff0000, ByteOrder::big));
153 EXPECT_EQ(0x55555555,
htog((uint32_t)0x55555555, ByteOrder::big));
154 EXPECT_EQ(0xa0a0a0a0,
htog((uint32_t)0xa0a0a0a0, ByteOrder::big));
161 EXPECT_EQ(0xefcdab8967452301,
htog((uint64_t)0xefcdab8967452301,
163 EXPECT_EQ(0x1032547698badcfe,
htog((uint64_t)0x1032547698badcfe,
165 EXPECT_EQ(0xb14171b771b01c0b,
htog((uint64_t)0xb14171b771b01c0b,
167 EXPECT_EQ(0xffffffff00000000,
htog((uint64_t)0xffffffff00000000,
169 EXPECT_EQ(0x5555555555555555,
htog((uint64_t)0x5555555555555555,
171 EXPECT_EQ(0xa0a0a0a0a0a0a0a0,
htog((uint64_t)0xa0a0a0a0a0a0a0a0,
173 EXPECT_EQ(0xefcd2301,
htog((uint32_t)0xefcd2301, ByteOrder::little));
174 EXPECT_EQ(0x1032dcfe,
htog((uint32_t)0x1032dcfe, ByteOrder::little));
175 EXPECT_EQ(0xb1411c0b,
htog((uint32_t)0xb1411c0b, ByteOrder::little));
176 EXPECT_EQ(0xffff0000,
htog((uint32_t)0xffff0000, ByteOrder::little));
177 EXPECT_EQ(0x55555555,
htog((uint32_t)0x55555555, ByteOrder::little));
178 EXPECT_EQ(0xa0a0a0a0,
htog((uint32_t)0xa0a0a0a0, ByteOrder::little));
179 EXPECT_EQ(0xef01,
htog((uint16_t)0xef01, ByteOrder::little));
180 EXPECT_EQ(0x10fe,
htog((uint16_t)0x10fe, ByteOrder::little));
181 EXPECT_EQ(0xb10b,
htog((uint16_t)0xb10b, ByteOrder::little));
182 EXPECT_EQ(0xff00,
htog((uint16_t)0xff00, ByteOrder::little));
183 EXPECT_EQ(0x5555,
htog((uint16_t)0x5555, ByteOrder::little));
184 EXPECT_EQ(0xa0a0,
htog((uint16_t)0xa0a0, ByteOrder::little));
186 #error Invalid Endianess
192 #if (defined(_BIG_ENDIAN)||!defined(_LITTLE_ENDIAN)) && BYTE_ORDER==BIG_ENDIAN
193 EXPECT_EQ(0xefcdab8967452301,
gtoh((uint64_t)0xefcdab8967452301,
195 EXPECT_EQ(0x1032547698badcfe,
gtoh((uint64_t)0x1032547698badcfe,
197 EXPECT_EQ(0xb14171b771b01c0b,
gtoh((uint64_t)0xb14171b771b01c0b,
199 EXPECT_EQ(0xffffffff00000000,
gtoh((uint64_t)0xffffffff00000000,
201 EXPECT_EQ(0x5555555555555555,
gtoh((uint64_t)0x5555555555555555,
203 EXPECT_EQ(0xa0a0a0a0a0a0a0a0,
gtoh((uint64_t)0xa0a0a0a0a0a0a0a0,
205 EXPECT_EQ(0xefcd2301,
gtoh((uint32_t)0xefcd2301, ByteOrder::big));
206 EXPECT_EQ(0x1032dcfe,
gtoh((uint32_t)0x1032dcfe, ByteOrder::big));
207 EXPECT_EQ(0xb1411c0b,
gtoh((uint32_t)0xb1411c0b, ByteOrder::big));
208 EXPECT_EQ(0xffff0000,
gtoh((uint32_t)0xffff0000, ByteOrder::big));
209 EXPECT_EQ(0x55555555,
gtoh((uint32_t)0x55555555, ByteOrder::big));
210 EXPECT_EQ(0xa0a0a0a0,
gtoh((uint32_t)0xa0a0a0a0, ByteOrder::big));
217 EXPECT_EQ(0x0123456789abcdef,
gtoh((uint64_t)0xefcdab8967452301,
219 EXPECT_EQ(0xfedcba9876543210,
gtoh((uint64_t)0x1032547698badcfe,
221 EXPECT_EQ(0x0b1cb071b77141b1,
gtoh((uint64_t)0xb14171b771b01c0b,
223 EXPECT_EQ(0x00000000ffffffff,
gtoh((uint64_t)0xffffffff00000000,
225 EXPECT_EQ(0x5555555555555555,
gtoh((uint64_t)0x5555555555555555,
227 EXPECT_EQ(0xa0a0a0a0a0a0a0a0,
gtoh((uint64_t)0xa0a0a0a0a0a0a0a0,
229 EXPECT_EQ(0x0123cdef,
gtoh((uint32_t)0xefcd2301, ByteOrder::little));
230 EXPECT_EQ(0xfedc3210,
gtoh((uint32_t)0x1032dcfe, ByteOrder::little));
231 EXPECT_EQ(0x0b1c41b1,
gtoh((uint32_t)0xb1411c0b, ByteOrder::little));
232 EXPECT_EQ(0x0000ffff,
gtoh((uint32_t)0xffff0000, ByteOrder::little));
233 EXPECT_EQ(0x55555555,
gtoh((uint32_t)0x55555555, ByteOrder::little));
234 EXPECT_EQ(0xa0a0a0a0,
gtoh((uint32_t)0xa0a0a0a0, ByteOrder::little));
235 EXPECT_EQ(0x01ef,
gtoh((uint16_t)0xef01, ByteOrder::little));
236 EXPECT_EQ(0xfe10,
gtoh((uint16_t)0x10fe, ByteOrder::little));
237 EXPECT_EQ(0x0bb1,
gtoh((uint16_t)0xb10b, ByteOrder::little));
238 EXPECT_EQ(0x00ff,
gtoh((uint16_t)0xff00, ByteOrder::little));
239 EXPECT_EQ(0x5555,
gtoh((uint16_t)0x5555, ByteOrder::little));
240 EXPECT_EQ(0xa0a0,
gtoh((uint16_t)0xa0a0, ByteOrder::little));
241 #elif defined(_LITTLE_ENDIAN) || BYTE_ORDER==LITTLE_ENDIAN
242 EXPECT_EQ(0x0123456789abcdef,
gtoh((uint64_t)0xefcdab8967452301,
244 EXPECT_EQ(0xfedcba9876543210,
gtoh((uint64_t)0x1032547698badcfe,
246 EXPECT_EQ(0x0b1cb071b77141b1,
gtoh((uint64_t)0xb14171b771b01c0b,
248 EXPECT_EQ(0x00000000ffffffff,
gtoh((uint64_t)0xffffffff00000000,
250 EXPECT_EQ(0x5555555555555555,
gtoh((uint64_t)0x5555555555555555,
252 EXPECT_EQ(0xa0a0a0a0a0a0a0a0,
gtoh((uint64_t)0xa0a0a0a0a0a0a0a0,
254 EXPECT_EQ(0x0123cdef,
gtoh((uint32_t)0xefcd2301, ByteOrder::big));
255 EXPECT_EQ(0xfedc3210,
gtoh((uint32_t)0x1032dcfe, ByteOrder::big));
256 EXPECT_EQ(0x0b1c41b1,
gtoh((uint32_t)0xb1411c0b, ByteOrder::big));
257 EXPECT_EQ(0x0000ffff,
gtoh((uint32_t)0xffff0000, ByteOrder::big));
258 EXPECT_EQ(0x55555555,
gtoh((uint32_t)0x55555555, ByteOrder::big));
259 EXPECT_EQ(0xa0a0a0a0,
gtoh((uint32_t)0xa0a0a0a0, ByteOrder::big));
266 EXPECT_EQ(0xefcdab8967452301,
gtoh((uint64_t)0xefcdab8967452301,
268 EXPECT_EQ(0x1032547698badcfe,
gtoh((uint64_t)0x1032547698badcfe,
270 EXPECT_EQ(0xb14171b771b01c0b,
gtoh((uint64_t)0xb14171b771b01c0b,
272 EXPECT_EQ(0xffffffff00000000,
gtoh((uint64_t)0xffffffff00000000,
274 EXPECT_EQ(0x5555555555555555,
gtoh((uint64_t)0x5555555555555555,
276 EXPECT_EQ(0xa0a0a0a0a0a0a0a0,
gtoh((uint64_t)0xa0a0a0a0a0a0a0a0,
278 EXPECT_EQ(0xefcd2301,
gtoh((uint32_t)0xefcd2301, ByteOrder::little));
279 EXPECT_EQ(0x1032dcfe,
gtoh((uint32_t)0x1032dcfe, ByteOrder::little));
280 EXPECT_EQ(0xb1411c0b,
gtoh((uint32_t)0xb1411c0b, ByteOrder::little));
281 EXPECT_EQ(0xffff0000,
gtoh((uint32_t)0xffff0000, ByteOrder::little));
282 EXPECT_EQ(0x55555555,
gtoh((uint32_t)0x55555555, ByteOrder::little));
283 EXPECT_EQ(0xa0a0a0a0,
gtoh((uint32_t)0xa0a0a0a0, ByteOrder::little));
284 EXPECT_EQ(0xef01,
gtoh((uint16_t)0xef01, ByteOrder::little));
285 EXPECT_EQ(0x10fe,
gtoh((uint16_t)0x10fe, ByteOrder::little));
286 EXPECT_EQ(0xb10b,
gtoh((uint16_t)0xb10b, ByteOrder::little));
287 EXPECT_EQ(0xff00,
gtoh((uint16_t)0xff00, ByteOrder::little));
288 EXPECT_EQ(0x5555,
gtoh((uint16_t)0x5555, ByteOrder::little));
289 EXPECT_EQ(0xa0a0,
gtoh((uint16_t)0xa0a0, ByteOrder::little));
291 #error Invalid Endianess