Build system improvements
[ustl.git] / bvt / bvt21.cc
blob795af399e10efd40be5876cd23b9768f2ffdb1f0
1 // This file is part of the ustl library, an STL implementation.
2 //
3 // Copyright (C) 2005 by Mike Sharov <msharov@users.sourceforge.net>
4 // This file is free software, distributed under the MIT License.
5 //
7 // Tests functions from uutility.h
8 //
10 #include "stdtest.h"
12 template <typename T>
13 void TestBswap (T v)
15 const T vsw (bswap(v));
16 #if BYTE_ORDER == LITTLE_ENDIAN
17 const T vbe (vsw), vle (v);
18 #elif BYTE_ORDER == BIG_ENDIAN
19 const T vbe (v), vle (vsw);
20 #endif
21 static const char ok[2][4] = { "bad", "ok" };
22 cout << "bswap(" << v << ") = " << vsw << endl;
23 cout << "le_to_native(" << v << ") = " << ok[le_to_native(vle) == v] << endl;
24 cout << "native_to_le(" << v << ") = " << ok[native_to_le(v) == vle] << endl;
25 cout << "be_to_native(" << v << ") = " << ok[be_to_native(vbe) == v] << endl;
26 cout << "native_to_be(" << v << ") = " << ok[native_to_be(v) == vbe] << endl;
29 void TestUtility (void)
31 cout << "DivRU(13,5) = " << DivRU(13,5) << endl;
32 cout << "DivRU(15,5) = " << DivRU(15,5) << endl;
33 cout << "DivRU(-12,5) = " << DivRU(-12,5) << endl;
34 cout << endl;
35 cout << "Align(5) = " << Align(5) << endl;
36 cout << "Align(5,2) = " << Align(5,2) << endl;
37 cout << "Align(17,7) = " << Align(17,7) << endl;
38 cout << "Align(14,7) = " << Align(14,7) << endl;
39 cout << endl;
40 cout << "advance(42,0) = " << advance(42,0) << endl;
41 cout << "advance(42,3) = " << advance(42,3) << endl;
42 const void *cvp = (const void*) 0x1234;
43 void* vp = (void*) 0x4321;
44 cout << ios::hex;
45 cout << "cvp = " << cvp << endl;
46 cout << "vp = " << vp << endl;
47 cout << "advance(cvp,5) = " << advance(cvp,5) << endl;
48 cout << "advance(vp,4) = " << advance(vp,4) << endl;
49 cout << "distance(cvp,vp) = " << distance(cvp,vp) << endl;
50 cout << "abs_distance(vp,cvp) = " << abs_distance(vp,cvp) << endl;
51 cout << ios::dec << endl;
52 const int32_t c_Numbers[] = { 1, 2, 3, 4, 5 };
53 const int32_t c_Empty[] = { };
54 cout << "size_of_elements(3, c_Numbers) = " << size_of_elements(3, c_Numbers) << endl;
55 cout << "VectorSize(c_Numbers[5]) = " << VectorSize(c_Numbers) << endl;
56 cout << "VectorSize(c_Numbers[0]) = " << VectorSize(c_Empty) << endl;
57 cout << endl;
58 cout << "BitsInType(uint32_t) = " << BitsInType(uint32_t) << endl;
59 cout << "BitsInType(int16_t) = " << BitsInType(int16_t) << endl;
60 cout << "BitsInType(char) = " << BitsInType(char) << endl;
61 cout << ios::hex << endl;
62 cout << "BitMask(uint32_t,12) = " << BitMask(uint32_t,12) << endl;
63 cout << "BitMask(uint16_t,1) = " << BitMask(uint16_t,1) << endl;
64 cout << "BitMask(uint8_t,8) = " << BitMask(uint8_t,8) << endl;
65 cout << "BitMask(uint16_t,0) = " << BitMask(uint16_t,0) << endl;
66 cout << endl;
67 uint16_t packed16 = 0xCDCD;
68 pack_type (uint8_t(0x42), packed16);
69 cout << "pack_type(uint8_t, uint16_t) = " << packed16 << endl;
70 uint32_t packed32 = 0xCDCDCDCD;
71 pack_type (uint8_t(0x42), packed32);
72 cout << "pack_type(uint8_t, uint32_t) = " << packed32 << endl;
73 packed32 = 0xCDCDCDCD;
74 pack_type (uint16_t(0x4243), packed32);
75 cout << "pack_type(uint16_t, uint32_t) = " << packed32 << endl;
76 #if HAVE_INT64_T
77 uint64_t packed64 = UINT64_C(0x123456789ABCDEF0);
78 pack_type (uint8_t(0x42), packed64);
79 cout << "pack_type(uint8_t, uint64_t) = " << packed64 << endl;
80 packed64 = UINT64_C(0x123456789ABCDEF0);
81 pack_type (uint32_t(0x42434445), packed64);
82 cout << "pack_type(uint32_t, uint64_t) = " << packed64 << endl;
83 #else
84 cout << "No 64bit types available on this platform" << endl;
85 #endif
86 cout << endl;
87 TestBswap (uint16_t (0x1234));
88 TestBswap (uint32_t (0x12345678));
89 #ifdef HAVE_INT64_T
90 TestBswap (uint64_t (UINT64_C(0x123456789ABCDEF0)));
91 #else
92 cout << "No 64bit types available on this platform" << endl;
93 #endif
94 cout << ios::dec << endl;
95 cout << "absv(12) = " << absv(12) << endl;
96 cout << "absv(-12) = " << absv(-12) << endl;
97 cout << "sign(12) = " << sign(12) << endl;
98 cout << "sign(-12) = " << sign(-12) << endl;
99 cout << "sign(0) = " << sign(0) << endl;
100 cout << "min(3,4) = " << min(3,4) << endl;
101 cout << "min(6U,1U) = " << min(6U,1U) << endl;
102 cout << "max(-3,-6) = " << max(-3,-6) << endl;
103 cout << "max(-3L,6L) = " << max(-3L,6L) << endl;
106 StdBvtMain (TestUtility)