summary refs log tree commit diff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2009-04-23 18:58:19 +0000
committerUlrich Drepper <drepper@redhat.com>2009-04-23 18:58:19 +0000
commit3b055b478685ccae785e656bdb94eedcdb6f1026 (patch)
treef7b255979a9adc62bd5e7f223340840422816296
parent829fea46179b8d5cf25f8eae0b78550e3539ad60 (diff)
downloadglibc-3b055b478685ccae785e656bdb94eedcdb6f1026.tar.gz
glibc-3b055b478685ccae785e656bdb94eedcdb6f1026.tar.xz
glibc-3b055b478685ccae785e656bdb94eedcdb6f1026.zip
* shadow/Makefile (tests): Add tst-shadow.
	* shadow/tst-shadow.c: New file.

	(public_sET_STATe): Pretty printing.
-rw-r--r--ChangeLog5
-rw-r--r--gshadow/tst-gshadow.c9
-rw-r--r--shadow/Makefile4
-rw-r--r--shadow/tst-shadow.c84
4 files changed, 97 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 85a7d240d0..b961433ba0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2009-04-23  Ulrich Drepper  <drepper@redhat.com>
 
+	* shadow/Makefile (tests): Add tst-shadow.
+	* shadow/tst-shadow.c: New file.
+
 	[BZ #9955]
 	* gshadow/Makefile: New file.
 	* gshadow/Versions: New file.
@@ -100,7 +103,7 @@
 	* malloc/arena.c (ptmalloc_init): Load hook variable into variable
 	before test and force into register.
 	* malloc/hooks.c (top_check): Likewise.
-	(public_s_ET_STATe): Pretty printing.
+	(public_sET_STATe): Pretty printing.
 
 	* resolv/res_send.c (send_dg): Don't just ignore the result we got
 	in case we only receive one reply in single-request mode.
diff --git a/gshadow/tst-gshadow.c b/gshadow/tst-gshadow.c
index 8c26a486a7..8b469b723d 100644
--- a/gshadow/tst-gshadow.c
+++ b/gshadow/tst-gshadow.c
@@ -27,10 +27,10 @@ static const struct sgrp data[] =
 #define ndata (sizeof (data) / sizeof (data[0]))
 
 
-int
-main (void)
+static int
+do_test (void)
 {
-  FILE *fp = fopen ("/tmp/aaa", "w+");//tmpfile ();
+  FILE *fp = tmpfile ();
   if (fp == NULL)
     {
       puts ("cannot open temporary file");
@@ -136,3 +136,6 @@ main (void)
 
   return result;
 }
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/shadow/Makefile b/shadow/Makefile
index cc0efaff6c..4755fab04a 100644
--- a/shadow/Makefile
+++ b/shadow/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1996, 2003, 2004 Free Software Foundation, Inc.
+# Copyright (C) 1996, 2003, 2004, 2009 Free Software Foundation, Inc.
 # This file is part of the GNU C Library.
 
 # The GNU C Library is free software; you can redistribute it and/or
@@ -26,6 +26,8 @@ routines	= getspent getspnam sgetspent fgetspent putspent \
 		  getspent_r getspnam_r sgetspent_r fgetspent_r \
 		  lckpwdf
 
+tests = tst-shadow
+
 CFLAGS-getspent_r.c = -fexceptions
 CFLAGS-getspent.c = -fexceptions
 CFLAGS-fgetspent.c = -fexceptions
diff --git a/shadow/tst-shadow.c b/shadow/tst-shadow.c
new file mode 100644
index 0000000000..48f7167baa
--- /dev/null
+++ b/shadow/tst-shadow.c
@@ -0,0 +1,84 @@
+#include <shadow.h>
+#include <stdio.h>
+#include <string.h>
+
+
+static const struct spwd data[] =
+  {
+    { (char *) "one", (char *) "pwdone", 1, 2, 3, 4, 5, 6, 7 },
+    { (char *) "two", (char *) "pwdtwo", 11, 12, 13, 14, 15, 16, 17 },
+    { (char *) "three", (char *) "pwdthree", -1, 22, 23, 24, 25, 26, 27 },
+    { (char *) "four", (char *) "pwdfour", 31, -1, 33, 34, 35, 36, 37 },
+    { (char *) "five", (char *) "pwdfive", 41, 42, -1, 44, 45, 46, 47 },
+    { (char *) "six", (char *) "pwdsix", 51, 52, 53, -1, 55, 56, 57 },
+    { (char *) "seven", (char *) "pwdseven", 61, 62, 63, 64, -1, 66, 67 },
+    { (char *) "eight", (char *) "pwdeigth", 71, 72, 73, 74, 75, -1, 77 },
+    { (char *) "nine", (char *) "pwdnine", 81, 82, 83, 84, 85, 86, ~0ul },
+  };
+#define ndata (sizeof (data) / sizeof (data[0]))
+
+
+static int
+do_test (void)
+{
+  FILE *fp = tmpfile ();
+  if (fp == NULL)
+    {
+      puts ("cannot open temporary file");
+      return 1;
+    }
+
+  for (size_t i = 0; i < ndata; ++i)
+    if (putspent (&data[i], fp) != 0)
+      {
+	printf ("putspent call %zu failed\n", i + 1);
+	return 1;
+      }
+
+  rewind (fp);
+
+  int result = 0;
+  int seen = -1;
+  struct spwd *p;
+  while ((p = fgetspent (fp)) != NULL)
+    {
+      ++seen;
+      if (strcmp (p->sp_namp, data[seen].sp_namp) != 0)
+	{
+	  printf ("sp_namp of entry %d does not match: %s vs %s\n",
+		  seen + 1, p->sp_namp, data[seen].sp_namp);
+	  result = 1;
+	}
+      if (strcmp (p->sp_pwdp, data[seen].sp_pwdp) != 0)
+	{
+	  printf ("sp_pwdp of entry %d does not match: %s vs %s\n",
+		  seen + 1, p->sp_pwdp, data[seen].sp_pwdp);
+	  result = 1;
+	}
+#define T(f) \
+      if (p->f != data[seen].f)						      \
+	{								      \
+	  printf ("%s of entry %d wrong: %ld vs %ld\n",			      \
+		  #f, seen + 1, p->f, data[seen].f);			      \
+	  result = 1;							      \
+	}
+      T (sp_lstchg);
+      T (sp_min);
+      T (sp_max);
+      T (sp_warn);
+      T (sp_expire);
+      if (p->sp_flag != data[seen].sp_flag)
+	{
+	  printf ("sp_flag of entry %d wrong: %lu vs %lu\n",
+		  seen + 1, p->sp_flag, data[seen].sp_flag);
+	  result = 1;
+	}
+    }
+
+  fclose (fp);
+
+  return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"