Lumiera  0.pre.03
»edit your freedom«
test-target-obj.hpp
Go to the documentation of this file.
1 /*
2  TEST-TARGET-OBJ.hpp - a test (stub) target object for testing the factories
3 
4  Copyright (C) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 */
22 
30 #ifndef LIBRARY_TEST_TARGET_OBJ_H
31 #define LIBRARY_TEST_TARGET_OBJ_H
32 
33 
34 #include "lib/test/run.hpp"
35 #include "lib/format-string.hpp"
36 #include "lib/format-cout.hpp"
37 
38 #include <boost/lexical_cast.hpp>
39 #include <string>
40 
41 
42 namespace lib {
43 namespace test{
44 
45  using util::_Fmt;
46  using boost::lexical_cast;
47  using std::string;
48 
55  {
56  uint cnt_;
57  string* heapData_;
58  string* heapArray_;
59 
60  public:
61  TestTargetObj(uint num);
62  virtual ~TestTargetObj();
63 
64  virtual operator string () const;
65  };
66 
67 
68 
69  inline
70  TestTargetObj::TestTargetObj(uint num)
71  : cnt_ (num)
72  , heapData_ (new string(num,'*'))
73  , heapArray_ (new string[num])
74  {
75  for (uint i=0; i<cnt_; ++i)
76  heapArray_[i] = lexical_cast<string>(i);
77  cout << _Fmt("ctor TargetObj(%i) successful\n") % cnt_;
78  }
79 
80 
81  inline
82  TestTargetObj::~TestTargetObj()
83  {
84  delete heapData_;
85  delete[] heapArray_;
86  cout << _Fmt("dtor ~TargetObj(%i) successful\n") % cnt_;
87  }
88 
89 
90 
91  inline
92  TestTargetObj::operator string () const
93  {
94  string array_contents = "{";
95  for (uint i=0; i<cnt_; ++i)
96  array_contents += heapArray_[i]+",";
97  array_contents+="}";
98 
99  return _Fmt(".....TargetObj(%1%): data=\"%2%\", array[%1%]=%3%")
100  % cnt_ % *heapData_ % array_contents;
101  }
102 
103 
104 
105 
106 }} // namespace lib::test
107 #endif
Automatically use custom string conversion in C++ stream output.
Definition: run.hpp:49
Front-end for printf-style string template interpolation.
A front-end for using printf-style formatting.
Implementation namespace for support and library code.
Target object to be created by Test-Factories or as Singleton.
Simple test class runner.