Endian: get tests working on more compilers, eliminate compiler warnings

git-svn-id: http://svn.boost.org/svn/boost/sandbox/endian@51866 b8fc166d-592f-0410-95f2-cb63ce0dd405
This commit is contained in:
bemandawes
2009-03-20 13:40:24 +00:00
parent 40fa3beec4
commit 22ccd7a2e4
6 changed files with 107 additions and 70 deletions

View File

@@ -10,11 +10,15 @@
#ifndef BOOST_BINARY_STREAM_HPP #ifndef BOOST_BINARY_STREAM_HPP
#define BOOST_BINARY_STREAM_HPP #define BOOST_BINARY_STREAM_HPP
#include <boost/config.hpp>
#include <ostream> #include <ostream>
#include <istream> #include <istream>
#include <string> #include <string>
#include <cstring> // for strlen #include <cstring> // for strlen
#include <cwchar> // for wcslen
#ifndef BOOST_NO_CWCHAR
# include <cwchar> // for wcslen
#endif
// unformatted binary (as opposed to formatted character-set) input and output // unformatted binary (as opposed to formatted character-set) input and output
@@ -127,8 +131,10 @@ namespace boost
inline std::ostream& operator<=(std::ostream& os, const unsigned char* p) inline std::ostream& operator<=(std::ostream& os, const unsigned char* p)
{ return os.write( reinterpret_cast<const char*>(p), std::strlen(reinterpret_cast<const char*>(p))+1 ); } { return os.write( reinterpret_cast<const char*>(p), std::strlen(reinterpret_cast<const char*>(p))+1 ); }
#ifndef BOOST_NO_CWCHAR
inline std::ostream& operator<=(std::ostream& os, const wchar_t* p) inline std::ostream& operator<=(std::ostream& os, const wchar_t* p)
{ return os.write( reinterpret_cast<const char*>(p), (std::wcslen(p)+1)*sizeof(wchar_t) ); } { return os.write( reinterpret_cast<const char*>(p), (std::wcslen(p)+1)*sizeof(wchar_t) ); }
#endif
// Caution: note the asymmetry between output and input; a string with embedded // Caution: note the asymmetry between output and input; a string with embedded
// nulls will be output with the embedded nulls, but input will stop at the first null. // nulls will be output with the embedded nulls, but input will stop at the first null.
@@ -138,9 +144,11 @@ namespace boost
inline std::istream& operator>=(std::istream& is, std::string& s) inline std::istream& operator>=(std::istream& is, std::string& s)
{ return getline(is, s, '\0'); } { return getline(is, s, '\0'); }
#ifndef BOOST_NO_STD_WSTRING
inline std::ostream& operator<=(std::ostream& os, const std::wstring& s) inline std::ostream& operator<=(std::ostream& os, const std::wstring& s)
{ return os.write( reinterpret_cast<const char*>(s.c_str()), (s.size()+1)*sizeof(wchar_t) ); } { return os.write( reinterpret_cast<const char*>(s.c_str()), (s.size()+1)*sizeof(wchar_t) ); }
// TODO: provide input function // TODO: provide input function
#endif
} // namespace boost } // namespace boost

View File

@@ -65,16 +65,16 @@ namespace boost
friend T& operator<<=(T& x, IntegerType y) { return x = +x << y; } friend T& operator<<=(T& x, IntegerType y) { return x = +x << y; }
friend T& operator>>=(T& x, IntegerType y) { return x = +x >> y; } friend T& operator>>=(T& x, IntegerType y) { return x = +x >> y; }
// A few binary arithmetic operations not covered by operators base class.
friend IntegerType operator<<(const T& x, IntegerType y) { return +x << y; }
friend IntegerType operator>>(const T& x, IntegerType y) { return +x >> y; }
// Auto-increment and auto-decrement can be defined in terms of the // Auto-increment and auto-decrement can be defined in terms of the
// arithmetic operations. // arithmetic operations.
friend T& operator++(T& x) { return x += 1; } friend T& operator++(T& x) { return x += 1; }
friend T& operator--(T& x) { return x -= 1; } friend T& operator--(T& x) { return x -= 1; }
# ifndef BOOST_MINIMAL_INTEGER_COVER_OPERATORS # ifdef BOOST_MINIMAL_INTEGER_COVER_OPERATORS
// A few binary arithmetic operations not covered by operators base class.
friend IntegerType operator<<(const T& x, IntegerType y) { return +x << y; }
friend IntegerType operator>>(const T& x, IntegerType y) { return +x >> y; }
friend T operator++(T& x, int) friend T operator++(T& x, int)
{ {
T tmp(x); T tmp(x);

View File

@@ -21,6 +21,14 @@
#ifndef BOOST_ENDIAN_HPP #ifndef BOOST_ENDIAN_HPP
#define BOOST_ENDIAN_HPP #define BOOST_ENDIAN_HPP
#ifdef BOOST_ENDIAN_LOG
# include <iostream>
#endif
#if defined(__BORLANDC__) || defined( __CODEGEARC__)
# pragma pack(push, 1)
#endif
#include <boost/config.hpp> #include <boost/config.hpp>
#include <boost/detail/endian.hpp> #include <boost/detail/endian.hpp>
#define BOOST_MINIMAL_INTEGER_COVER_OPERATORS #define BOOST_MINIMAL_INTEGER_COVER_OPERATORS
@@ -411,4 +419,8 @@ namespace boost
} // namespace integer } // namespace integer
} // namespace boost } // namespace boost
#if defined(__BORLANDC__) || defined( __CODEGEARC__)
# pragma pack(pop)
#endif
#endif // BOOST_ENDIAN_HPP #endif // BOOST_ENDIAN_HPP

