Merge pull request #853 from echampet/onclick
[mono.git] / mcs / class / Mono.Posix / Test / Mono.Unix / UnixGroupTest.cs
index 9888dff3016804219faded61eb5283f63d092e38..81e775e64b0d517b962928b2b4bd04301390aabf 100644 (file)
 
 using NUnit.Framework;
 using System;
+using System.Collections.Generic;
 using System.Configuration;
 using System.Diagnostics;
-using System.Xml;
 
 using Mono.Unix;
 
+using Group = Mono.Unix.Native.Group;
+using Syscall = Mono.Unix.Native.Syscall;
+
 namespace MonoTests.Mono.Unix {
 
        [TestFixture, Category ("NotDotNet")]
        public class UnixGroupTest
        {
                [Test]
+               [Category ("AndroidNotWorking")] // API 21 conditionally has setgrent in the NDK headers, but bionic doesn't export it
                public void ListAllGroups_ToString ()
                {
                        try {
                                Console.WriteLine ("Listing all groups");
-                               foreach (UnixGroupInfo group in UnixGroup.GetLocalGroups ()) {
+                               foreach (UnixGroupInfo group in UnixGroupInfo.GetLocalGroups ()) {
                                        Console.WriteLine ("\t{0}", group);
                                }
                        }
@@ -38,13 +42,14 @@ namespace MonoTests.Mono.Unix {
                }
 
                [Test]
-               // According to bug 72293, this may not work:
-               // On systems with NIS, it is possible to have multiple users in the passwd
-               // file with the same name, so the assertion above no longer holds.
-               [Category ("NotWorking")]
+               [Category ("AndroidNotWorking")] // API 21 conditionally has setgrent in the NDK headers, but bionic doesn't export it
                public void ReentrantConstructors ()
                {
-                       foreach (UnixGroupInfo group in UnixGroup.GetLocalGroups ()) {
+                       var seen = new Dictionary<string, object> ();
+                       foreach (UnixGroupInfo group in UnixGroupInfo.GetLocalGroups ()) {
+                               if (seen.ContainsKey (group.GroupName))
+                                       continue;
+                               seen.Add (group.GroupName, null);
                                try {
                                        UnixGroupInfo byName = new UnixGroupInfo (group.GroupName);
                                        UnixGroupInfo byId   = new UnixGroupInfo (group.GroupId);
@@ -62,12 +67,17 @@ namespace MonoTests.Mono.Unix {
                }
 
                [Test]
+               [Category ("AndroidNotWorking")] // API 21 conditionally has setgrent in the NDK headers, but bionic doesn't export it
                public void NonReentrantSyscalls ()
                {
-                       foreach (UnixGroupInfo group in UnixGroup.GetLocalGroups ()) {
+                       var seen = new Dictionary<string, object> ();
+                       foreach (UnixGroupInfo group in UnixGroupInfo.GetLocalGroups ()) {
+                               if (seen.ContainsKey (group.GroupName))
+                                       continue;
+                               seen.Add (group.GroupName, null);
                                try {
                                        Group byName = Syscall.getgrnam (group.GroupName);
-                                       Group byId   = Syscall.getgrgid (group.GroupId);
+                                       Group byId   = Syscall.getgrgid ((uint) group.GroupId);
 
                                        Assert.IsNotNull (byName, "#TNRS: access by name");
                                        Assert.IsNotNull (byId,   "#TNRS: access by gid");
@@ -88,6 +98,7 @@ namespace MonoTests.Mono.Unix {
                }
 
                [Test]
+               [Category ("AndroidNotWorking")] // API 21 conditionally has getgrnam_r in the NDK headers, but bionic doesn't export it
                public void InvalidGroups_Constructor_Name ()
                {
                        string[] badGroups = new string[]{"i'm bad", "so am i", "does-not-exist"};