public void NonReentrantSyscalls() { foreach (UnixGroupInfo group in UnixGroupInfo.GetLocalGroups()) { try { Group byName = Syscall.getgrnam(group.GroupName); Group byId = Syscall.getgrgid((uint)group.GroupId); Assert.IsNotNull(byName, "#TNRS: access by name"); Assert.IsNotNull(byId, "#TNRS: access by gid"); UnixGroupInfo n = new UnixGroupInfo(byName); UnixGroupInfo u = new UnixGroupInfo(byId); Assert.AreEqual(group, n, "#TNRS: construct by name"); Assert.AreEqual(group, u, "#TNRS: construct by gid"); Assert.AreEqual(n, u, "#TNRS: name == gid?"); } catch (Exception e) { Assert.Fail( string.Format("#TRC: Exception constructing UnixGroupInfo: {0}", e.ToString())); } } }
[Category("AndroidNotWorking")] // API 21 conditionally has setgrent in the NDK headers, but bionic doesn't export it public void NonReentrantSyscalls() { 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((uint)group.GroupId); Assert.IsNotNull(byName, "#TNRS: access by name"); Assert.IsNotNull(byId, "#TNRS: access by gid"); UnixGroupInfo n = new UnixGroupInfo(byName); UnixGroupInfo u = new UnixGroupInfo(byId); Assert.AreEqual(group, n, "#TNRS: construct by name"); Assert.AreEqual(group, u, "#TNRS: construct by gid"); Assert.AreEqual(n, u, "#TNRS: name == gid?"); } catch (Exception e) { Assert.Fail( string.Format("#TRC: Exception constructing UnixGroupInfo: {0}", e.ToString())); } } }
public void InvalidUsers_Syscall_Name() { string[] badUsers = new string[] { "i'm bad", "so am i", "does-not-exist" }; foreach (string u in badUsers) { try { Passwd pw = Syscall.getpwnam(u); Assert.IsNull(pw, "#TIUSN: invalid users should return null!"); } catch (Exception e) { Assert.Fail(string.Format("#TIUCN: invalid exception thrown: " + "expected ArgumentException, got {0}: {1}", e.GetType().FullName, e.Message)); } } }
public void NonReentrantSyscalls() { ArrayList user_ids = new ArrayList(4); IList users = UnixUserInfo.GetLocalUsers(); foreach (UnixUserInfo user in users) { try { Passwd byName = Syscall.getpwnam(user.UserName); Assert.IsNotNull(byName, "#TNRS: access by name"); UnixUserInfo n = new UnixUserInfo(byName); Assert.AreEqual(user, n, "#TNRS: construct by name"); if (!user_ids.Contains(user.UserId)) { user_ids.Add(user.UserId); } } catch (Exception e) { Assert.Fail( string.Format("#TNRS: Exception constructing UnixUserInfo (string): {0}", e.ToString())); } } foreach (long uid in user_ids) { try { Passwd byId = Syscall.getpwuid(Convert.ToUInt32(uid)); Assert.IsNotNull(byId, "#TNRS: access by uid"); UnixUserInfo u = new UnixUserInfo(byId); Assert.IsTrue(users.Contains(u), "TNRS: construct by uid"); } catch (Exception e) { Assert.Fail( string.Format("#TNRS: Exception constructing UnixUserInfo (uint): {0}", e.ToString())); } } }