Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
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"
21#include "lib/zombie-check.hpp"
22#include "lib/util.hpp"
23
24#include <string>
25
26using util::contains;
27using util::isnil;
28using std::string;
29
30
31namespace lib {
32namespace 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
Automatic lifecycle tracker, to produce an alarm when accessing objects after deletion.
virtual CStr what() const noexcept override
std::exception interface : yield a diagnostic message
Derived specific exceptions within Lumiera's exception hierarchy.
Definition error.hpp:193
string randStr(size_t len)
create garbage string of given length
Implementation namespace for support and library code.
Test runner and basic definitions for tests.
bool contains(MAP &map, typename MAP::key_type const &key)
shortcut for containment test on a map
Definition util.hpp:230
bool isnil(lib::time::Duration const &dur)
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
A collection of frequently used helper functions to support unit testing.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Detector to set off alarm when (re)using deceased objects.