[Mockpp-commits] mockpp/mockpp/tests ConstraintList_test.cpp,NONE,1.1
Brought to you by:
ewald-arnold
|
From: Ewald A. <ewa...@us...> - 2005-02-27 18:06:57
|
Update of /cvsroot/mockpp/mockpp/mockpp/tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4989/mockpp/tests Added Files: ConstraintList_test.cpp Log Message: VisitableMockObjects also take constraints as controlling elements --- NEW FILE: ConstraintList_test.cpp --- /*************************************************************************** ConstraintList_test.cpp - unit tests for ConstraintList class ------------------- begin : Sat Feb 26 2005 copyright : (C) 2002-2005 by Ewald Arnold email : mockpp at ewald-arnold dot de $Id: ConstraintList_test.cpp,v 1.1 2005/02/27 18:06:48 ewald-arnold Exp $ ***************************************************************************/ /************************************************************************** * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation; either version 2 of the License, * or (at your option) any later version. * * This program 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 Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * ***************************************************************************/ #include <mockpp/mockpp.h> // always first #ifndef HAVE_CPPUNIT # warning CppUnit not available at compile time #else #include <mockpp/compat/Assert.h> #include <mockpp/constraint/ConstraintList.h> #include <mockpp/constraint/IsLessOrEqual.h> #include <mockpp/constraint/IsGreaterOrEqual.h> #include <cppunit/extensions/HelperMacros.h> class ConstraintList_test : public CppUnit::TestFixture { public: CPPUNIT_TEST_SUITE( ConstraintList_test ); CPPUNIT_TEST(test_chain); CPPUNIT_TEST(test_hasExpectations); CPPUNIT_TEST(test_name); CPPUNIT_TEST(test_many); CPPUNIT_TEST(test_balance); CPPUNIT_TEST(test_clear); CPPUNIT_TEST(test_expectNothing); CPPUNIT_TEST(test_expectNothing_revoked); CPPUNIT_TEST(test_expectActualImmediate); CPPUNIT_TEST(test_expectActualVerify); CPPUNIT_TEST(test_ifNoExpected); CPPUNIT_TEST_EXCEPTION(fail_clearActual, mockpp::AssertionFailedError); CPPUNIT_TEST_EXCEPTION(fail_expectActualImmediate, mockpp::AssertionFailedError); CPPUNIT_TEST_EXCEPTION(fail_expectActualVerify, mockpp::AssertionFailedError); CPPUNIT_TEST_EXCEPTION(fail_expectNothing, mockpp::AssertionFailedError); CPPUNIT_TEST_EXCEPTION(fail_many, mockpp::AssertionFailedError); CPPUNIT_TEST_EXCEPTION(fail_ifNoActual, mockpp::AssertionFailedError); CPPUNIT_TEST_SUITE_END(); public: void test_expectNothing(); void test_expectNothing_revoked(); void fail_expectNothing(); void test_expectActualImmediate(); void fail_expectActualImmediate(); void test_expectActualVerify(); void fail_expectActualVerify(); void test_clear(); void fail_many(); void test_name(); void fail_clearActual(); void test_hasExpectations(); void test_ifNoExpected(); void test_chain(); void test_balance(); void test_many(); void fail_ifNoActual(); }; CPPUNIT_TEST_SUITE_REGISTRATION(ConstraintList_test); void ConstraintList_test::test_chain() { int exp_prep[10] = { 0, 1 }; mockpp::ConstraintList<int> ab (MOCKPP_PCHAR("testConstraintList"), 0); ab.addExpected(200) .addExpected(exp_prep+0, exp_prep+2) .addExpected(700) .addExpected(800) .addExpected(new mockpp::IsGreaterOrEqual<int>(20)) .addExpected(new mockpp::IsLessOrEqual<int>(20)); ab.addActual(200); ab.addActual(0); ab.addActual(1); ab.addActual(700); ab.balanceActual(); ab.addActual(22); ab.addActual(18); ab.verify(); ab.clear(); ab.addActual(22); ab.addActual(18); ab.addExpected(22); ab.addExpected(18); ab.verify(); } void ConstraintList_test::test_name() { mockpp::ConstraintList<int> ec (MOCKPP_PCHAR("testList"), 0); CPPUNIT_ASSERT(ec.getVerifiableName() == (MOCKPP_PCHAR("testList"))); } void ConstraintList_test::test_hasExpectations() { { mockpp::ConstraintList<int> ec (MOCKPP_PCHAR("testList"), 0); CPPUNIT_ASSERT(false == ec.hasExpectations()); ec.addExpected(2); CPPUNIT_ASSERT(true == ec.hasExpectations()); } mockpp::ConstraintList<int> ec2 (MOCKPP_PCHAR("testList"), 0); CPPUNIT_ASSERT(false == ec2.hasExpectations()); ec2.setExpectNothing(); CPPUNIT_ASSERT(true == ec2.hasExpectations()); } void ConstraintList_test::test_clear() { mockpp::ConstraintList<int> ec (MOCKPP_PCHAR("nothingValue"), 0); ec.addExpected(1234); ec.clear(); CPPUNIT_ASSERT(false == ec.hasExpectations()); ec.verify(); // no fail because no expectations } void ConstraintList_test::fail_clearActual() { mockpp::ConstraintList<int> ec (MOCKPP_PCHAR("testList"), 0); ec.addExpected(3); ec.addActual(3); ec.clearActual(); ec.verify(); } void ConstraintList_test::test_ifNoExpected() { mockpp::ConstraintList<int> ec (MOCKPP_PCHAR("nothingList"), 0); ec.addActual(3); // fails because no expectation value } void ConstraintList_test::fail_ifNoActual() { mockpp::ConstraintList<int> ec (MOCKPP_PCHAR("nothingList"), 0); ec.addExpected(3); ec.verify(); // fails because no value } static void doNothing(mockpp::ConstraintList<int> &ec) { ec.addExpected(3); ec.setExpectNothing(); } void ConstraintList_test::test_expectNothing() { mockpp::ConstraintList<int> ec (MOCKPP_PCHAR("nothingList"), 0); doNothing(ec); ec.verify(); // no fail } void ConstraintList_test::test_expectNothing_revoked() { mockpp::ConstraintList<int> ec (MOCKPP_PCHAR("nothingList"), 0); ec.setExpectNothing(); ec.addExpected(3); ec.addActual(3); ec.verify(); // no fail } void ConstraintList_test::fail_expectNothing() { mockpp::ConstraintList<int> ec (MOCKPP_PCHAR("nothingList"), 0); doNothing(ec); ec.addActual(3); // fails even if equal } static void doActualImmediate(mockpp::ConstraintList<int> &ec) { ec.addExpected(1234); ec.addExpected(5678); ec.addExpected(8765); ec.addExpected(4321); ec.addActual(1234); ec.addActual(5678); ec.addActual(8765); ec.addActual(4321); } void ConstraintList_test::test_expectActualImmediate() { mockpp::ConstraintList<int> ec (MOCKPP_PCHAR("actualList"), 0); doActualImmediate(ec); ec.verify(); // no fail } void ConstraintList_test::test_many() { mockpp::ConstraintList<int> ec (MOCKPP_PCHAR("actualList"), 0); int prep[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; ec.addExpected(prep+0, prep+10); ec.addActual(prep+0, prep+10); } void ConstraintList_test::fail_many() { mockpp::ConstraintList<int> ec (MOCKPP_PCHAR("actualList"), 0); int prep[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; ec.addExpected(prep+0, prep+10); ec.addActual(prep+2, prep+10); } void ConstraintList_test::fail_expectActualImmediate() { mockpp::ConstraintList<int> ec (MOCKPP_PCHAR("actualList"), 0); doActualImmediate(ec); ec.addActual(4321); // fails } static void doActualVerify(mockpp::ConstraintList<int> &ec) { ec.addExpected(1234); ec.setFailOnVerify(); ec.addActual(4321); // should not fail } void ConstraintList_test::test_expectActualVerify() { mockpp::ConstraintList<int> ec (MOCKPP_PCHAR("verifyList"), 0); doActualVerify(ec); // no fail } void ConstraintList_test::fail_expectActualVerify() { mockpp::ConstraintList<int> ec (MOCKPP_PCHAR("verifyList"), 0); doActualVerify(ec); // no fail ec.verify(); // fails } void ConstraintList_test::test_balance() { mockpp::ConstraintList<int> ec (MOCKPP_PCHAR("verifyList"), 0); ec.addExpected(1); ec.addExpected(2); ec.addExpected(3); ec.addExpected(4); ec.addExpected(5); ec.addExpected(6); ec.balanceActual(); // copy last element ec.balanceActual(); // copy last element ec.balanceActual(); // copy last element ec.balanceActual(); // copy last element ec.balanceActual(); // copy last element ec.addActual(6); ec.verify(); } #endif // HAVE_CPPUNIT |