Changeset bf5e6a2 for tester.c


Ignore:
Timestamp:
Jul 9, 2011, 4:01:01 PM (10 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.8, release-1.9
Children:
14c9e05
Parents:
c0c48d14
git-author:
David Benjamin <davidben@mit.edu> (06/25/11 06:25:43)
git-committer:
David Benjamin <davidben@mit.edu> (07/09/11 16:01:01)
Message:
Add unit tests for owl_util_makepath

Stress all the relevant cases, including ones the previous code did not
handle.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tester.c

    r7feba19 rbf5e6a2  
    44#undef WINDOW
    55
     6#include <errno.h>
    67#include <unistd.h>
     8#include <pwd.h>
     9#include <stdio.h>
    710#include <stdlib.h>
     11#include <string.h>
     12#include <sys/types.h>
    813
    914#undef instr
     
    131136{
    132137  int numfailed=0;
    133   char *s;
     138  const char *home;
     139  char *s, *path;
     140  struct passwd *pw;
    134141
    135142  printf("# BEGIN testing owl_util\n");
     
    253260
    254261
     262  s = owl_util_makepath("foo/bar");
     263  FAIL_UNLESS("makepath foo/bar", !strcmp("foo/bar", s));
     264  g_free(s);
     265  s = owl_util_makepath("//foo///bar");
     266  FAIL_UNLESS("makepath //foo///bar", !strcmp("/foo/bar", s));
     267  g_free(s);
     268  s = owl_util_makepath("foo/~//bar/");
     269  FAIL_UNLESS("makepath foo/~//bar/", !strcmp("foo/~/bar/", s));
     270  g_free(s);
     271  s = owl_util_makepath("~thisuserhadreallybetternotexist/foobar/");
     272  FAIL_UNLESS("makepath ~thisuserhadreallybetternotexist/foobar/",
     273              !strcmp("~thisuserhadreallybetternotexist/foobar/", s));
     274  g_free(s);
     275
     276  errno = 0;
     277  pw = getpwuid(getuid());
     278  if (pw) {
     279    home = pw->pw_dir;
     280  } else {
     281    /* Just make some noise so we notice. */
     282    home = "<WHAT>";
     283    fprintf(stderr, "getpwuid: %s", errno ? strerror(errno) : "No such user");
     284  }
     285  s = owl_util_makepath("~");
     286  FAIL_UNLESS("makepath ~", !strcmp(home, s));
     287  g_free(s);
     288
     289  path = g_strconcat(home, "/foo/bar/baz", NULL);
     290  s = owl_util_makepath("~///foo/bar//baz");
     291  FAIL_UNLESS("makepath ~///foo/bar//baz", !strcmp(path, s));
     292  g_free(s);
     293  g_free(path);
     294
     295  errno = 0;
     296  pw = getpwnam("root");
     297  if (pw) {
     298    home = pw->pw_dir;
     299  } else {
     300    /* Just make some noise so we notice. */
     301    home = "<WHAT>";
     302    fprintf(stderr, "getpwnam: %s", errno ? strerror(errno) : "No such user");
     303  }
     304
     305  s = owl_util_makepath("~root");
     306  FAIL_UNLESS("makepath ~root", !strcmp(home, s));
     307  g_free(s);
     308
     309  path = g_strconcat(home, "/foo/bar/baz", NULL);
     310  s = owl_util_makepath("~root///foo/bar//baz");
     311  FAIL_UNLESS("makepath ~root///foo/bar//baz", !strcmp(path, s));
     312  g_free(s);
     313  g_free(path);
    255314
    256315  /* if (numfailed) printf("*** WARNING: failures encountered with owl_util\n"); */
Note: See TracChangeset for help on using the changeset viewer.