3 // NUnit Test Cases for Mono.Unix.UnixGroup
6 // Jonathan Pryor (jonpryor@vt.edu)
8 // (C) 2004 Jonathan Pryor
11 using NUnit.Framework;
13 using System.Configuration;
14 using System.Diagnostics;
19 namespace MonoTests.Mono.Unix {
22 public class UnixGroupTest
25 public void ListAllGroups_ToString ()
28 Console.WriteLine ("Listing all groups");
29 foreach (UnixGroupInfo group in UnixGroup.GetLocalGroups ()) {
30 Console.WriteLine ("\t{0}", group);
35 string.Format ("#TLAU_TS: Exception listing local groups: {0}",
41 public void ReentrantConstructors ()
43 foreach (UnixGroupInfo group in UnixGroup.GetLocalGroups ()) {
45 UnixGroupInfo byName = new UnixGroupInfo (group.GroupName);
46 UnixGroupInfo byId = new UnixGroupInfo (group.GroupId);
48 Assert.AreEqual (group, byName, "#TRC: construct by name");
49 Assert.AreEqual (group, byId, "#TRC: construct by gid");
50 Assert.AreEqual (byName, byId, "#TRC: name == gid?");
54 string.Format ("#TRC: Exception constructing UnixGroupInfo: {0}",
61 public void NonReentrantSyscalls ()
63 foreach (UnixGroupInfo group in UnixGroup.GetLocalGroups ()) {
65 Group byName = Syscall.getgrnam (group.GroupName);
66 Group byId = Syscall.getgrgid (group.GroupId);
68 Assert.IsNotNull (byName, "#TNRS: access by name");
69 Assert.IsNotNull (byId, "#TNRS: access by gid");
71 UnixGroupInfo n = new UnixGroupInfo (byName);
72 UnixGroupInfo u = new UnixGroupInfo (byId);
74 Assert.AreEqual (group, n, "#TNRS: construct by name");
75 Assert.AreEqual (group, u, "#TNRS: construct by gid");
76 Assert.AreEqual (n, u, "#TNRS: name == gid?");
80 string.Format ("#TRC: Exception constructing UnixGroupInfo: {0}",
87 public void InvalidGroups_Constructor_Name ()
89 string[] badGroups = new string[]{"i'm bad", "so am i", "does-not-exist"};
90 foreach (string u in badGroups) {
92 new UnixGroupInfo (u);
93 Assert.Fail ("#TIUCN: exception not thrown");
95 catch (ArgumentException) {
99 Assert.Fail (string.Format ("#TIUCN: invalid exception thrown: " +
100 "expected ArgumentException, got {0}: {1}",
101 e.GetType().FullName, e.Message));
107 public void InvalidGroups_Syscall_Name ()
109 string[] badGroups = new string[]{"i'm bad", "so am i", "does-not-exist"};
110 foreach (string u in badGroups) {
112 Group pw = Syscall.getgrnam (u);
113 Assert.IsNull (pw, "#TIUSN: invalid groups should return null!");
115 catch (Exception e) {
116 Assert.Fail (string.Format ("#TIUCN: invalid exception thrown: " +
117 "expected null return, got {0}: {1}",
118 e.GetType().FullName, e.Message));
124 public void Equality ()
126 Group orig = new Group ();
127 Group mod = new Group ();
128 mod.gr_name = orig.gr_name = "some name";
129 mod.gr_passwd = orig.gr_passwd = "some passwd";
130 mod.gr_gid = orig.gr_gid = 500;
131 mod.gr_mem = orig.gr_mem = new string[]{"foo", "bar"};
133 Assert.AreEqual (orig, mod, "#TE: copies should be equal");
135 mod.gr_name = "another name";
136 Assert.IsFalse (orig.Equals (mod), "#TE: changes should be reflected");