File: AddressTest.cs

package info (click to toggle)
dbus-sharp 0.8.1-2.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 868 kB
  • sloc: cs: 7,690; sh: 494; makefile: 181
file content (80 lines) | stat: -rw-r--r-- 2,094 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright 2009 Alp Toker <alp@atoker.com>
// This software is made available under the MIT License
// See COPYING for details

using System;
using NUnit.Framework;
using DBus;
using System.Collections.Generic;

namespace DBus.Tests
{
	[TestFixture]
	public class AddressTest
	{
		[Test]
		[ExpectedException (typeof (InvalidAddressException))]
		public void ParseBad ()
		{
			Address.Parse ("lala");
		}

		[Test]
		public void ParseUnix ()
		{
			string addressText = @"unix:path=/var/run/dbus/system_bus_socket";

			AddressEntry[] addrs = Address.Parse (addressText);
			Assert.AreEqual (1, addrs.Length);

			AddressEntry entry = addrs[0];
			Assert.AreEqual (addressText, entry.ToString ());

			Assert.AreEqual ("unix", entry.Method);
			Assert.AreEqual (1, entry.Properties.Count);
			Assert.AreEqual ("/var/run/dbus/system_bus_socket", entry.Properties["path"]);
			Assert.AreEqual (UUID.Zero, entry.GUID);
		}

		[Test]
		public void ParseMany ()
		{
			string addressText = @"unix:path=/var/run/dbus/system_bus_socket;unix:path=/var/run/dbus/system_bus_socket";

			AddressEntry[] addrs = Address.Parse (addressText);
			Assert.AreEqual (2, addrs.Length);
			// TODO: Improve this test.
		}

		[Test]
		public void ParseGuid ()
		{
			string addressText = @"unix:abstract=/tmp/dbus-A4EzCUcGvg,guid=50ab33155e2cdd289e58c42a497ded1e";

			AddressEntry[] addrs = Address.Parse (addressText);
			Assert.AreEqual (1, addrs.Length);

			AddressEntry entry = addrs[0];
			Assert.AreEqual (addressText, entry.ToString ());

			Assert.AreEqual ("unix", entry.Method);
			Assert.AreEqual (1, entry.Properties.Count);

			UUID expectedId = UUID.Parse ("50ab33155e2cdd289e58c42a497ded1e");
			uint expectedTimestamp = 1232989470;
			Assert.AreEqual (expectedTimestamp, expectedId.UnixTimestamp);
			Assert.AreEqual (expectedId, entry.GUID);
		}

		[Test]
		public void UUIDEntropy ()
		{
			int n = 10000;
			DateTime dt = DateTime.MinValue;

			HashSet<int> hs = new HashSet<int> ();
			for (int i = 0 ; i != n ; i++)
				Assert.IsTrue (hs.Add (UUID.Generate (dt).GetHashCode ()));
		}
	}
}