Lumiera  0.pre.03
»edit your freedom«
null-value-test.cpp
Go to the documentation of this file.
1 /*
2  NullValue(Test) - verify the singleton holder for NIL or default values
3 
4  Copyright (C) Lumiera.org
5  2010, 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 #include "lib/test/run.hpp"
31 #include "lib/null-value.hpp"
32 #include "lib/util.hpp"
33 
34 #include <cstdlib>
35 
36 
37 namespace lib {
38 namespace test{
39 
40  using util::isSameObject;
41  using std::rand;
42 
43 
44  namespace { // test data and helpers...
45 
46 
48  struct DummyType
49  {
50  static bool created;
51 
52  uint id_;
53 
54  DummyType()
55  : id_(1 + (rand() % 100))
56  {
57  created = true;
58  }
59  };
60 
61  bool DummyType::created = false;
62 
63 
64  }
65 
66 
67 
68  /***********************************************************************************/
75  class NullValue_test : public Test
76  {
77 
78  void
79  run (Arg)
80  {
81  CHECK (long() == NullValue<long>::get());
82  CHECK (short() == NullValue<short>::get());
83  CHECK (isSameObject(NullValue<short>::get(), NullValue<short>::get()));
84 
85  CHECK (!DummyType::created);
86  DummyType copy (NullValue<DummyType>::get());
87  CHECK ( DummyType::created);
88 
89  CHECK ( copy.id_ == NullValue<DummyType>::get().id_);
90  CHECK (!isSameObject(NullValue<DummyType>::get(), copy));
91  CHECK ( isSameObject(NullValue<DummyType>::get(), NullValue<DummyType>::get()));
92  }
93  };
94 
95 
97  LAUNCHER (NullValue_test, "unit common");
98 
99 
100 }} // namespace lib::test
Definition: run.hpp:49
Singleton holder for NIL or default value objects.
Definition: null-value.hpp:71
Singleton-style holder for NIL or default values.
Implementation namespace for support and library code.
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
bool isSameObject(A const &a, B const &b)
compare plain object identity, bypassing any custom comparison operators.
Definition: util.hpp:372