aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/zencore.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-05-02 10:01:47 +0200
committerGitHub <[email protected]>2023-05-02 10:01:47 +0200
commit075d17f8ada47e990fe94606c3d21df409223465 (patch)
treee50549b766a2f3c354798a54ff73404217b4c9af /src/zencore/zencore.cpp
parentfix: bundle shouldn't append content zip to zen (diff)
downloadzen-075d17f8ada47e990fe94606c3d21df409223465.tar.xz
zen-075d17f8ada47e990fe94606c3d21df409223465.zip
moved source directories into `/src` (#264)
* moved source directories into `/src` * updated bundle.lua for new `src` path * moved some docs, icon * removed old test trees
Diffstat (limited to 'src/zencore/zencore.cpp')
-rw-r--r--src/zencore/zencore.cpp175
1 files changed, 175 insertions, 0 deletions
diff --git a/src/zencore/zencore.cpp b/src/zencore/zencore.cpp
new file mode 100644
index 000000000..2a7c5755e
--- /dev/null
+++ b/src/zencore/zencore.cpp
@@ -0,0 +1,175 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#include <zencore/zencore.h>
+
+#if ZEN_PLATFORM_WINDOWS
+# include <zencore/windows.h>
+#endif
+
+#if ZEN_PLATFORM_LINUX
+# include <pthread.h>
+#endif
+
+#include <zencore/blake3.h>
+#include <zencore/compactbinary.h>
+#include <zencore/compactbinarybuilder.h>
+#include <zencore/compactbinarypackage.h>
+#include <zencore/compositebuffer.h>
+#include <zencore/compress.h>
+#include <zencore/crypto.h>
+#include <zencore/filesystem.h>
+#include <zencore/intmath.h>
+#include <zencore/iobuffer.h>
+#include <zencore/memory.h>
+#include <zencore/mpscqueue.h>
+#include <zencore/refcount.h>
+#include <zencore/sha1.h>
+#include <zencore/stats.h>
+#include <zencore/stream.h>
+#include <zencore/string.h>
+#include <zencore/thread.h>
+#include <zencore/timer.h>
+#include <zencore/uid.h>
+
+namespace zen {
+
+AssertImpl AssertImpl::DefaultAssertImpl;
+AssertImpl* AssertImpl::CurrentAssertImpl = &AssertImpl::DefaultAssertImpl;
+
+//////////////////////////////////////////////////////////////////////////
+
+bool
+IsDebuggerPresent()
+{
+#if ZEN_PLATFORM_WINDOWS
+ return ::IsDebuggerPresent();
+#else
+ return false;
+#endif
+}
+
+std::optional<bool> InteractiveSessionFlag;
+
+void
+SetIsInteractiveSession(bool Value)
+{
+ InteractiveSessionFlag = Value;
+}
+
+bool
+IsInteractiveSession()
+{
+ if (!InteractiveSessionFlag.has_value())
+ {
+#if ZEN_PLATFORM_WINDOWS
+ DWORD dwSessionId = 0;
+ if (ProcessIdToSessionId(GetCurrentProcessId(), &dwSessionId))
+ {
+ InteractiveSessionFlag = (dwSessionId != 0);
+ }
+ else
+ {
+ InteractiveSessionFlag = false;
+ }
+#else
+ // TODO: figure out what actually makes sense here
+ InteractiveSessionFlag = true;
+#endif
+ }
+
+ return InteractiveSessionFlag.value();
+}
+
+//////////////////////////////////////////////////////////////////////////
+
+static int s_ApplicationExitCode = 0;
+static bool s_ApplicationExitRequested;
+
+bool
+IsApplicationExitRequested()
+{
+ return s_ApplicationExitRequested;
+}
+
+void
+RequestApplicationExit(int ExitCode)
+{
+ s_ApplicationExitCode = ExitCode;
+ s_ApplicationExitRequested = true;
+}
+
+#if ZEN_WITH_TESTS
+void
+zencore_forcelinktests()
+{
+ zen::blake3_forcelink();
+ zen::compositebuffer_forcelink();
+ zen::compress_forcelink();
+ zen::filesystem_forcelink();
+ zen::intmath_forcelink();
+ zen::iobuffer_forcelink();
+ zen::memory_forcelink();
+ zen::mpscqueue_forcelink();
+ zen::refcount_forcelink();
+ zen::sha1_forcelink();
+ zen::stats_forcelink();
+ zen::stream_forcelink();
+ zen::string_forcelink();
+ zen::thread_forcelink();
+ zen::timer_forcelink();
+ zen::uid_forcelink();
+ zen::uson_forcelink();
+ zen::usonbuilder_forcelink();
+ zen::usonpackage_forcelink();
+ zen::crypto_forcelink();
+}
+} // namespace zen
+
+# include <zencore/testing.h>
+
+namespace zen {
+
+TEST_CASE("Assert.Default")
+{
+ bool A = true;
+ bool B = false;
+ CHECK_THROWS_WITH(ZEN_ASSERT(A == B), "A == B");
+}
+
+TEST_CASE("Assert.Custom")
+{
+ struct MyAssertImpl : AssertImpl
+ {
+ ZEN_FORCENOINLINE ZEN_DEBUG_SECTION MyAssertImpl() : PrevAssertImpl(CurrentAssertImpl) { CurrentAssertImpl = this; }
+ virtual ZEN_FORCENOINLINE ZEN_DEBUG_SECTION ~MyAssertImpl() { CurrentAssertImpl = PrevAssertImpl; }
+ virtual void ZEN_FORCENOINLINE ZEN_DEBUG_SECTION OnAssert(const char* Filename,
+ int LineNumber,
+ const char* FunctionName,
+ const char* Msg)
+ {
+ AssertFileName = Filename;
+ Line = LineNumber;
+ FuncName = FunctionName;
+ Message = Msg;
+ }
+ AssertImpl* PrevAssertImpl;
+
+ const char* AssertFileName = nullptr;
+ int Line = -1;
+ const char* FuncName = nullptr;
+ const char* Message = nullptr;
+ };
+
+ MyAssertImpl MyAssert;
+ bool A = true;
+ bool B = false;
+ CHECK_THROWS_WITH(ZEN_ASSERT(A == B), "A == B");
+ CHECK(MyAssert.AssertFileName != nullptr);
+ CHECK(MyAssert.Line != -1);
+ CHECK(MyAssert.FuncName != nullptr);
+ CHECK(strcmp(MyAssert.Message, "A == B") == 0);
+}
+
+#endif
+
+} // namespace zen