]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: use safe_glob() at one more place
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 23 Jun 2025 00:00:20 +0000 (09:00 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 23 Jun 2025 14:11:44 +0000 (23:11 +0900)
This also makes the test use ASSERT_OK() and STRV_FOREACH() macros.

No functional change, just refactoring.

src/resolve/test-dns-packet.c

index 88c6cb127b8b0244d24bf1100647c48046885ed6..5e818106e8889a4d43ab524297ae67cdd23c0ccf 100644 (file)
@@ -9,6 +9,7 @@
 #include "resolved-dns-packet.h"
 #include "resolved-dns-rr.h"
 #include "siphash24.h"
+#include "strv.h"
 #include "tests.h"
 #include "unaligned.h"
 
@@ -119,29 +120,26 @@ static void test_dns_resource_record_get_cname_target(void) {
 }
 
 int main(int argc, char **argv) {
-        int N;
-        _cleanup_globfree_ glob_t g = {};
+        _cleanup_strv_free_ char **v = NULL;
         char **fnames;
 
         test_setup_logging(LOG_DEBUG);
 
-        if (argc >= 2) {
-                N = argc - 1;
+        if (argc >= 2)
                 fnames = argv + 1;
-        else {
+        else {
                 _cleanup_free_ char *pkts_glob = NULL;
-                assert_se(get_testdata_dir("test-resolve/*.pkts", &pkts_glob) >= 0);
-                assert_se(glob(pkts_glob, GLOB_NOSORT, NULL, &g) == 0);
-                N = g.gl_pathc;
-                fnames = g.gl_pathv;
+                ASSERT_OK(get_testdata_dir("test-resolve/*.pkts", &pkts_glob));
+                ASSERT_OK(safe_glob(pkts_glob, GLOB_NOSORT, &v));
+                fnames = v;
         }
 
-        for (int i = 0; i < N; i++) {
-                test_packet_from_file(fnames[i], false);
-                puts("");
-                test_packet_from_file(fnames[i], true);
-                if (i + 1 < N)
+        STRV_FOREACH(p, fnames) {
+                if (p != fnames)
                         puts("");
+                test_packet_from_file(*p, false);
+                puts("");
+                test_packet_from_file(*p, true);
         }
 
         test_dns_resource_record_get_cname_target();