]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-user-record.c: Migrate to new assertion MACROs
authorYaping Li <202858510+YapingLi04@users.noreply.github.com>
Tue, 22 Jul 2025 22:23:48 +0000 (15:23 -0700)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 23 Jul 2025 00:36:46 +0000 (09:36 +0900)
We recently added a new set of assertion macros such as ASSERT_GE, ASSERT_OK, ASSERT_EQ, ... which show not
only the expression that failed but also the values of the arguments of the expression. Let's use them.

src/test/test-user-record.c

index dd5d7360070494c0d7667568293570734b458fec..c807ffe83afd61162a880bb78fb289d28d0cf27c 100644 (file)
@@ -9,7 +9,7 @@
         ({                                      \
                 typeof(ret) _r = (ret);         \
                 user_record_unref(*_r);         \
-                assert_se(user_record_build((ret), SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR_STRING("disposition", "regular"), __VA_ARGS__)) >= 0); \
+                ASSERT_OK(user_record_build((ret), SD_JSON_BUILD_OBJECT(SD_JSON_BUILD_PAIR_STRING("disposition", "regular"), __VA_ARGS__))); \
                 0;                              \
         })
 
@@ -23,7 +23,7 @@ TEST(self_changes) {
         USER(&new,
              SD_JSON_BUILD_PAIR_STRING("userName", "test"),
              SD_JSON_BUILD_PAIR_UNSIGNED("notInHardCodedList", 99999));
-        assert_se(!user_record_self_changes_allowed(curr, new));
+        ASSERT_FALSE(user_record_self_changes_allowed(curr, new));
 
         /* manually allowlisted */
         USER(&curr,
@@ -35,7 +35,7 @@ TEST(self_changes) {
              SD_JSON_BUILD_PAIR_ARRAY("selfModifiableFields", SD_JSON_BUILD_STRING("notInHardCodedList")),
              /* change in order shouldn't affect things */
              SD_JSON_BUILD_PAIR_UNSIGNED("notInHardCodedList", 99999));
-        assert_se(user_record_self_changes_allowed(curr, new));
+        ASSERT_TRUE(user_record_self_changes_allowed(curr, new));
 
         /* default allowlisted */
         USER(&curr,
@@ -44,7 +44,7 @@ TEST(self_changes) {
         USER(&new,
              SD_JSON_BUILD_PAIR_STRING("userName", "test"),
              SD_JSON_BUILD_PAIR_STRING("realName", "New Name"));
-        assert_se(user_record_self_changes_allowed(curr, new));
+        ASSERT_TRUE(user_record_self_changes_allowed(curr, new));
 
         /* introduced new default allowlisted */
         USER(&curr,
@@ -52,7 +52,7 @@ TEST(self_changes) {
         USER(&new,
              SD_JSON_BUILD_PAIR_STRING("userName", "test"),
              SD_JSON_BUILD_PAIR_STRING("realName", "New Name"));
-        assert_se(user_record_self_changes_allowed(curr, new));
+        ASSERT_TRUE(user_record_self_changes_allowed(curr, new));
 
         /* introduced new not allowlisted */
         USER(&curr,
@@ -60,7 +60,7 @@ TEST(self_changes) {
         USER(&new,
              SD_JSON_BUILD_PAIR_STRING("userName", "test"),
              SD_JSON_BUILD_PAIR_UNSIGNED("notInHardCodedList", 99999));
-        assert_se(!user_record_self_changes_allowed(curr, new));
+        ASSERT_FALSE(user_record_self_changes_allowed(curr, new));
 
         /* privileged section: default allowlisted */
         USER(&curr,
@@ -71,7 +71,7 @@ TEST(self_changes) {
              SD_JSON_BUILD_PAIR_STRING("userName", "test"),
              SD_JSON_BUILD_PAIR_OBJECT("privileged",
                                     SD_JSON_BUILD_PAIR_STRING("passwordHint", "New Hint")));
-        assert_se(user_record_self_changes_allowed(curr, new));
+        ASSERT_TRUE(user_record_self_changes_allowed(curr, new));
 
         /* privileged section: not allowlisted */
         USER(&curr,
@@ -82,7 +82,7 @@ TEST(self_changes) {
              SD_JSON_BUILD_PAIR_STRING("userName", "test"),
              SD_JSON_BUILD_PAIR_OBJECT("privileged",
                                     SD_JSON_BUILD_PAIR_UNSIGNED("notInHardCodedList", 99999)));
-        assert_se(!user_record_self_changes_allowed(curr, new));
+        ASSERT_FALSE(user_record_self_changes_allowed(curr, new));
 
         /* privileged section: manually allowlisted */
         USER(&curr,
@@ -95,7 +95,7 @@ TEST(self_changes) {
              SD_JSON_BUILD_PAIR_ARRAY("selfModifiablePrivileged", SD_JSON_BUILD_STRING("notInHardCodedList")),
              SD_JSON_BUILD_PAIR_OBJECT("privileged",
                                     SD_JSON_BUILD_PAIR_UNSIGNED("notInHardCodedList", 99999)));
-        assert_se(user_record_self_changes_allowed(curr, new));
+        ASSERT_TRUE(user_record_self_changes_allowed(curr, new));
 }
 
 DEFINE_TEST_MAIN(LOG_INFO);