apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject cvs commit: apr/test Makefile.in test_apr.h testall.c testuser.c
Date Sat, 07 Dec 2002 03:49:21 GMT
rbb         2002/12/06 19:49:21

  Modified:    test     Makefile.in test_apr.h testall.c testuser.c
  Log:
  Migrate testuser to the new test suite.
  
  Revision  Changes    Path
  1.130     +1 -5      apr/test/Makefile.in
  
  Index: Makefile.in
  ===================================================================
  RCS file: /home/cvs/apr/test/Makefile.in,v
  retrieving revision 1.129
  retrieving revision 1.130
  diff -u -r1.129 -r1.130
  --- Makefile.in	7 Dec 2002 02:59:20 -0000	1.129
  +++ Makefile.in	7 Dec 2002 03:49:21 -0000	1.130
  @@ -15,7 +15,6 @@
   	testlockperf@EXEEXT@ \
   	testshmproducer@EXEEXT@ \
   	testshmconsumer@EXEEXT@ \
  -	testuser@EXEEXT@ \
   	testatomic@EXEEXT@ \
   	testmutexscope@EXEEXT@ \
   	testall@EXEEXT@
  @@ -88,9 +87,6 @@
   testshmconsumer@EXEEXT@: testshmconsumer.lo $(LOCAL_LIBS)
   	$(LINK) testshmconsumer.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
  -testuser@EXEEXT@: testuser.lo $(LOCAL_LIBS)
  -	$(LINK) testuser.lo $(LOCAL_LIBS) $(ALL_LIBS)
  -
   testprocmutex@EXEEXT@: testprocmutex.lo $(LOCAL_LIBS)
   	$(LINK) testprocmutex.lo $(LOCAL_LIBS) $(ALL_LIBS)
   
  @@ -108,7 +104,7 @@
   	testfmt.lo testfile.lo testdir.lo testfileinfo.lo testrand.lo \
   	testdso.lo testoc.lo testdup.lo testsockets.lo testproc.lo \
   	testpoll.lo testlock.lo testsockopt.lo testpipe.lo testthread.lo \
  -	testhash.lo testargs.lo testnames.lo
  +	testhash.lo testargs.lo testnames.lo testuser.lo
   
   testall: $(TESTS) mod_test.la libmod_test.la occhild@EXEEXT@ \
   	 CuTest.lo proc_child@EXEEXT@ $(LOCAL_LIBS)
  
  
  
  1.38      +1 -0      apr/test/test_apr.h
  
  Index: test_apr.h
  ===================================================================
  RCS file: /home/cvs/apr/test/test_apr.h,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- test_apr.h	7 Dec 2002 02:59:20 -0000	1.37
  +++ test_apr.h	7 Dec 2002 03:49:21 -0000	1.38
  @@ -93,6 +93,7 @@
   CuSuite *testthread(void);
   CuSuite *testgetopt(void);
   CuSuite *testnames(void);
  +CuSuite *testuser(void);
   
   /* Assert that RV is an APR_SUCCESS value; else fail giving strerror
    * for RV and CONTEXT message. */
  
  
  
  1.35      +1 -0      apr/test/testall.c
  
  Index: testall.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testall.c,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- testall.c	7 Dec 2002 02:59:20 -0000	1.34
  +++ testall.c	7 Dec 2002 03:49:21 -0000	1.35
  @@ -101,6 +101,7 @@
       {"testthread", testthread},
       {"testargs", testgetopt},
       {"testnames", testnames},
  +    {"testuser", testuser},
       {"LastTest", NULL}
   };
   
  
  
  
  1.8       +76 -94    apr/test/testuser.c
  
  Index: testuser.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testuser.c,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- testuser.c	20 Nov 2002 03:50:22 -0000	1.7
  +++ testuser.c	7 Dec 2002 03:49:21 -0000	1.8
  @@ -52,107 +52,89 @@
    * <http://www.apache.org/>.
    */
   
  -#include <stdio.h>
  -#include <stdlib.h>
  -
  +#include "test_apr.h"
   #include "apr_errno.h"
   #include "apr_general.h"
   #include "apr_user.h"
   
  -#if !APR_HAS_USER
  -int main(void)
  +#if APR_HAS_USER
  +static void uid_current(CuTest *tc)
   {
  -    fprintf(stderr,
  -            "This program won't work on this platform because !APR_HAS_USER.\n");
  -    return 0;
  +    apr_uid_t uid = -1;
  +    apr_gid_t gid = -1;
  +    apr_status_t rv;
  +
  +    rv = apr_uid_current(&uid, &gid, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssert(tc, "uid not modified", uid != -1);
  +    CuAssert(tc, "gid not modified", gid != -1);
   }
  -#else
  -int main(int argc, char *argv[])
  +
  +static void username(CuTest *tc)
  +{
  +    apr_uid_t uid = -1;
  +    apr_gid_t gid = -1;
  +    apr_uid_t retreived_uid = -1;
  +    apr_gid_t retreived_gid = -1;
  +    apr_status_t rv;
  +    char *uname = NULL;
  +
  +    rv = apr_uid_current(&uid, &gid, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssert(tc, "uid not modified", uid != -1);
  +    CuAssert(tc, "gid not modified", gid != -1);
  +
  +    rv = apr_uid_name_get(&uname, uid, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssertPtrNotNull(tc, uname);
  +
  +    rv = apr_uid_get(&retreived_uid, &retreived_gid, uname, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +
  +    CuAssertIntEquals(tc, uid, retreived_uid);
  +    CuAssertIntEquals(tc, gid, retreived_gid);
  +}
  +
  +static void groupname(CuTest *tc)
   {
  -    apr_pool_t *p;
  +    apr_uid_t uid = -1;
  +    apr_gid_t gid = -1;
  +    apr_gid_t retreived_gid = -1;
       apr_status_t rv;
  -    char msgbuf[80];
  -    char *groupname;
  -    char *username;
  -    char *homedir;
  -    apr_uid_t userid;
  -    apr_gid_t groupid, newgroupid;
  -
  -    if (apr_initialize() != APR_SUCCESS) {
  -        fprintf(stderr, "Something went wrong\n");
  -        exit(-1);
  -    }
  -    atexit(apr_terminate);
  -
  -    if (apr_pool_create(&p, NULL) != APR_SUCCESS) {
  -        fprintf(stderr, "Something went wrong\n");
  -        exit(-1);
  -    }
  -
  -    if (argc != 2) {
  -        fprintf(stderr,
  -                "optional: %s username\n",
  -                argv[0]);
  -        if ((rv = apr_uid_current(&userid, &groupid, p)) != APR_SUCCESS) {
  -            fprintf(stderr, "apr_uid_current failed: %s\n",
  -                    apr_strerror(rv, msgbuf, sizeof(msgbuf)));
  -            exit(-1);
  -        }
  -        apr_uid_name_get(&username, userid, p);
  -        if (rv != APR_SUCCESS) {
  -            fprintf(stderr, "apr_uid_name_get(,,) failed: %s\n",
  -                    apr_strerror(rv, msgbuf, sizeof(msgbuf)));
  -            exit(-1);
  -        }
  -    }
  -    else {
  -        username = argv[1];
  -
  -        rv = apr_uid_get(&userid, &groupid, username, p);
  -        if (rv != APR_SUCCESS) {
  -            fprintf(stderr, "apr_uid_get(,,%s,) failed: %s\n",
  -                    username,
  -                    apr_strerror(rv, msgbuf, sizeof(msgbuf)));
  -            exit(-1);
  -        }
  -    }
  -
  -    rv = apr_gid_name_get(&groupname, groupid, p);
  -    if (rv != APR_SUCCESS)
  -        groupname = "(none)";
  -
  -    rv = apr_gid_get(&newgroupid, groupname, p);
  -    if (rv != APR_SUCCESS) {
  -        fprintf(stderr, "apr_gid_get(,%s,) failed: %s\n",
  -                groupname,
  -                apr_strerror(rv, msgbuf, sizeof msgbuf));
  -        exit(-1);
  -    }
  -
  -    if (groupid != newgroupid) {
  -        fprintf(stderr, "oops, we got a different result for the "
  -                "group name/id mapping\n");
  -        /* whoever hits this problem gets to figure out how to 
  -         * portably display groupid and newgroupid :) 
  -         */
  -        fprintf(stderr, "group: %s\n",
  -                groupname);
  -    }
  -
  -    printf("user/group ids for %s: %d/%d\n",
  -           username,
  -           (int)userid, (int)groupid);
  -
  -    rv = apr_uid_homepath_get(&homedir, username, p);
  -    if (rv != APR_SUCCESS) {
  -        fprintf(stderr, "apr_uid_homepath_get(,%s,) failed: %s\n",
  -                username,
  -                apr_strerror(rv, msgbuf, sizeof(msgbuf)));
  -        exit(-1);
  -    }
  -    printf("home directory for %s (member of %s) is:\n`%s'\n",
  -           username, groupname, homedir);
  +    char *gname = NULL;
  +
  +    rv = apr_uid_current(&uid, &gid, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssert(tc, "uid not modified", uid != -1);
  +    CuAssert(tc, "gid not modified", gid != -1);
  +
  +    rv = apr_gid_name_get(&gname, gid, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssertPtrNotNull(tc, gname);
  +
  +    rv = apr_gid_get(&retreived_gid, gname, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +
  +    CuAssertIntEquals(tc, gid, retreived_gid);
  +}
  +#else
  +static void threads_not_impl(CuTest *tc)
  +{
  +    CuNotImpl(tc, "Users not implemented on this platform");
  +}
  +#endif
  +
  +CuSuite *testuser(void)
  +{
  +    CuSuite *suite = CuSuiteNew("Users");
  +
  +#if !APR_HAS_USER
  +    SUITE_ADD_TEST(suite, users_not_impl);
  +#else
  +    SUITE_ADD_TEST(suite, uid_current);
  +    SUITE_ADD_TEST(suite, username);
  +    SUITE_ADD_TEST(suite, groupname);
  +#endif
   
  -    return 0;
  +    return suite;
   }
  -#endif /* APR_HAS_USER */
  
  
  

Mime
View raw message