Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/QtTrayMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ QtTrayMenu::QtTrayMenu(int argc, char **argv, QObject *parent, const bool debug)
// Note: The following is ugly but QApplication requires an argv containing the application name.
// We might not have access to the real argc/argv here due to being called/pulled as a dependency.
if (argc < 0 && argv == nullptr) {
app = new QApplication(defaultArgc, defaultArgv); // NOSONAR(cpp:S5025) - Qt has its own integrated memory management
app = new QApplication(defaultArgc, defaultArgv); // NOSONAR(cpp:S5025): Qt has its own integrated memory management
} else {
app = new QApplication(argc, argv); // NOSONAR(cpp:S5025) - Qt has its own integrated memory management
app = new QApplication(argc, argv); // NOSONAR(cpp:S5025): Qt has its own integrated memory management
}
}
#if defined(_WIN32)
Expand All @@ -59,7 +59,7 @@ QtTrayMenu::~QtTrayMenu() {
// Quit QApplication
QApplication::quit();
// Delete app and clear references
delete app; // NOSONAR(cpp:S5025) - Qt has its own integrated memory management
delete app; // NOSONAR(cpp:S5025): Qt has its own integrated memory management
app = nullptr; // Set to nullptr after deletion
}
}
Expand Down Expand Up @@ -147,13 +147,13 @@ void QtTrayMenu::onExitRequested() {
if (trayIcon) {
trayIcon->setContextMenu(nullptr);
}
delete trayTopMenu; // NOSONAR(cpp:S5025) - Qt has its own integrated memory management
delete trayTopMenu; // NOSONAR(cpp:S5025): Qt has its own integrated memory management
trayTopMenu = nullptr; // Set to nullptr after deletion
}
// Remove tray icon references;
if (trayIcon) {
trayIcon->hide();
delete trayIcon; // NOSONAR(cpp:S5025) - Qt has its own integrated memory management
delete trayIcon; // NOSONAR(cpp:S5025): Qt has its own integrated memory management
trayIcon = nullptr; // Set to nullptr after deletion
}
// Unset tray structure
Expand All @@ -167,7 +167,7 @@ void QtTrayMenu::onExitRequested() {

void QtTrayMenu::updateMenu(struct tray_menu *items) {
// Create and setup new tray menu instance
const auto newTrayTopMenu = new QMenu(); // NOSONAR(cpp:S5025) - Qt has its own integrated memory management
const auto newTrayTopMenu = new QMenu(); // NOSONAR(cpp:S5025): Qt has its own integrated memory management
#if defined(_WIN32)
connect(newTrayTopMenu, &QMenu::aboutToShow, this, []() {
tray_qt::windows::sync_color_scheme();
Expand All @@ -179,7 +179,7 @@ void QtTrayMenu::updateMenu(struct tray_menu *items) {
// Clear old, unused trayTopMenu instance
if (trayTopMenu != nullptr) {
trayTopMenu->clear(); // Remove all actions
delete trayTopMenu; // NOSONAR(cpp:S5025) - Qt has its own integrated memory management
delete trayTopMenu; // NOSONAR(cpp:S5025): Qt has its own integrated memory management
}
// Store reference for cleanup
trayTopMenu = newTrayTopMenu;
Expand All @@ -190,7 +190,7 @@ void QtTrayMenu::createMenu(struct tray_menu *items, QMenu *menu) {
if (strcmp(items->text, "-") == 0) {
menu->addSeparator();
} else {
auto *action = new QAction(QString::fromUtf8(items->text), menu); // NOSONAR(cpp:S5025) - Qt has its own integrated memory management
auto *action = new QAction(QString::fromUtf8(items->text), menu); // NOSONAR(cpp:S5025): Qt has its own integrated memory management
action->setDisabled(items->disabled == 1);
action->setCheckable(items->checkbox == 1);
action->setChecked(items->checked == 1);
Expand Down Expand Up @@ -257,7 +257,7 @@ void QtTrayMenu::onMenuItemTriggered() {
}
}

struct tray_menu *QtTrayMenu::getTrayMenuItem(QAction *action) { // NOSONAR(cpp:S995) - Use as defined in function interface
struct tray_menu *QtTrayMenu::getTrayMenuItem(QAction *action) { // NOSONAR(cpp:S995): Use as defined in function interface
return static_cast<struct tray_menu *>(action->property("tray_menu_item").value<void *>());
}

Expand Down
6 changes: 3 additions & 3 deletions src/example.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static void toggle_cb(struct tray_menu *item) {
tray_update(&tray);
}

static void hello_cb(struct tray_menu *item) {
static void hello_cb(struct tray_menu *item) { // NOSONAR(c:S995): Mutable parameter required by tray_menu.cb.
(void) item;
printf("hello cb\n");
if (strcmp(tray.icon, TRAY_ICON1) == 0) {
Expand All @@ -31,13 +31,13 @@ static void hello_cb(struct tray_menu *item) {
tray_update(&tray);
}

static void quit_cb(struct tray_menu *item) {
static void quit_cb(struct tray_menu *item) { // NOSONAR(c:S995): Mutable parameter required by tray_menu.cb.
(void) item;
printf("quit cb\n");
tray_exit();
}

static void submenu_cb(struct tray_menu *item) {
static void submenu_cb(struct tray_menu *item) { // NOSONAR(c:S995): Mutable parameter required by tray_menu.cb.
(void) item;
printf("submenu: clicked on %s\n", item->text);
tray_update(&tray);
Expand Down
16 changes: 8 additions & 8 deletions src/tray_qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ namespace tray_qt {
/**
* QtTrayMenu instance
*/
std::unique_ptr<QtTrayMenu> qt_tray_menu = nullptr; // NOSONAR(cpp:S5421) - mutable state, not const
std::unique_ptr<QtTrayMenu> qt_tray_menu = nullptr; // NOSONAR(cpp:S5421): mutable state, not const
/**
* Logging callback for qt_message_handler
*/
void (*log_callback)(int, const char *) = nullptr; // NOSONAR(cpp:S5421) - mutable state, not const
void (*log_callback)(int, const char *) = nullptr; // NOSONAR(cpp:S5421): mutable state, not const
/**
* Explicit Qt application metadata configured through the C API.
*/
bool app_info_configured = false; // NOSONAR(cpp:S5421) - mutable state, not const
bool app_info_configured = false; // NOSONAR(cpp:S5421): mutable state, not const
/**
* Qt application name configured through the C API.
*/
QString app_name; // NOSONAR(cpp:S5421) - mutable state, not const
QString app_name; // NOSONAR(cpp:S5421): mutable state, not const
/**
* Qt application display name configured through the C API.
*/
QString app_display_name; // NOSONAR(cpp:S5421) - mutable state, not const
QString app_display_name; // NOSONAR(cpp:S5421): mutable state, not const
/**
* Qt desktop file name configured through the C API.
*/
QString desktop_name; // NOSONAR(cpp:S5421) - mutable state, not const
QString desktop_name; // NOSONAR(cpp:S5421): mutable state, not const

/**
* @brief Acknowledge/click current notification.
Expand Down Expand Up @@ -179,7 +179,7 @@ extern "C" {
return tray_qt::qt_tray_menu->loop(blocking);
}

void tray_update(struct tray *tray) { // NOSONAR(cpp:S995) - C API requires this exact mutable-pointer signature
void tray_update(struct tray *tray) { // NOSONAR(cpp:S995): C API requires this exact mutable-pointer signature
if (tray_qt::qt_tray_menu == nullptr) {
return;
}
Expand All @@ -206,7 +206,7 @@ extern "C" {
tray_qt::qt_tray_menu->exit();
}

void tray_set_log_callback(void (*cb)(int level, const char *msg)) { // NOSONAR(cpp:S5205) - C API requires a plain function pointer callback type
void tray_set_log_callback(void (*cb)(int level, const char *msg)) { // NOSONAR(cpp:S5205): C API requires a plain function pointer callback type
tray_qt::log_callback = cb;
if (cb != nullptr) {
qInstallMessageHandler(tray_qt::qt_message_handler);
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

// test includes
#include "tests/screenshot_utils.h"

// Undefine the original TEST macro
#undef TEST
#undef TEST // NOSONAR(cpp:S959): Tray tests extend the shared fixture with screenshot support.

// Redefine TEST to use our BaseTest class, to automatically use our BaseTest fixture
#define TEST(test_case_name, test_name) \
Expand All @@ -30,8 +31,7 @@ class BaseTest: public ::lizardbyte::common::testing::BaseTest {
void SetUp() override {
::lizardbyte::common::testing::BaseTest::SetUp();

// todo: only run this one time, instead of every time a test is run
// see: https://stackoverflow.com/questions/2435277/googletest-accessing-the-environment-from-a-test
// The shared test fixture caches the command-line arguments.
// get command line args from the test executable
testArgs_ = getArgs();

Expand Down
2 changes: 1 addition & 1 deletion tests/notification_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace {
"id=$((id + 1)); "
"done; "
"fi";
(void) std::system(close_notifications); // NOSONAR(cpp:S4721) - test-only cleanup of desktop notifications
(void) std::system(close_notifications); // NOSONAR(cpp:S4721): test-only cleanup of desktop notifications
}
} // namespace
#endif
Expand Down
4 changes: 2 additions & 2 deletions tests/screenshot_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace {
static bool dpiAware = false;
std::call_once(dpiFlag, []() {
using SetProcessDPIAwareFn = BOOL(WINAPI *)();
auto *fn = reinterpret_cast<SetProcessDPIAwareFn>( // NOSONAR(cpp:S3630) - required for GetProcAddress function pointer cast
auto *fn = reinterpret_cast<SetProcessDPIAwareFn>( // NOSONAR(cpp:S3630): required for GetProcAddress function pointer cast
GetProcAddress(GetModuleHandleA("user32.dll"), "SetProcessDPIAware")
);
dpiAware = fn == nullptr || fn() == TRUE;
Expand Down Expand Up @@ -90,7 +90,7 @@ namespace {
namespace screenshot {

inline std::filesystem::path &output_root_ref() {
static std::filesystem::path g_outputRoot; // NOSONAR(cpp:S6018) - function-local static is intentional for lazy, TU-local initialization
static std::filesystem::path g_outputRoot; // NOSONAR(cpp:S6018): function-local static is intentional for lazy, TU-local initialization
return g_outputRoot;
}

Expand Down
44 changes: 22 additions & 22 deletions tests/unit/test_tray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,23 @@ namespace {
return {};
}

struct tray_menu g_submenu7_8[] = { // NOSONAR(cpp:S5945, cpp:S5421) - C-style array with null sentinel required by tray C API; mutable for runtime callback assignment
struct tray_menu g_submenu7_8[] = { // NOSONAR(cpp:S5945,cpp:S5421): C-style array with null sentinel required by tray C API; mutable for runtime callback assignment
{.text = "7", .cb = nullptr},
{.text = "-"},
{.text = "8", .cb = nullptr},
{.text = nullptr}
};
struct tray_menu g_submenu5_6[] = { // NOSONAR(cpp:S5945, cpp:S5421) - C-style array with null sentinel required by tray C API; mutable for runtime callback assignment
struct tray_menu g_submenu5_6[] = { // NOSONAR(cpp:S5945,cpp:S5421): C-style array with null sentinel required by tray C API; mutable for runtime callback assignment
{.text = "5", .cb = nullptr},
{.text = "6", .cb = nullptr},
{.text = nullptr}
};
struct tray_menu g_submenu_second[] = { // NOSONAR(cpp:S5945, cpp:S5421) - C-style array with null sentinel required by tray C API; mutable for runtime callback assignment
struct tray_menu g_submenu_second[] = { // NOSONAR(cpp:S5945,cpp:S5421): C-style array with null sentinel required by tray C API; mutable for runtime callback assignment
{.text = "THIRD", .submenu = g_submenu7_8},
{.text = "FOUR", .submenu = g_submenu5_6},
{.text = nullptr}
};
struct tray_menu g_submenu[] = { // NOSONAR(cpp:S5945, cpp:S5421) - C-style array with null sentinel required by tray C API; mutable for runtime callback assignment
struct tray_menu g_submenu[] = { // NOSONAR(cpp:S5945,cpp:S5421): C-style array with null sentinel required by tray C API; mutable for runtime callback assignment
{.text = "Hello", .cb = nullptr},
{.text = "Checked", .checked = 1, .checkbox = 1, .cb = nullptr},
{.text = "Disabled", .disabled = 1},
Expand All @@ -93,15 +93,15 @@ namespace {
{.text = "Quit", .cb = nullptr},
{.text = nullptr}
};
struct tray g_testTray = { // NOSONAR(cpp:S5421) - mutable global required for shared tray state across TEST_F instances
struct tray g_testTray = { // NOSONAR(cpp:S5421): mutable global required for shared tray state across TEST_F instances
.icon = TRAY_ICON1,
.tooltip = "TestTray",
.menu = g_submenu
};
} // namespace

class TrayTest: public BaseTest { // NOSONAR(cpp:S3656) - fixture members must be protected for TEST_F-generated subclasses
protected: // NOSONAR(cpp:S3656) - TEST_F generates subclasses that need access to fixture state/methods
class TrayTest: public BaseTest { // NOSONAR(cpp:S3656): fixture members must be protected for TEST_F-generated subclasses
protected: // NOSONAR(cpp:S3656): TEST_F generates subclasses that need access to fixture state/methods
void ShutdownTray() {
if (!trayRunning) {
return;
Expand Down Expand Up @@ -147,27 +147,27 @@ class TrayTest: public BaseTest { // NOSONAR(cpp:S3656) - fixture members must
capture_thread.join();
}

bool trayRunning {false}; // NOSONAR(cpp:S3656) - protected access required by gtest TEST_F subclass pattern
struct tray &testTray = g_testTray; // NOSONAR(cpp:S3656) - protected access required by gtest TEST_F subclass pattern
struct tray_menu *submenu = g_submenu; // NOSONAR(cpp:S3656) - protected access required by gtest TEST_F subclass pattern
struct tray_menu *submenu7_8 = g_submenu7_8; // NOSONAR(cpp:S3656) - protected access required by gtest TEST_F subclass pattern
struct tray_menu *submenu5_6 = g_submenu5_6; // NOSONAR(cpp:S3656) - protected access required by gtest TEST_F subclass pattern
struct tray_menu *submenu_second = g_submenu_second; // NOSONAR(cpp:S3656) - protected access required by gtest TEST_F subclass pattern
bool trayRunning {false}; // NOSONAR(cpp:S3656): protected access required by gtest TEST_F subclass pattern
struct tray &testTray = g_testTray; // NOSONAR(cpp:S3656): protected access required by gtest TEST_F subclass pattern
struct tray_menu *submenu = g_submenu; // NOSONAR(cpp:S3656): protected access required by gtest TEST_F subclass pattern
struct tray_menu *submenu7_8 = g_submenu7_8; // NOSONAR(cpp:S3656): protected access required by gtest TEST_F subclass pattern
struct tray_menu *submenu5_6 = g_submenu5_6; // NOSONAR(cpp:S3656): protected access required by gtest TEST_F subclass pattern
struct tray_menu *submenu_second = g_submenu_second; // NOSONAR(cpp:S3656): protected access required by gtest TEST_F subclass pattern

static void hello_cb([[maybe_unused]] struct tray_menu *item) {
// Mock implementation
}

static void toggle_cb([[maybe_unused]] struct tray_menu *item) { // NOSONAR(cpp:S1172) - unused param required by tray_menu.cb function pointer type
static void toggle_cb([[maybe_unused]] struct tray_menu *item) { // NOSONAR(cpp:S1172): unused param required by tray_menu.cb function pointer type
g_testTray.menu[1].checked = !g_testTray.menu[1].checked;
tray_update(&g_testTray);
}

static void quit_cb([[maybe_unused]] struct tray_menu *item) { // NOSONAR(cpp:S1172) - unused param required by tray_menu.cb function pointer type
static void quit_cb([[maybe_unused]] struct tray_menu *item) { // NOSONAR(cpp:S1172): unused param required by tray_menu.cb function pointer type
tray_exit();
}

static void submenu_cb([[maybe_unused]] struct tray_menu *item) { // NOSONAR(cpp:S1172) - unused param required by tray_menu.cb function pointer type
static void submenu_cb([[maybe_unused]] struct tray_menu *item) { // NOSONAR(cpp:S1172): unused param required by tray_menu.cb function pointer type
// Mock implementation
tray_update(&g_testTray);
}
Expand Down Expand Up @@ -477,7 +477,7 @@ TEST_F(TrayTest, TestMenuItemContext) {
static int contextValue = 42;
static bool contextCallbackInvoked = false;

auto context_callback = [](struct tray_menu *item) { // NOSONAR(cpp:S995) - must match tray_menu.cb signature void(*)(struct tray_menu*)
auto context_callback = [](struct tray_menu *item) { // NOSONAR(cpp:S995): must match tray_menu.cb signature void(*)(struct tray_menu*)
if (item->context != nullptr) {
const auto *value = static_cast<const int *>(item->context);
contextCallbackInvoked = (*value == 42);
Expand Down Expand Up @@ -516,7 +516,7 @@ TEST_F(TrayTest, TestCheckboxStates) {
EXPECT_EQ(testTray.menu[1].checked, 1);

// Show menu open with checkbox in checked state
captureMenuStateAndExit("tray_menu_checkbox_checked"); // NOSONAR(cpp:S6168) - helper uses std::thread for AppleClang 17 compatibility
captureMenuStateAndExit("tray_menu_checkbox_checked"); // NOSONAR(cpp:S6168): helper uses std::thread for AppleClang 17 compatibility

// Re-initialize tray with checkbox unchecked
trayRunning = false;
Expand All @@ -526,7 +526,7 @@ TEST_F(TrayTest, TestCheckboxStates) {
ASSERT_EQ(initResult, 0);

// Show menu open with checkbox in unchecked state
captureMenuStateAndExit("tray_menu_checkbox_unchecked"); // NOSONAR(cpp:S6168) - helper uses std::thread for AppleClang 17 compatibility
captureMenuStateAndExit("tray_menu_checkbox_unchecked"); // NOSONAR(cpp:S6168): helper uses std::thread for AppleClang 17 compatibility

// Restore initial checked state
testTray.menu[1].checked = 1;
Expand Down Expand Up @@ -600,7 +600,7 @@ TEST_F(TrayTest, TestTrayShowMenu) {
ASSERT_EQ(initResult, 0);

// Screenshot shows the full menu open, including the SubMenu entry that leads to nested items
captureMenuStateAndExit("tray_menu_shown"); // NOSONAR(cpp:S6168) - helper uses std::thread for AppleClang 17 compatibility
captureMenuStateAndExit("tray_menu_shown"); // NOSONAR(cpp:S6168): helper uses std::thread for AppleClang 17 compatibility
}

TEST_F(TrayTest, TestTrayExit) {
Expand All @@ -617,7 +617,7 @@ TEST_F(TrayTest, TestMenuAppearsOnLeftClick) {
trayRunning = (initResult == 0);
ASSERT_EQ(initResult, 0);

captureMenuStateAndExit("tray_menu_left_click"); // NOSONAR(cpp:S6168) - helper uses std::thread for AppleClang 17 compatibility
captureMenuStateAndExit("tray_menu_left_click"); // NOSONAR(cpp:S6168): helper uses std::thread for AppleClang 17 compatibility
}

TEST_P(TrayNotificationIconTest, TestNotificationCallbackFiredOnClick) {
Expand Down Expand Up @@ -660,7 +660,7 @@ TEST_F(TrayTest, TestMenuCallbackAfterNotificationUpdate) {
static int callbackCount = 0;
callbackCount = 0;

auto first_item_callback = [](struct tray_menu *item) { // NOSONAR(cpp:S1172) - unused param required by tray_menu.cb function pointer type
auto first_item_callback = [](struct tray_menu *item) { // NOSONAR(cpp:S1172): unused param required by tray_menu.cb function pointer type
callbackCount++;
(void) item;
};
Expand Down
Loading
Loading