Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/integer/integer_traits_test.cpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 17 years ago

added boost

File size: 3.8 KB
Line 
1/* boost integer_traits.hpp tests
2 *
3 * Copyright Jens Maurer 2000
4 * Distributed under the Boost Software License, Version 1.0. (See
5 * accompanying file LICENSE_1_0.txt or copy at
6 * http://www.boost.org/LICENSE_1_0.txt)
7 *
8 * $Id: integer_traits_test.cpp,v 1.15 2005/05/25 13:43:12 joaquintides Exp $
9 *
10 * Revision history
11 *  2000-02-22  Small improvements by Beman Dawes
12 *  2000-06-27  Rework for better MSVC and BCC co-operation
13 */
14
15#include <iostream>
16#include <boost/integer_traits.hpp>
17// use int64_t instead of long long for better portability
18#include <boost/cstdint.hpp>
19
20#define BOOST_INCLUDE_MAIN
21#include <boost/test/test_tools.hpp>
22
23/*
24 * General portability note:
25 * MSVC mis-compiles explicit function template instantiations.
26 * For example, f<A>() and f<B>() are both compiled to call f<A>().
27 * BCC is unable to implicitly convert a "const char *" to a std::string
28 * when using explicit function template instantiations.
29 *
30 * Therefore, avoid explicit function template instantiations.
31 */
32
33#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
34template<typename T> inline T make_char_numeric_for_streaming(T x) { return x; }
35namespace fix{
36inline int make_char_numeric_for_streaming(char c) { return c; }
37inline int make_char_numeric_for_streaming(signed char c) { return c; }
38inline int make_char_numeric_for_streaming(unsigned char c) { return c; }
39}
40using namespace fix;
41#else
42template<typename T> inline T make_char_numeric_for_streaming(T x) { return x; }
43inline int make_char_numeric_for_streaming(char c) { return c; }
44inline int make_char_numeric_for_streaming(signed char c) { return c; }
45inline int make_char_numeric_for_streaming(unsigned char c) { return c; }
46#endif
47
48template<class T>
49void runtest(const char * type, T)
50{
51  typedef boost::integer_traits<T> traits;
52  std::cout << "Checking " << type
53            << "; min is " << make_char_numeric_for_streaming((traits::min)())
54            << ", max is " << make_char_numeric_for_streaming((traits::max)())
55            << std::endl;
56  BOOST_CHECK(traits::is_specialized);
57#if defined(BOOST_MSVC) && (BOOST_MSVC <= 1200)
58  // MSVC++ 6.0 issues a LNK1179 error (duplicate comdat) when the compiler
59  // generates different symbol names with a very long common prefix:
60  // the dummy "&& true" disambiguates between the symbols generated by this
61  // BOOST_CHECK instantiation and the preceding one.
62  BOOST_CHECK(traits::is_integer && true);
63#else
64  BOOST_CHECK(traits::is_integer);
65#endif
66  BOOST_CHECK(traits::is_integral == true);
67  BOOST_CHECK(traits::const_min == (traits::min)());
68  BOOST_CHECK(traits::const_max == (traits::max)());
69}
70
71int test_main(int, char*[])
72{
73  runtest("bool", bool());
74  runtest("char", char());
75  typedef signed char signed_char;
76  runtest("signed char", signed_char());
77  typedef unsigned char unsigned_char;
78  runtest("unsigned char", unsigned_char());
79  runtest("wchar_t", wchar_t());
80  runtest("short", short());
81  typedef unsigned short unsigned_short;
82  runtest("unsigned short", unsigned_short());
83  runtest("int", int());
84  typedef unsigned int unsigned_int;
85  runtest("unsigned int", unsigned_int());
86  runtest("long", long());
87  typedef unsigned long unsigned_long;
88  runtest("unsigned long", unsigned_long());
89#if !defined(BOOST_NO_INT64_T) && (!defined(BOOST_MSVC) || BOOST_MSVC > 1300) && !defined(__BORLANDC__) && !defined(__BEOS__)
90  //
91  // MS/Borland compilers can't support 64-bit member constants
92  // BeOS doesn't have specialisations for long long in SGI's <limits> header.
93  runtest("int64_t (possibly long long)", boost::int64_t());
94  runtest("uint64_t (possibly unsigned long long)", boost::uint64_t());
95#else
96  std::cout << "Skipped int64_t and uint64_t" << std::endl;
97#endif
98  // Some compilers don't pay attention to std:3.6.1/5 and issue a
99  // warning here if "return 0;" is omitted.
100  return 0;
101}
102
Note: See TracBrowser for help on using the repository browser.