From fd08eaefee13c52aea595637f857d086529f3759 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Sun, 22 Jan 2023 08:23:45 +0000 Subject: [PATCH] trivial: Fix bitwise operators in last commit --- libfwupdplugin/fu-context.c | 4 ++-- libfwupdplugin/fu-self-test.c | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/libfwupdplugin/fu-context.c b/libfwupdplugin/fu-context.c index 073108b19..08618b435 100644 --- a/libfwupdplugin/fu-context.c +++ b/libfwupdplugin/fu-context.c @@ -1093,7 +1093,7 @@ fu_context_add_flag(FuContext *context, FuContextFlags flag) { FuContextPrivate *priv = GET_PRIVATE(context); g_return_if_fail(FU_IS_CONTEXT(context)); - if (priv->flags | flag) + if (priv->flags & flag) return; priv->flags |= flag; g_object_notify(G_OBJECT(context), "flags"); @@ -1113,7 +1113,7 @@ fu_context_remove_flag(FuContext *context, FuContextFlags flag) { FuContextPrivate *priv = GET_PRIVATE(context); g_return_if_fail(FU_IS_CONTEXT(context)); - if ((priv->flags | flag) == 0) + if ((priv->flags & flag) == 0) return; priv->flags &= ~flag; g_object_notify(G_OBJECT(context), "flags"); diff --git a/libfwupdplugin/fu-self-test.c b/libfwupdplugin/fu-self-test.c index 35baf1522..3969ba5b2 100644 --- a/libfwupdplugin/fu-self-test.c +++ b/libfwupdplugin/fu-self-test.c @@ -415,6 +415,22 @@ fu_smbios3_func(void) g_assert_cmpstr(str, ==, "Dell Inc."); } +static void +fu_context_flags_func(void) +{ + g_autoptr(FuContext) ctx = fu_context_new(); + + g_assert_false(fu_context_has_flag(ctx, FU_CONTEXT_FLAG_SAVE_EVENTS)); + fu_context_add_flag(ctx, FU_CONTEXT_FLAG_SAVE_EVENTS); + g_assert_true(fu_context_has_flag(ctx, FU_CONTEXT_FLAG_SAVE_EVENTS)); + fu_context_remove_flag(ctx, FU_CONTEXT_FLAG_SAVE_EVENTS); + fu_context_remove_flag(ctx, FU_CONTEXT_FLAG_SAVE_EVENTS); + g_assert_false(fu_context_has_flag(ctx, FU_CONTEXT_FLAG_SAVE_EVENTS)); + fu_context_add_flag(ctx, FU_CONTEXT_FLAG_SAVE_EVENTS); + fu_context_add_flag(ctx, FU_CONTEXT_FLAG_SAVE_EVENTS); + g_assert_true(fu_context_has_flag(ctx, FU_CONTEXT_FLAG_SAVE_EVENTS)); +} + static void fu_context_hwids_dmi_func(void) { @@ -3790,6 +3806,7 @@ main(int argc, char **argv) g_test_add_func("/fwupd/common{strsafe}", fu_strsafe_func); g_test_add_func("/fwupd/efivar", fu_efivar_func); g_test_add_func("/fwupd/hwids", fu_hwids_func); + g_test_add_func("/fwupd/context{flags}", fu_context_flags_func); g_test_add_func("/fwupd/context{hwids-dmi}", fu_context_hwids_dmi_func); g_test_add_func("/fwupd/smbios", fu_smbios_func); g_test_add_func("/fwupd/smbios3", fu_smbios3_func); -- 2.39.5