File: ObjectPathTest.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 (89 lines) | stat: -rw-r--r-- 2,078 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
81
82
83
84
85
86
87
88
89
// Copyright 2009 Alp Toker <alp@atoker.com>
// Copyright 2010 Alan McGovern <alan.mcgovern@gmail.com>
// This software is made available under the MIT License
// See COPYING for details

using System;
using NUnit.Framework;
using DBus;

namespace DBus.Tests
{
	[TestFixture]
	public class ObjectPathTest
	{
		[Test]
		[ExpectedException (typeof (ArgumentException))]
		public void InvalidStartingCharacter ()
		{
			// Paths must start with "/"
			new ObjectPath ("no_starting_slash");
		}

		[Test]
		[ExpectedException (typeof (ArgumentException))]
		public void InvalidEndingCharacter ()
		{
			// Paths must not end with "/"
			new ObjectPath ("/ends_with_slash/");
		}

		[Test]
		[ExpectedException (typeof (ArgumentException))]
		public void MultipleConsecutiveSlash ()
		{
			// Paths must not contains consecutive "/"
			new ObjectPath ("/foo//bar");
		}

		[Test]
		[ExpectedException (typeof (ArgumentException))]
		public void InvalidCharacters ()
		{
			// Paths must be in the range "[A-Z][a-z][0-9]_"
			new ObjectPath ("/?valid/path/invalid?/character.^");
		}

		[Test]
		public void ConstructorTest ()
		{
			var x = new ObjectPath ("/");
			Assert.AreEqual (x.ToString (), "/", "#1");
			Assert.AreEqual (x, ObjectPath.Root, "#2");

			x = new ObjectPath ("/this/01234567890/__Test__");
			Assert.AreEqual ("/this/01234567890/__Test__", x.ToString (), "#3");
		}

		[Test]
		public void Equality ()
		{
			string pathText = "/org/freedesktop/DBus";

			ObjectPath a = new ObjectPath (pathText);
			ObjectPath b = new ObjectPath (pathText);

			Assert.IsTrue (a.Equals (b));
			Assert.AreEqual (String.Empty.CompareTo (null), a.CompareTo (null));
			Assert.IsTrue (a == b);
			Assert.IsFalse (a != b);

			ObjectPath c = new ObjectPath (pathText + "/foo");
			Assert.IsFalse (a == c);
		}

		[Test]
		[ExpectedException (typeof (ArgumentNullException))]
		public void NullConstructor ()
		{
			new ObjectPath (null);
		}

		[Test]
		[ExpectedException (typeof (ArgumentException))]
		public void EmptyStringConstructor ()
		{
			new ObjectPath ("");
		}
	}
}