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)
5  2018, Hermann Vosseler <Ichthyostega@web.de>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
19 #include "lib/test/run.hpp"
20 #include "lib/test/test-helper.hpp"
21 #include "lib/zombie-check.hpp"
22 #include "lib/util.hpp"
23 
24 #include <string>
25 
26 using util::contains;
27 using util::isnil;
28 using std::string;
29 
30 
31 namespace lib {
32 namespace test{
33 
34 
35 
36 
37 
38 
39  /**********************************************************************/
46  class ZombieCheck_test : public Test
47  {
48 
49  virtual void
50  run (Arg)
51  {
52  auto zombieID = randStr(50);
53  ZombieCheck trap{zombieID};
54  CHECK (not trap);
55 
56  trap.~ZombieCheck(); // note: unconventional kill
57  CHECK (trap); // accessing deceased object...
58 
59  try { //
60  trap(); // trigger the tripwire
61  }
62  catch(lumiera::error::Fatal& casuality)
63  {
64  string obituary = casuality.what();
65  CHECK (not isnil (obituary));
66  CHECK ( contains (obituary, zombieID.substr(0,41)));
67  CHECK (not contains (obituary, zombieID));
68  }
69  }
70  };
71 
72 
73 
75  LAUNCHER (ZombieCheck_test, "unit common");
76 
77 
78 
79 }} // namespace lib::test
Definition: run.hpp:40
Implementation namespace for support and library code.
string randStr(size_t len)
create garbage string of given length
Definition: test-helper.cpp:61
Derived specific exceptions within Lumiera&#39;s exception hierarchy.
Definition: error.hpp:190
Simplistic 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