tests: Add test_getresuid out of test_uid
authorAndreas Schneider <asn@samba.org>
Tue, 22 Sep 2015 15:21:11 +0000 (17:21 +0200)
committerAndreas Schneider <asn@samba.org>
Tue, 27 Oct 2015 13:55:22 +0000 (14:55 +0100)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
tests/CMakeLists.txt
tests/test_getresuid.c [moved from tests/test_uid.c with 59% similarity]

index 1741c088282f171e7cb31a63b2de33ed62b8593b..1add0c037e036627fc5b4b7e056537faa3c08fa5 100644 (file)
@@ -27,11 +27,13 @@ endif (HAVE_SETREUID)
 
 if (HAVE_SETRESUID)
     list(APPEND UWRAP_UID_TESTS test_setresuid)
+    if (HAVE_GETRESUID)
+        list(APPEND UWRAP_UID_TESTS test_getresuid)
+    endif (HAVE_GETRESUID)
 endif (HAVE_SETRESUID)
 
 set(UWRAP_TESTS
     ${UWRAP_UID_TESTS}
-    test_uid
     test_gid
     test_syscall
     test_syscall_uid
similarity index 59%
rename from tests/test_uid.c
rename to tests/test_getresuid.c
index ef01e3cfb377cec0412c41073370f8d5d5dd845e..291b703a9273940c3ce0f691fd007e5c51bd491c 100644 (file)
@@ -7,39 +7,39 @@
 
 #include <sys/types.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include <pwd.h>
 
-#ifdef HAVE_GETRESUID
 static void test_uwrap_getresuid(void **state)
 {
        int rc;
-       uid_t ru, eu, su;
+       uid_t u, ru, eu, su;
 
        (void) state; /* unused */
 
-       rc = setresuid(1, 2, -1);
-       assert_int_equal(rc, 0);
+       rc = setresuid(0x4444, 0x5555, -1);
+       assert_return_code(rc, errno);
 
-       ru = getuid();
-       assert_int_equal(ru, 1);
+       u = getuid();
+       assert_int_equal(u, 0x4444);
 
-       eu = geteuid();
-       assert_int_equal(eu, 2);
+       u = geteuid();
+       assert_int_equal(u, 0x5555);
 
        rc = getresuid(&ru, &eu, &su);
-       assert_int_equal(ru, 1);
-       assert_int_equal(eu, 2);
+       assert_return_code(rc, errno);
+
+       assert_int_equal(ru, 0x4444);
+       assert_int_equal(eu, 0x5555);
+       assert_int_equal(su, 0);
 }
-#endif
 
 int main(void) {
        int rc;
 
        const struct CMUnitTest uwrap_tests[] = {
-#ifdef HAVE_GETRESUID
                cmocka_unit_test(test_uwrap_getresuid),
-#endif
        };
 
        rc = cmocka_run_group_tests(uwrap_tests, NULL, NULL);