]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tests: add test for umask-util.h 12439/head
authorLennart Poettering <lennart@poettering.net>
Tue, 30 Apr 2019 07:53:09 +0000 (09:53 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 30 Apr 2019 07:53:09 +0000 (09:53 +0200)
src/test/meson.build
src/test/test-umask-util.c [new file with mode: 0644]

index e58e1cc73d3f90729f0b1ae7e7f8d1bcfb8eebcc..c68229b536a9bb5f552f7650a22f28031874eba9 100644 (file)
@@ -269,6 +269,10 @@ tests += [
          [],
          []],
 
+        [['src/test/test-umask-util.c'],
+         [],
+         []],
+
         [['src/test/test-proc-cmdline.c'],
          [],
          []],
diff --git a/src/test/test-umask-util.c b/src/test/test-umask-util.c
new file mode 100644 (file)
index 0000000..27f6b56
--- /dev/null
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include "tests.h"
+#include "umask-util.h"
+
+int main(int argc, char *argv[]) {
+        size_t n;
+        mode_t u;
+
+        test_setup_logging(LOG_DEBUG);
+
+        u = umask(0111);
+
+        n = 0;
+        RUN_WITH_UMASK(0123) {
+                assert_se(umask(000) == 0123);
+                n++;
+        }
+
+        assert_se(n == 1);
+        assert_se(umask(u) == 0111);
+
+        RUN_WITH_UMASK(0135) {
+                assert_se(umask(000) == 0135);
+                n++;
+        }
+
+        assert_se(n == 2);
+        assert_se(umask(0111) == u);
+
+        RUN_WITH_UMASK(0315) {
+                assert_se(umask(000) == 0315);
+                n++;
+                break;
+        }
+
+        assert_se(n == 3);
+        assert_se(umask(u) == 0111);
+
+        return EXIT_SUCCESS;
+}