View File

@@ -14,7 +14,8 @@
[ run binary_stream_test.cpp ] [ run binary_stream_test.cpp ]
[ run endian_binary_stream_test.cpp ] [ run endian_binary_stream_test.cpp ]
[ run endian_test.cpp ] [ run endian_test.cpp ]
[ run endian_operations_test.cpp ] [ run endian_operations_test.cpp
: : : <toolset>gcc:<cxxflags>-Wno-sign-compare ]
[ run endian_in_union_test.cpp ] [ run endian_in_union_test.cpp ]
[ run scoped_enum_emulation_test.cpp ] [ run scoped_enum_emulation_test.cpp ]
; ;

View File

@@ -46,6 +46,7 @@ struct construct
{ {
T2 o2(1); T2 o2(1);
T1 o1(o2); T1 o1(o2);
++o1; // quiet gcc unused variable warning
} }
}; };
@@ -56,6 +57,7 @@ struct initialize
{ {
T1 o2(2); T1 o2(2);
T1 o1 = o2; T1 o1 = o2;
++o1; // quiet gcc unused variable warning
} }
}; };
@@ -122,6 +124,12 @@ struct op_star
template <template<class, class> class Test, class T1> template <template<class, class> class Test, class T1>
void op_test_aux() void op_test_aux()
{ {
#ifdef BOOST_SHORT_ENDIAN_TEST
Test<T1, int>::test();
Test<T1, unsigned int>::test();
Test<T1, bi::big16_t>::test();
Test<T1, bi::ubig64_t>::test();
#else
Test<T1, char>::test(); Test<T1, char>::test();
Test<T1, unsigned char>::test(); Test<T1, unsigned char>::test();
Test<T1, signed char>::test(); Test<T1, signed char>::test();
@@ -181,12 +189,19 @@ void op_test_aux()
Test<T1, bi::unative48_t>::test(); Test<T1, bi::unative48_t>::test();
Test<T1, bi::unative56_t>::test(); Test<T1, bi::unative56_t>::test();
Test<T1, bi::unative64_t>::test(); Test<T1, bi::unative64_t>::test();
#endif
} }
template <template<class, class> class Test> template <template<class, class> class Test>
void op_test() void op_test()
{ {
#ifdef BOOST_SHORT_ENDIAN_TEST
op_test_aux<Test, unsigned short>();
op_test_aux<Test, int>();
op_test_aux<Test, bi::big32_t>();
op_test_aux<Test, bi::ubig32_t>();
op_test_aux<Test, bi::little48_t>();
#else
op_test_aux<Test, char>(); op_test_aux<Test, char>();
op_test_aux<Test, unsigned char>(); op_test_aux<Test, unsigned char>();
op_test_aux<Test, signed char>(); op_test_aux<Test, signed char>();
@@ -246,6 +261,7 @@ void op_test()
op_test_aux<Test, bi::unative48_t>(); op_test_aux<Test, bi::unative48_t>();
op_test_aux<Test, bi::unative56_t>(); op_test_aux<Test, bi::unative56_t>();
op_test_aux<Test, bi::unative64_t>(); op_test_aux<Test, bi::unative64_t>();
#endif
} }
int main() int main()
@@ -280,7 +296,7 @@ int main()
++big; ++big;
std::clog << "\nresult = big++\n"; std::clog << "\nresult = big++\n";
big++; result = big++;
std::clog << "\n--big\n"; std::clog << "\n--big\n";
--big; --big;

