00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <mockpp/mockpp.h>
00014
00015 #include "interface.h"
00016 #include "consumer.h"
00017
00018 #include <iostream>
00019
00020 #include <mockpp/TrackingCounter.h>
00021 #include <mockpp/MockObject.h>
00022
00023
00024 class PoorMockSecondEdition : public Interface
00025 , public MOCKPP_NS::MockObject
00026 {
00027 private:
00028
00029 MOCKPP_NS::TrackingCounterMaster counter;
00030
00031 public:
00032
00033 PoorMockSecondEdition()
00034 : MOCKPP_NS::MockObject(MOCKPP_PCHAR("MockObject"))
00035 , counter(MOCKPP_PCHAR("counter"), this)
00036 , open_counter(MOCKPP_PCHAR("open_counter"), counter)
00037 , read_counter(MOCKPP_PCHAR("read_counter"), counter)
00038 , write_counter(MOCKPP_PCHAR("write_counter"), counter)
00039 , close_counter(MOCKPP_PCHAR("close_counter"), counter)
00040 {
00041 }
00042
00043 virtual void open(const MOCKPP_STL::string & )
00044 {
00045 open_counter++;
00046 }
00047
00048 virtual MOCKPP_STL::string read()
00049 {
00050 read_counter++;
00051 return "dummy";
00052 }
00053
00054 virtual void write(const MOCKPP_STL::string & )
00055 {
00056 write_counter++;
00057 }
00058
00059 virtual unsigned calculate(unsigned input)
00060 {
00061 return input + 1;
00062 }
00063
00064 virtual void close()
00065 {
00066 close_counter++;
00067 }
00068
00069 MOCKPP_NS::TrackingCounterClient open_counter;
00070 MOCKPP_NS::TrackingCounterClient read_counter;
00071 MOCKPP_NS::TrackingCounterClient write_counter;
00072 MOCKPP_NS::TrackingCounterClient close_counter;
00073 };
00074
00075
00076 int main(int , char ** )
00077 {
00078 PoorMockSecondEdition mock;
00079
00080 MOCKPP_STD_NS::cout << "Tests starting" << MOCKPP_STD_NS::endl;
00081
00082 MOCKPP_TRY
00083 {
00084
00085 Consumer consumer(&mock);
00086 mock.open_counter.setExpected(1);
00087 mock.read_counter.setExpected(4);
00088 mock.close_counter.setExpected(5);
00089 consumer.load();
00090 mock.verify();
00091
00092 consumer.process();
00093 mock.open_counter.setExpected(6);
00094 mock.write_counter.setExpected(9);
00095 mock.close_counter.setExpected(10);
00096 consumer.save();
00097 mock.verify();
00098
00099 MOCKPP_STD_NS::cout << "Tests finished" << MOCKPP_STD_NS::endl;
00100
00101 }
00102 MOCKPP_CATCH(MOCKPP_STD_NS::exception &ex)
00103 {
00104 #ifndef MOCKPP_NO_EXCEPTIONS
00105 MOCKPP_STD_NS::cout << MOCKPP_STD_NS::endl
00106 << "Error occured.\n" << ex.what() << MOCKPP_STD_NS::endl
00107 << MOCKPP_STD_NS::endl;
00108 #endif
00109 return 1;
00110 }
00111
00112 MOCKPP_STD_NS::cout << "All tests have passed successfully" << MOCKPP_STD_NS::endl;
00113 return 0;
00114 }
00115