HelloAurora/Tests/Public/18. Hello Exit/Main.cpp
Reece d575087487 [+] Exit
[*] Update
[*] Formatting
2022-04-02 01:50:21 +01:00

65 lines
2.0 KiB
C++

/***
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: Main.cpp
Date: 2022-2-18
Author: Reece
***/
#include <AuroraRuntime.hpp>
#include <gtest/gtest.h>
static void AddHooks()
{
AuExit::ExitHandlerAdd(AuExit::ETriggerLevel::eProblematicEvent,
AuMakeShared<AuExit::IExitSubscriberFunctional>(
[](AuExit::ETriggerLevel level, const AuExit::ExitInvoker *pInvoker)
{
AuLogInfo("A problematic event occoured");
}));
AuExit::ExitHandlerAdd(AuExit::ETriggerLevel::eFatalException,
AuMakeShared<AuExit::IExitSubscriberFunctional>(
[](AuExit::ETriggerLevel level, const AuExit::ExitInvoker *pInvoker)
{
AuLogInfo("A fatal event occoured");
}));
AuExit::ExitHandlerAdd(AuExit::ETriggerLevel::eSigTerminate,
AuMakeShared<AuExit::IExitSubscriberFunctional>(
[](AuExit::ETriggerLevel level, const AuExit::ExitInvoker *pInvoker)
{
AuLogInfo("A terminate event was sent");
// You must synchronize / join all spawned threads here
// Aurora APIs may become unstable after this point
// Yes, we can try to design around and mitigate issues, but it's time to go...
}));
AuExit::ExitHandlerAdd(AuExit::ETriggerLevel::eSafeTermination,
AuMakeShared<AuExit::IExitSubscriberFunctional>(
[](AuExit::ETriggerLevel level, const AuExit::ExitInvoker *pInvoker)
{
AuLogInfo("Safe termination of application");
}));
AuLogInfo("Throwing exception...");
try
{
AU_THROW_STRING("hi");
}
catch (...)
{
}
AuLogInfo("Sleeping for 20s. Send a control+c, if you want");
AuThreading::Sleep(20'000);
}
void RunTests()
{
Aurora::RuntimeStartInfo info;
info.console.fio.enableLogging = false;
Aurora::RuntimeStart(info);
AddHooks();
}