about summary refs log tree commit diff
path: root/grp
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-06-08 11:44:48 +0000
committerUlrich Drepper <drepper@redhat.com>1999-06-08 11:44:48 +0000
commita7f7e9543d56cfa677a6ffd95dee7c29d3f0f626 (patch)
treea3231d5787173c5ec042d5f9f9c61efa155f6305 /grp
parent4807d0486a282a8a6fcc957b50d9a18f1509aca1 (diff)
downloadglibc-a7f7e9543d56cfa677a6ffd95dee7c29d3f0f626.tar.gz
glibc-a7f7e9543d56cfa677a6ffd95dee7c29d3f0f626.tar.xz
glibc-a7f7e9543d56cfa677a6ffd95dee7c29d3f0f626.zip
Test for fgetgrent function.
Diffstat (limited to 'grp')
-rw-r--r--grp/tst_fgetgrent.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/grp/tst_fgetgrent.c b/grp/tst_fgetgrent.c
new file mode 100644
index 0000000000..e7cd0d92b5
--- /dev/null
+++ b/grp/tst_fgetgrent.c
@@ -0,0 +1,111 @@
+/* Copyright (C) 1999 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Andreas Jaeger <aj@arthur.rhein-neckar.de>, 1999.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <grp.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+
+static int errors;
+
+static void
+write_users (FILE *f, int large_pos, int pos)
+{
+  int i;
+
+  if (pos == large_pos)
+    {
+      /* we need more than 2048 bytes for proper testing.  */
+      for (i = 0; i < 500; i++)
+	fprintf (f, ",user%03d", i);
+    }
+  fprintf (f, "\n");
+
+}
+
+static void
+write_group (const char *filename, int pos)
+{
+  FILE *f;
+
+  f = fopen (filename, "w");
+  fprintf (f, "one:x:0:one");
+  write_users (f, pos, 1);
+  fprintf (f, "two:x:1:two");
+  write_users (f, pos, 2);
+  fprintf (f, "three:x:2");
+  write_users (f, pos, 3);
+  fclose (f);
+}
+
+static void
+test_entry (const char *name, gid_t gid, struct group *g)
+{
+  if (!g)
+    {
+      printf ("Error: Entry is empty\n");
+      errors++;
+      return;
+    }
+
+  if ((g->gr_gid == gid) && (strcmp (g->gr_name, name) == 0))
+    printf ("Ok: %s: %d\n", g->gr_name, g->gr_gid);
+  else
+    {
+      printf ("Error: %s: %d should be: %s: %d\n", g->gr_name, g->gr_gid,
+	      name, gid);
+      errors++;
+    }
+}
+
+
+static void
+test_fgetgrent (const char *filename)
+{
+  struct group *g;
+  FILE *f;
+
+  f = fopen (filename, "r");
+
+  g = fgetgrent (f);
+  test_entry ("one", 0, g);
+  g = fgetgrent (f);
+  test_entry ("two", 1, g);
+  g = fgetgrent (f);
+  test_entry ("three", 2, g);
+  fclose (f);
+}
+
+
+int
+main (void)
+{
+  char *file = tmpnam (NULL);
+  int i;
+
+  for (i = 0; i < 4; i++)
+    {
+      printf ("Pass %d\n", i);
+      write_group (file, i);
+      test_fgetgrent (file);
+    }
+  remove (file);
+
+  return (errors != 0);
+}