annotate packages/language/cxx/ustl/current/tests/bvt21.cpp @ 3152:4885e0722884

* include/*: * src/*: * tests/*: * HISTORY: * LICENSE: Updated to uSTL 1.6 sources.
author sergeig
date Wed, 04 Apr 2012 18:51:57 +0000
parents 4d0db334c7fc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2904
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
1 // This file is part of the uSTL library, an STL implementation.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
2 //
3152
4885e0722884 * include/*:
sergeig
parents: 2961
diff changeset
3 // Copyright (c) 2005 by Mike Sharov <msharov@users.sourceforge.net>
2904
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
4 // This file is free software, distributed under the MIT License.
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
5
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
6 #include "stdtest.h"
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
7
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
8 template <typename T>
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
9 void TestBswap (T v)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
10 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
11 const T vsw (bswap(v));
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
12 #if BYTE_ORDER == LITTLE_ENDIAN
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
13 const T vbe (vsw), vle (v);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
14 #elif BYTE_ORDER == BIG_ENDIAN
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
15 const T vbe (v), vle (vsw);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
16 #endif
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
17 static const char ok[2][4] = { "bad", "ok" };
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
18 cout << "bswap(" << v << ") = " << vsw << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
19 cout << "le_to_native(" << v << ") = " << ok[le_to_native(vle) == v] << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
20 cout << "native_to_le(" << v << ") = " << ok[native_to_le(v) == vle] << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
21 cout << "be_to_native(" << v << ") = " << ok[be_to_native(vbe) == v] << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
22 cout << "native_to_be(" << v << ") = " << ok[native_to_be(v) == vbe] << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
23 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
24
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
25 void TestUtility (void)
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
26 {
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
27 cout << "DivRU(13,5) = " << DivRU(13,5) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
28 cout << "DivRU(15,5) = " << DivRU(15,5) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
29 cout << "DivRU(-12,5) = " << DivRU(-12,5) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
30 cout << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
31 cout << "Align(5) = " << Align(5) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
32 cout << "Align(5,2) = " << Align(5,2) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
33 cout << "Align(17,7) = " << Align(17,7) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
34 cout << "Align(14,7) = " << Align(14,7) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
35 cout << endl;
2961
4d0db334c7fc * include/*, tests/*, HISTORY, LICENSE: Update to uSTL 1.4 sources.
jld
parents: 2904
diff changeset
36 cout << "NextPow2(0) = " << NextPow2(0) << endl;
4d0db334c7fc * include/*, tests/*, HISTORY, LICENSE: Update to uSTL 1.4 sources.
jld
parents: 2904
diff changeset
37 cout << "NextPow2(1) = " << NextPow2(1) << endl;
4d0db334c7fc * include/*, tests/*, HISTORY, LICENSE: Update to uSTL 1.4 sources.
jld
parents: 2904
diff changeset
38 cout << "NextPow2(4) = " << NextPow2(4) << endl;
4d0db334c7fc * include/*, tests/*, HISTORY, LICENSE: Update to uSTL 1.4 sources.
jld
parents: 2904
diff changeset
39 cout << "NextPow2(3827) = " << NextPow2(3827) << endl;
4d0db334c7fc * include/*, tests/*, HISTORY, LICENSE: Update to uSTL 1.4 sources.
jld
parents: 2904
diff changeset
40 cout << "NextPow2(0xFFFFFFF0) = " << NextPow2(0xFFFFFFF0) << endl;
4d0db334c7fc * include/*, tests/*, HISTORY, LICENSE: Update to uSTL 1.4 sources.
jld
parents: 2904
diff changeset
41 cout << endl;
2904
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
42 cout << "advance(42,0) = " << advance(42,0) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
43 cout << "advance(42,3) = " << advance(42,3) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
44 const void *cvp = (const void*) 0x1234;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
45 void* vp = (void*) 0x4321;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
46 cout << ios::hex;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
47 cout << "cvp = " << cvp << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
48 cout << "vp = " << vp << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
49 cout << "advance(cvp,5) = " << advance(cvp,5) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
50 cout << "advance(vp,4) = " << advance(vp,4) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
51 cout << "distance(cvp,vp) = " << distance(cvp,vp) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
52 cout << "abs_distance(vp,cvp) = " << abs_distance(vp,cvp) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
53 cout << ios::dec << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
54 const int32_t c_Numbers[] = { 1, 2, 3, 4, 5 };
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
55 const int32_t c_Empty[] = { };
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
56 cout << "size_of_elements(3, c_Numbers) = " << size_of_elements(3, c_Numbers) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
57 cout << "VectorSize(c_Numbers[5]) = " << VectorSize(c_Numbers) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
58 cout << "VectorSize(c_Numbers[0]) = " << VectorSize(c_Empty) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
59 cout << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
60 cout << "BitsInType(uint32_t) = " << BitsInType(uint32_t) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
61 cout << "BitsInType(int16_t) = " << BitsInType(int16_t) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
62 cout << "BitsInType(char) = " << BitsInType(char) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
63 cout << ios::hex << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
64 cout << "BitMask(uint32_t,12) = " << BitMask(uint32_t,12) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
65 cout << "BitMask(uint16_t,1) = " << BitMask(uint16_t,1) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
66 cout << "BitMask(uint8_t,8) = " << BitMask(uint8_t,8) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
67 cout << "BitMask(uint16_t,0) = " << BitMask(uint16_t,0) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
68 cout << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
69 uint16_t packed16 = 0xCDCD;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
70 pack_type (uint8_t(0x42), packed16);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
71 cout << "pack_type(uint8_t, uint16_t) = " << packed16 << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
72 uint32_t packed32 = 0xCDCDCDCD;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
73 pack_type (uint8_t(0x42), packed32);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
74 cout << "pack_type(uint8_t, uint32_t) = " << packed32 << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
75 packed32 = 0xCDCDCDCD;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
76 pack_type (uint16_t(0x4243), packed32);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
77 cout << "pack_type(uint16_t, uint32_t) = " << packed32 << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
78 #if HAVE_INT64_T
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
79 uint64_t packed64 = UINT64_C(0x123456789ABCDEF0);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
80 pack_type (uint8_t(0x42), packed64);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
81 cout << "pack_type(uint8_t, uint64_t) = " << packed64 << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
82 packed64 = UINT64_C(0x123456789ABCDEF0);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
83 pack_type (uint32_t(0x42434445), packed64);
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
84 cout << "pack_type(uint32_t, uint64_t) = " << packed64 << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
85 #else
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
86 cout << "No 64bit types available on this platform" << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
87 #endif
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
88 cout << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
89 TestBswap (uint16_t (0x1234));
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
90 TestBswap (uint32_t (0x12345678));
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
91 #if HAVE_INT64_T
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
92 TestBswap (uint64_t (UINT64_C(0x123456789ABCDEF0)));
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
93 #else
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
94 cout << "No 64bit types available on this platform" << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
95 #endif
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
96 cout << ios::dec << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
97 cout << "absv(12) = " << absv(12) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
98 cout << "absv(-12) = " << absv(-12) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
99 cout << "sign(12) = " << sign(12) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
100 cout << "sign(-12) = " << sign(-12) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
101 cout << "sign(0) = " << sign(0) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
102 cout << "min(3,4) = " << min(3,4) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
103 cout << "min(6U,1U) = " << min(6U,1U) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
104 cout << "max(-3,-6) = " << max(-3,-6) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
105 cout << "max(-3L,6L) = " << max(-3L,6L) << endl;
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
106 }
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
107
88af52c64ce4 * ecos.db: Add uSTL library package record.
jld
parents:
diff changeset
108 StdBvtMain (TestUtility)