/* TestTracking(Test) - demonstrate test helpers for tracking automated clean-up Copyright (C) Lumiera.org 2024, Hermann Vosseler This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * *****************************************************/ /** @file test-tracking-test.cpp ** unit test \ref TestTracking_test */ #include "lib/test/run.hpp" #include "lib/test/test-helper.hpp" #include "lib/test/tracking-dummy.hpp" #include "lib/test/tracking-allocator.hpp" #include "lib/format-cout.hpp" #include "lib/format-util.hpp" #include "lib/test/diagnostic-output.hpp"///////////////////////TODO #include using std::string; using util::toString; using util::join; namespace lib { namespace test{ namespace test{ /***************************************************//** * @test verify proper working of test helpers to track * automated clean-up and memory deallocation. * @see TestHelper_test * @see tracking-dummy.hpp * @see tracking-allocator.hpp */ class TestTracking_test : public Test { void run (Arg) { demonstrate_logObject(); demonstrate_checkObject(); demonstrate_checkAllocator(); } /** @test capture object lifecycle events in the EventLog. * @see EventLog_test * @see LateBindInstance_test */ void demonstrate_logObject () { auto& log = Tracker::log; log.clear (this); Tracker alpha; // (1) create α auto randomAlpha = toString(alpha.val); log.note("type=ID",alpha.val); // (2) α has an random ID { Tracker beta{55}; // (3) create β alpha = beta; // (4) assign α ≔ β } log.note("type=ID",alpha.val); // (5) thus α now also bears the ID 55 of β Tracker gamma = move(alpha); // (6) create γ by move-defuncting α { Tracker delta(23); // (7) create δ with ID 23 delta = move(gamma); // (8) move-assign δ ⟵ γ log.note("type=ID",delta.val); // (9) thus δ now bears the ID 55 (moved α ⟶ γ ⟶ δ) } log.note("type=ID",alpha.val); // (X) and thus α is now a zombie object cout << "____Tracker-Log_______________\n" << util::join(Tracker::log, "\n") << "\n───╼━━━━━━━━━━━╾──────────────"<>; SpyVec vec1(3); int v3 = vec1.back().val; SHOW_EXPR(v3); SHOW_EXPR(join(vec1)) SpyVec vec2; vec2.emplace_back (move (vec1[2])); SHOW_EXPR(join(vec1)) SHOW_EXPR(join(vec2)) } CHECK (TrackingAllocator::checksum() == 0); cout << "____Tracking-Allo-Log_________\n" << util::join(Tracker::log, "\n") << "\n───╼━━━━━━━━━━━━━━━━━╾────────"<