monotone

monotone Mtn Source Tree

Root/numeric_vocab.cc

1// Copyright (C) 2006 Nathaniel Smith <njs@pobox.com>
2//
3// This program is made available under the GNU GPL version 2.0 or
4// greater. See the accompanying file COPYING for details.
5//
6// This program is distributed WITHOUT ANY WARRANTY; without even the
7// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8// PURPOSE.
9
10// Currently, this file just contains unit tests for widen<>.
11
12#ifdef BUILD_UNIT_TESTS
13
14#include "unit_tests.hh"
15#include "sanity.hh"
16#include "numeric_vocab.hh"
17
18UNIT_TEST(widen, widen)
19{
20 // These all have double-parens to stop the C preprocessor from becoming
21 // confused by the commas in the template arguments. The static_cast<u8>'s
22 // are to shut up compiler warnings.
23
24 // unsigned -> unsigned
25 I((widen<u8,u8>(1) == 1));
26 I((widen<u8,u8>(255) == 255));
27 I((widen<u8,u8>(static_cast<u8>(-1)) == 255));
28 I((widen<u32,u8>(1) == 1));
29 I((widen<u32,u8>(255) == 255));
30 I((widen<u32,u8>(static_cast<u8>(-1)) == 255));
31 // unsigned -> signed
32 I((widen<int32_t,u8>(1) == 1));
33 I((widen<int32_t,u8>(255) == 255));
34 I((widen<int32_t,u8>(static_cast<u8>(-1)) == 255));
35 // signed -> signed
36 I((widen<int32_t,int8_t>(1) == 1));
37 I((widen<int32_t,int8_t>(255) == -1));
38 I((widen<int32_t,int8_t>(-1) == -1));
39 // signed -> unsigned ((critical case!))
40 I((widen<u32,int8_t>(1) == 1));
41 I((widen<u32,int8_t>(255) == 255));
42 I((widen<u32,int8_t>(-1) == 255));
43 // contrasts with:
44 I((static_cast<u32>(int8_t(-1)) == u32(4294967295)));
45}
46
47#endif // BUILD_UNIT_TESTS
48
49
50// Local Variables:
51// mode: C++
52// fill-column: 76
53// c-file-style: "gnu"
54// indent-tabs-mode: nil
55// End:
56// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
57

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status