about summary refs log tree commit diff
path: root/REORG.TODO/gshadow/tst-gshadow.c
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2017-06-08 15:39:03 -0400
committerZack Weinberg <zackw@panix.com>2017-06-08 15:39:03 -0400
commit5046dbb4a7eba5eccfd258f92f4735c9ffc8d069 (patch)
tree4470480d904b65cf14ca524f96f79eca818c3eaf /REORG.TODO/gshadow/tst-gshadow.c
parent199fc19d3aaaf57944ef036e15904febe877fc93 (diff)
downloadglibc-5046dbb4a7eba5eccfd258f92f4735c9ffc8d069.tar.gz
glibc-5046dbb4a7eba5eccfd258f92f4735c9ffc8d069.tar.xz
glibc-5046dbb4a7eba5eccfd258f92f4735c9ffc8d069.zip
Prepare for radical source tree reorganization. zack/build-layout-experiment
All top-level files and directories are moved into a temporary storage
directory, REORG.TODO, except for files that will certainly still
exist in their current form at top level when we're done (COPYING,
COPYING.LIB, LICENSES, NEWS, README), all old ChangeLog files (which
are moved to the new directory OldChangeLogs, instead), and the
generated file INSTALL (which is just deleted; in the new order, there
will be no generated files checked into version control).
Diffstat (limited to 'REORG.TODO/gshadow/tst-gshadow.c')
-rw-r--r--REORG.TODO/gshadow/tst-gshadow.c141
1 files changed, 141 insertions, 0 deletions
diff --git a/REORG.TODO/gshadow/tst-gshadow.c b/REORG.TODO/gshadow/tst-gshadow.c
new file mode 100644
index 0000000000..8b469b723d
--- /dev/null
+++ b/REORG.TODO/gshadow/tst-gshadow.c
@@ -0,0 +1,141 @@
+#include <gshadow.h>
+#include <stdio.h>
+#include <string.h>
+
+
+static const struct sgrp data[] =
+  {
+    { (char *) "one", (char *) "pwdone",
+      (char *[]) { (char *) "admoneone", (char *) "admonetwo",
+		  (char *) "admonethree", NULL },
+      (char *[]) { (char *) "memoneone", (char *) "memonetwo",
+		  (char *) "memonethree", NULL } },
+    { (char *) "two", (char *) "pwdtwo",
+      (char *[]) { (char *) "admtwoone", (char *) "admtwotwo", NULL },
+      (char *[]) { (char *) "memtwoone", (char *) "memtwotwo",
+		  (char *) "memtwothree", NULL } },
+    { (char *) "three", (char *) "pwdthree",
+      (char *[]) { (char *) "admthreeone", (char *) "admthreetwo", NULL },
+      (char *[]) { (char *) "memthreeone", (char *) "memthreetwo", NULL } },
+    { (char *) "four", (char *) "pwdfour",
+      (char *[]) { (char *) "admfourone", (char *) "admfourtwo", NULL },
+      (char *[]) { NULL } },
+    { (char *) "five", (char *) "pwdfive",
+      (char *[]) { NULL },
+      (char *[]) { (char *) "memfiveone", (char *) "memfivetwo", NULL } },
+  };
+#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 (putsgent (&data[i], fp) != 0)
+      {
+	printf ("putsgent call %zu failed\n", i + 1);
+	return 1;
+      }
+
+  rewind (fp);
+
+  int result = 0;
+  int seen = -1;
+  struct sgrp *g;
+  while ((g = fgetsgent (fp)) != NULL)
+    {
+      ++seen;
+      if (strcmp (g->sg_namp, data[seen].sg_namp) != 0)
+	{
+	  printf ("sg_namp of entry %d does not match: %s vs %s\n",
+		  seen + 1, g->sg_namp, data[seen].sg_namp);
+	  result = 1;
+	}
+      if (strcmp (g->sg_passwd, data[seen].sg_passwd) != 0)
+	{
+	  printf ("sg_passwd of entry %d does not match: %s vs %s\n",
+		  seen + 1, g->sg_passwd, data[seen].sg_passwd);
+	  result = 1;
+	}
+      if (g->sg_adm == NULL)
+	{
+	  printf ("sg_adm of entry %d is NULL\n", seen + 1);
+	  result = 1;
+	}
+      else
+	{
+	  int i = 1;
+	  char **sp1 = g->sg_adm;
+	  char **sp2 = data[seen].sg_adm;
+	  while (*sp1 != NULL && *sp2 != NULL)
+	    {
+	      if (strcmp (*sp1, *sp2) != 0)
+		{
+		  printf ("sg_adm[%d] of entry %d does not match: %s vs %s\n",
+			  i, seen + 1, *sp1, *sp2);
+		  result = 1;
+		}
+	      ++sp1;
+	      ++sp2;
+	      ++i;
+	    }
+	  if (*sp1 == NULL && *sp2 != NULL)
+	    {
+	      printf ("sg_adm of entry %d has too few entries\n", seen + 1);
+	      result = 1;
+	    }
+	  else if (*sp1 != NULL && *sp2 == NULL)
+	    {
+	      printf ("sg_adm of entry %d has too many entries\n", seen + 1);
+	      result = 1;
+	    }
+	}
+      if (g->sg_mem == NULL)
+	{
+	  printf ("sg_mem of entry %d is NULL\n", seen + 1);
+	  result = 1;
+	}
+      else
+	{
+	  int i = 1;
+	  char **sp1 = g->sg_mem;
+	  char **sp2 = data[seen].sg_mem;
+	  while (*sp1 != NULL && *sp2 != NULL)
+	    {
+	      if (strcmp (*sp1, *sp2) != 0)
+		{
+		  printf ("sg_mem[%d] of entry %d does not match: %s vs %s\n",
+			  i, seen + 1, *sp1, *sp2);
+		  result = 1;
+		}
+	      ++sp1;
+	      ++sp2;
+	      ++i;
+	    }
+	  if (*sp1 == NULL && *sp2 != NULL)
+	    {
+	      printf ("sg_mem of entry %d has too few entries\n", seen + 1);
+	      result = 1;
+	    }
+	  else if (*sp1 != NULL && *sp2 == NULL)
+	    {
+	      printf ("sg_mem of entry %d has too many entries\n", seen + 1);
+	      result = 1;
+	    }
+	}
+    }
+
+  fclose (fp);
+
+  return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"