Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/spirit/phoenix/test/binary_tests.cpp @ 12

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

added boost

File size: 3.3 KB
Line 
1/*=============================================================================
2    Phoenix V1.2.1
3    Copyright (c) 2001-2003 Joel de Guzman
4
5    Use, modification and distribution is subject to the Boost Software
6    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7    http://www.boost.org/LICENSE_1_0.txt)
8==============================================================================*/
9#ifdef __GNUC__   //  Darn these relops!
10#ifndef __SGI_STL_INTERNAL_RELOPS
11#define __SGI_STL_INTERNAL_RELOPS
12#endif
13#endif
14
15#include <iostream>
16#include <cassert>
17
18#define PHOENIX_LIMIT 15
19#include <boost/spirit/phoenix/primitives.hpp>
20#include <boost/spirit/phoenix/operators.hpp>
21
22using namespace phoenix;
23using namespace std;
24
25///////////////////////////////////////////////////////////////////////////////
26int
27main()
28{
29    int i2 = 2, i3 = 3, i = 5;
30    const char* world = " world";
31
32///////////////////////////////////////////////////////////////////////////////
33//
34//  Binary operators
35//
36///////////////////////////////////////////////////////////////////////////////
37    assert((var(i) = var(i))() == 5);
38    assert((var(i) = 3)() == 3);
39    assert(i == 3);
40    i = 5;
41    int x, y, z;
42    (var(x) = var(y) = var(z) = 10)();
43    assert(x == 10 && y == 10 && z == 10);
44    assert((val(world)[3])() == world[3]);
45
46    assert((var(i) += 5)() == 10);
47    assert((var(i) -= 5)() == 5);
48    assert((var(i) *= 5)() == 25);
49    assert((var(i) /= 5)() == 5);
50    assert((var(i) %= 2)() == 1);
51
52    assert((var(i) <<= 3)() == 8);
53    assert((var(i) >>= 1)() == 4);
54    assert((var(i) |= 0xFF)() == 0xFF);
55    assert((var(i) &= 0xF0)() == 0xF0);
56    assert((var(i) ^= 0xFFFFFFFF)() == int(0xFFFFFF0F));
57
58    assert((val(5) == val(5))());
59    assert((val(5) == 5)());
60
61    assert((arg1 + arg2)(i2, i3) == i2 + i3);
62    assert((arg1 - arg2)(i2, i3) == i2 - i3);
63    assert((arg1 * arg2)(i2, i3) == i2 * i3);
64    assert((arg1 / arg2)(i2, i3) == i2 / i3);
65    assert((arg1 % arg2)(i2, i3) == i2 % i3);
66    assert((arg1 & arg2)(i2, i3) == i2 & i3);
67    assert((arg1 | arg2)(i2, i3) == i2 | i3);
68    assert((arg1 ^ arg2)(i2, i3) == i2 ^ i3);
69    assert((arg1 << arg2)(i2, i3) == i2 << i3);
70    assert((arg1 >> arg2)(i2, i3) == i2 >> i3);
71
72    assert((val(5) != val(6))());
73    assert((val(5) < val(6))());
74    assert(!(val(5) > val(6))());
75    assert((val(5) < val(6))());
76    assert((val(5) <= val(6))());
77    assert((val(5) <= val(5))());
78    assert((val(7) >= val(6))());
79    assert((val(7) >= val(7))());
80
81    assert((val(false) && val(false))() == false);
82    assert((val(true) && val(false))() == false);
83    assert((val(false) && val(true))() == false);
84    assert((val(true) && val(true))() == true);
85
86    assert((val(false) || val(false))() == false);
87    assert((val(true) || val(false))() == true);
88    assert((val(false) || val(true))() == true);
89    assert((val(true) || val(true))() == true);
90
91///////////////////////////////////////////////////////////////////////////////
92//
93//  End asserts
94//
95///////////////////////////////////////////////////////////////////////////////
96
97    cout << "///////////////////////////////////////////////////////////////////////////////\n";
98    cout << "\t\tTests concluded\n";
99    cout << "\t\tSUCCESS!!!\n";
100    cout << "///////////////////////////////////////////////////////////////////////////////\n";
101}
Note: See TracBrowser for help on using the repository browser.