/*============================================================================= This file is part of FLINT. FLINT is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. FLINT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with FLINT; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA =============================================================================*/ /****************************************************************************** Copyright (C) 2013 Tom Bachmann ******************************************************************************/ // XXX NOTE: the forwarding code was never completed, and neither was this // test file. #include #include #include "flintxx/forwarding.h" #include "flintxx/test/myint.h" #include "flintxx/test/helpers.h" using namespace flint; template class forwarded_expression : public expression, Operation, Data> { public: forwarded_expression() {}; template explicit forwarded_expression(const T& t) : expression, Operation, Data>(t) {} template forwarded_expression& operator=(const T& t) { this->set(t); return *this; } protected: explicit forwarded_expression(const Data& d) : expression, Operation, Data>(d) {} template friend class ::flint::expression; }; struct hide_myint { myint i; template hide_myint(const T& t) : i(t) {} hide_myint() {} }; typedef forwarded_expression fwint; namespace flint { namespace forwarding { template<> struct enable : mp::true_ { typedef myint underlying_t; static const myint& get_underlying(const fwint& fwd) { return fwd._data().i; } static myint& get_underlying(fwint& fwd) { return fwd._data().i; } }; } } void test_print() { fwint fwd(4); std::ostringstream oss; oss << fwd; tassert(oss.str() == "4"); } void test_assignment() { fwint f1, f2(4); f1 = WORD(3); // TODO understand why "3" seems to lead to circular dependency tassert(f1 == 3); f1 = f2; tassert(f1 == 4); } void test_equals() { fwint f1(4), f2(5); myint m1(4); tassert(f1 == f1); tassert(f1 != f2); tassert(f1 == 4); tassert(5 != f1); tassert(f1 == m1); tassert(m1 != f2); } void test_conversion() { fwint a(4); tassert(typed_equals(a.to(), 4)); } void test_evaluation() { fwint a(4); myint b(5); tassert(typed_equals((a + a).evaluate(), myint(8))); tassert(a + b == 9); tassert(a + 6 == 10); tassert((a + 6) + b == 15); } int main() { std::cout << "forwarding...."; test_print(); test_assignment(); // TODO test cmp test_equals(); test_conversion(); test_evaluation(); std::cout << "PASS" << std::endl; return 0; }