Lumiera  0.pre.03
»edit your freedom«
zombie-check-test.cpp
Go to the documentation of this file.
1 /*
2  ZombieCheck(Test) - verify a trap for accessing deceased objects
3 
4  Copyright (C) Lumiera.org
5  2018, 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 
28 #include "lib/test/run.hpp"
29 #include "lib/test/test-helper.hpp"
30 #include "lib/zombie-check.hpp"
31 #include "lib/util.hpp"
32 
33 #include <string>
34 
35 using util::contains;
36 using util::isnil;
37 using std::string;
38 
39 
40 namespace lib {
41 namespace test{
42 
43 
44 
45 
46 
47 
48  /**********************************************************************/
55  class ZombieCheck_test : public Test
56  {
57 
58  virtual void
59  run (Arg)
60  {
61  auto zombieID = randStr(50);
62  ZombieCheck trap{zombieID};
63  CHECK (not trap);
64 
65  trap.~ZombieCheck(); // note: unconventional kill
66  CHECK (trap); // accessing deceased object...
67 
68  try { //
69  trap(); // trigger the tripwire
70  }
71  catch(lumiera::error::Fatal& casuality)
72  {
73  string obituary = casuality.what();
74  CHECK (not isnil (obituary));
75  CHECK ( contains (obituary, zombieID.substr(0,41)));
76  CHECK (not contains (obituary, zombieID));
77  }
78  }
79  };
80 
81 
82 
84  LAUNCHER (ZombieCheck_test, "unit common");
85 
86 
87 
88 }} // namespace lib::test
Definition: run.hpp:49
Implementation namespace for support and library code.
string randStr(size_t len)
create garbage string of given length
Definition: test-helper.cpp:69
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:199
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A collection of frequently used helper functions to support unit testing.
Automatic lifecycle tracker, to produce an alarm when accessing objects after deletion.
Detector to set off alarm when (re)using deceased objects.
bool contains(SEQ const &cont, typename SEQ::const_reference val)
shortcut for brute-force containment test in any sequential container
Definition: util.hpp:255