View File

@@ -53,7 +53,7 @@ namespace
{ {
if ( actual == expected ) return; if ( actual == expected ) return;
++err_count; ++err_count;
cout << "Error: verify failed on line " << line << endl; cout << "Error: verify size failed on line " << line << endl;
cout << " A structure with an expected sizeof() " << expected cout << " A structure with an expected sizeof() " << expected
<< " had an actual sizeof() " << actual << " had an actual sizeof() " << actual
<< "\n This will cause common uses of <boost/endian.hpp> to fail\n"; << "\n This will cause common uses of <boost/endian.hpp> to fail\n";
@@ -149,75 +149,75 @@ namespace
VERIFY( numeric_limits<signed char>::digits == 7 ); VERIFY( numeric_limits<signed char>::digits == 7 );
VERIFY( numeric_limits<unsigned char>::digits == 8 ); VERIFY( numeric_limits<unsigned char>::digits == 8 );
VERIFY( sizeof( big8_t ) == 1 ); VERIFY_SIZE( sizeof( big8_t ), 1 );
VERIFY( sizeof( big16_t ) == 2 ); VERIFY_SIZE( sizeof( big16_t ), 2 );
VERIFY( sizeof( big24_t ) == 3 ); VERIFY_SIZE( sizeof( big24_t ), 3 );
VERIFY( sizeof( big32_t ) == 4 ); VERIFY_SIZE( sizeof( big32_t ), 4 );
VERIFY( sizeof( big40_t ) == 5 ); VERIFY_SIZE( sizeof( big40_t ), 5 );
VERIFY( sizeof( big48_t ) == 6 ); VERIFY_SIZE( sizeof( big48_t ), 6 );
VERIFY( sizeof( big56_t ) == 7 ); VERIFY_SIZE( sizeof( big56_t ), 7 );
VERIFY( sizeof( big64_t ) == 8 ); VERIFY_SIZE( sizeof( big64_t ), 8 );
VERIFY( sizeof( ubig8_t ) == 1 ); VERIFY_SIZE( sizeof( ubig8_t ), 1 );
VERIFY( sizeof( ubig16_t ) == 2 ); VERIFY_SIZE( sizeof( ubig16_t ), 2 );
VERIFY( sizeof( ubig24_t ) == 3 ); VERIFY_SIZE( sizeof( ubig24_t ), 3 );
VERIFY( sizeof( ubig32_t ) == 4 ); VERIFY_SIZE( sizeof( ubig32_t ), 4 );
VERIFY( sizeof( ubig40_t ) == 5 ); VERIFY_SIZE( sizeof( ubig40_t ), 5 );
VERIFY( sizeof( ubig48_t ) == 6 ); VERIFY_SIZE( sizeof( ubig48_t ), 6 );
VERIFY( sizeof( ubig56_t ) == 7 ); VERIFY_SIZE( sizeof( ubig56_t ), 7 );
VERIFY( sizeof( ubig64_t ) == 8 ); VERIFY_SIZE( sizeof( ubig64_t ), 8 );
VERIFY( sizeof( little8_t ) == 1 ); VERIFY_SIZE( sizeof( little8_t ), 1 );
VERIFY( sizeof( little16_t ) == 2 ); VERIFY_SIZE( sizeof( little16_t ), 2 );
VERIFY( sizeof( little24_t ) == 3 ); VERIFY_SIZE( sizeof( little24_t ), 3 );
VERIFY( sizeof( little32_t ) == 4 ); VERIFY_SIZE( sizeof( little32_t ), 4 );
VERIFY( sizeof( little40_t ) == 5 ); VERIFY_SIZE( sizeof( little40_t ), 5 );
VERIFY( sizeof( little48_t ) == 6 ); VERIFY_SIZE( sizeof( little48_t ), 6 );
VERIFY( sizeof( little56_t ) == 7 ); VERIFY_SIZE( sizeof( little56_t ), 7 );
VERIFY( sizeof( little64_t ) == 8 ); VERIFY_SIZE( sizeof( little64_t ), 8 );
VERIFY( sizeof( ulittle8_t ) == 1 ); VERIFY_SIZE( sizeof( ulittle8_t ), 1 );
VERIFY( sizeof( ulittle16_t ) == 2 ); VERIFY_SIZE( sizeof( ulittle16_t ), 2 );
VERIFY( sizeof( ulittle24_t ) == 3 ); VERIFY_SIZE( sizeof( ulittle24_t ), 3 );
VERIFY( sizeof( ulittle32_t ) == 4 ); VERIFY_SIZE( sizeof( ulittle32_t ), 4 );
VERIFY( sizeof( ulittle40_t ) == 5 ); VERIFY_SIZE( sizeof( ulittle40_t ), 5 );
VERIFY( sizeof( ulittle48_t ) == 6 ); VERIFY_SIZE( sizeof( ulittle48_t ), 6 );
VERIFY( sizeof( ulittle56_t ) == 7 ); VERIFY_SIZE( sizeof( ulittle56_t ), 7 );
VERIFY( sizeof( ulittle64_t ) == 8 ); VERIFY_SIZE( sizeof( ulittle64_t ), 8 );
VERIFY( sizeof( native8_t ) == 1 ); VERIFY_SIZE( sizeof( native8_t ), 1 );
VERIFY( sizeof( native16_t ) == 2 ); VERIFY_SIZE( sizeof( native16_t ), 2 );
VERIFY( sizeof( native24_t ) == 3 ); VERIFY_SIZE( sizeof( native24_t ), 3 );
VERIFY( sizeof( native32_t ) == 4 ); VERIFY_SIZE( sizeof( native32_t ), 4 );
VERIFY( sizeof( native40_t ) == 5 ); VERIFY_SIZE( sizeof( native40_t ), 5 );
VERIFY( sizeof( native48_t ) == 6 ); VERIFY_SIZE( sizeof( native48_t ), 6 );
VERIFY( sizeof( native56_t ) == 7 ); VERIFY_SIZE( sizeof( native56_t ), 7 );
VERIFY( sizeof( native64_t ) == 8 ); VERIFY_SIZE( sizeof( native64_t ), 8 );
VERIFY( sizeof( unative8_t ) == 1 ); VERIFY_SIZE( sizeof( unative8_t ), 1 );
VERIFY( sizeof( unative16_t ) == 2 ); VERIFY_SIZE( sizeof( unative16_t ), 2 );
VERIFY( sizeof( unative24_t ) == 3 ); VERIFY_SIZE( sizeof( unative24_t ), 3 );
VERIFY( sizeof( unative32_t ) == 4 ); VERIFY_SIZE( sizeof( unative32_t ), 4 );
VERIFY( sizeof( unative40_t ) == 5 ); VERIFY_SIZE( sizeof( unative40_t ), 5 );
VERIFY( sizeof( unative48_t ) == 6 ); VERIFY_SIZE( sizeof( unative48_t ), 6 );
VERIFY( sizeof( unative56_t ) == 7 ); VERIFY_SIZE( sizeof( unative56_t ), 7 );
VERIFY( sizeof( unative64_t ) == 8 ); VERIFY_SIZE( sizeof( unative64_t ), 8 );
VERIFY( sizeof( aligned_big16_t ) == 2 ); VERIFY_SIZE( sizeof( aligned_big16_t ), 2 );
VERIFY( sizeof( aligned_big32_t ) == 4 ); VERIFY_SIZE( sizeof( aligned_big32_t ), 4 );
VERIFY( sizeof( aligned_big64_t ) == 8 ); VERIFY_SIZE( sizeof( aligned_big64_t ), 8 );
VERIFY( sizeof( aligned_ubig16_t ) == 2 ); VERIFY_SIZE( sizeof( aligned_ubig16_t ), 2 );
VERIFY( sizeof( aligned_ubig32_t ) == 4 ); VERIFY_SIZE( sizeof( aligned_ubig32_t ), 4 );
VERIFY( sizeof( aligned_ubig64_t ) == 8 ); VERIFY_SIZE( sizeof( aligned_ubig64_t ), 8 );
VERIFY( sizeof( aligned_little16_t ) == 2 ); VERIFY_SIZE( sizeof( aligned_little16_t ), 2 );
VERIFY( sizeof( aligned_little32_t ) == 4 ); VERIFY_SIZE( sizeof( aligned_little32_t ), 4 );
VERIFY( sizeof( aligned_little64_t ) == 8 ); VERIFY_SIZE( sizeof( aligned_little64_t ), 8 );
VERIFY( sizeof( aligned_ulittle16_t ) == 2 ); VERIFY_SIZE( sizeof( aligned_ulittle16_t ), 2 );
VERIFY( sizeof( aligned_ulittle32_t ) == 4 ); VERIFY_SIZE( sizeof( aligned_ulittle32_t ), 4 );
VERIFY( sizeof( aligned_ulittle64_t ) == 8 ); VERIFY_SIZE( sizeof( aligned_ulittle64_t ), 8 );
} // check_size } // check_size
// check_alignment -------------------------------------------------------// // check_alignment -------------------------------------------------------//