PageRenderTime 44ms CodeModel.GetById 11ms app.highlight 24ms RepoModel.GetById 7ms app.codeStats 0ms

/Src/Dependencies/Boost/libs/phoenix/test/operator/misc_binary_tests.cpp

http://hadesmem.googlecode.com/
C++ | 102 lines | 78 code | 18 blank | 6 comment | 55 complexity | b9884b68a4ac7c5e113587062d242cef MD5 | raw file
  1/*=============================================================================
  2    Copyright (c) 2001-2007 Joel de Guzman
  3
  4    Distributed under the Boost Software License, Version 1.0. (See accompanying 
  5    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6==============================================================================*/
  7
  8#include <string>
  9#include <boost/detail/lightweight_test.hpp>
 10#include <boost/phoenix/core.hpp>
 11#include <boost/phoenix/operator.hpp>
 12
 13namespace phoenix = boost::phoenix;
 14
 15int
 16main()
 17{
 18    using phoenix::ref;
 19    using phoenix::val;
 20    using phoenix::arg_names::arg1;
 21    using phoenix::arg_names::arg2;
 22    using std::string;
 23    {   // From Phoenix 1.1 binary tests
 24
 25        int i2 = 2, i3 = 3, i = 5;
 26        const char* world = " world";
 27
 28
 29        BOOST_TEST((ref(i) = ref(i))() == 5);
 30        BOOST_TEST((ref(i) = 3)() == 3);
 31        BOOST_TEST(i == 3);
 32        i = 5;
 33        int x, y, z;
 34        (ref(x) = ref(y) = ref(z) = 10)();
 35        BOOST_TEST(x == 10 && y == 10 && z == 10);
 36        BOOST_TEST((val(world)[3])() == world[3]);
 37
 38        BOOST_TEST((ref(i) += 5)() == 10);
 39        BOOST_TEST((ref(i) -= 5)() == 5);
 40        BOOST_TEST((ref(i) *= 5)() == 25);
 41        BOOST_TEST((ref(i) /= 5)() == 5);
 42        BOOST_TEST((ref(i) %= 2)() == 1);
 43
 44        BOOST_TEST((ref(i) <<= 3)() == 8);
 45        BOOST_TEST((ref(i) >>= 1)() == 4);
 46        BOOST_TEST((ref(i) |= 0xFF)() == 0xFF);
 47        BOOST_TEST((ref(i) &= 0xF0)() == 0xF0);
 48        BOOST_TEST((ref(i) ^= 0xFFFFFFFF)() == int(0xFFFFFF0F));
 49
 50        BOOST_TEST((val(5) == val(5))());
 51        BOOST_TEST((val(5) == 5)());
 52
 53        BOOST_TEST((arg1 + arg2 )(i2, i3) == i2 + i3 );
 54        BOOST_TEST((arg1 - arg2)(i2, i3) == i2 - i3);
 55        BOOST_TEST((arg1 * arg2)(i2, i3) == i2 * i3);
 56        BOOST_TEST((arg1 / arg2)(i2, i3) == i2 / i3);
 57        BOOST_TEST((arg1 % arg2)(i2, i3) == i2 % i3);
 58        BOOST_TEST((arg1 & arg2)(i2, i3) == (i2 & i3));
 59        BOOST_TEST((arg1 | arg2)(i2, i3) == (i2 | i3));
 60        BOOST_TEST((arg1 ^ arg2)(i2, i3) == (i2 ^ i3));
 61        BOOST_TEST((arg1 << arg2)(i2, i3) == i2 << i3);
 62        BOOST_TEST((arg1 >> arg2)(i2, i3) == i2 >> i3);
 63
 64        BOOST_TEST((val(5) != val(6))());
 65        BOOST_TEST((val(5) < val(6))());
 66        BOOST_TEST(!(val(5) > val(6))());
 67        BOOST_TEST((val(5) < val(6))());
 68        BOOST_TEST((val(5) <= val(6))());
 69        BOOST_TEST((val(5) <= val(5))());
 70        BOOST_TEST((val(7) >= val(6))());
 71        BOOST_TEST((val(7) >= val(7))());
 72
 73        BOOST_TEST((val(false) && val(false))() == false);
 74        BOOST_TEST((val(true) && val(false))() == false);
 75        BOOST_TEST((val(false) && val(true))() == false);
 76        BOOST_TEST((val(true) && val(true))() == true);
 77
 78        BOOST_TEST((val(false) || val(false))() == false);
 79        BOOST_TEST((val(true) || val(false))() == true);
 80        BOOST_TEST((val(false) || val(true))() == true);
 81        BOOST_TEST((val(true) || val(true))() == true);
 82    }
 83
 84    {  // From Phoenix 1.1 mixed_binary tests
 85
 86        int     i1 = 1, i2 = 2, i50 = 50, i100 = 100;
 87        double  d2_5 = 2.5;
 88        string hello = "hello";
 89        const char* world = " world";
 90
 91        BOOST_TEST((arg1 + arg2)(i100, i50) == (i100 + i50));
 92        BOOST_TEST((arg1 + 3)(i100) == (3 + i100));
 93        BOOST_TEST((arg1 + arg2)(hello, world) == "hello world");
 94        BOOST_TEST((arg1 + arg2)(i1, d2_5) == (i1 + d2_5));
 95
 96        BOOST_TEST((*(arg1 + arg2))(world, i2) == *(world + i2));
 97        BOOST_TEST((*(arg1 + arg2))(i2, world) == *(i2 + world));
 98        BOOST_TEST((*(val(world+i2) - arg1))(i2) == *world);
 99    }
100
101    return boost::report_errors();
102}