[graphics/krita] libs/ui: Add a code for testing asserts

Dmitry Kazakov null at kde.org
Fri Jul 19 12:19:13 BST 2024


Git commit fe42eb944e1827a14aed38c6a4cd968918202200 by Dmitry Kazakov.
Committed on 19/07/2024 at 11:18.
Pushed by dkazakov into branch 'master'.

Add a code for testing asserts

1) Set environment variable:

export KRITA_ENABLE_ASSERT_TESTS=1

2) Create an image with a file layer

3) Set file name with any of:

   * crash_me_with_safe_assert
   * crash_me_with_normal_assert
   * crash_me_with_qfatal

4) Press "Open attached file" button (folder icon)

CCBUG:489537
CC:kimageshop at kde.org

M  +13   -0    libs/ui/kis_file_layer.cpp

https://invent.kde.org/graphics/krita/-/commit/fe42eb944e1827a14aed38c6a4cd968918202200

diff --git a/libs/ui/kis_file_layer.cpp b/libs/ui/kis_file_layer.cpp
index b73e6d6b9b6..f8b960372bc 100644
--- a/libs/ui/kis_file_layer.cpp
+++ b/libs/ui/kis_file_layer.cpp
@@ -182,6 +182,19 @@ void KisFileLayer::openFile() const
             fileAlreadyOpen = true;
         }
     }
+    if (qEnvironmentVariableIsSet("KRITA_ENABLE_ASSERT_TESTS")) {
+        ENTER_FUNCTION() << ppVar(m_filename);
+        if (m_filename.toLower() == "crash_me_with_safe_assert") {
+            KIS_SAFE_ASSERT_RECOVER_NOOP(0 && "safe assert for testing purposes");
+        }
+        if (m_filename.toLower() == "crash_me_with_normal_assert") {
+            KIS_ASSERT_RECOVER_NOOP(0 && "normal assert for testing purposes");
+        }
+        if (m_filename.toLower() == "crash_me_with_qfatal") {
+            qFatal("Testing fatal message");
+        }
+    }
+
     if (!fileAlreadyOpen && QFile::exists(QFileInfo(path()).absoluteFilePath())) {
         KisPart::instance()->openExistingFile(QFileInfo(path()).absoluteFilePath());
     }


More information about the kimageshop mailing list