[Galago-commits] r2680 - in trunk/galago-sharp: . galago tests

galago-commits at freedesktop.org galago-commits at freedesktop.org
Wed Apr 5 02:42:16 PDT 2006


Author: chipx86
Date: 2006-04-05 02:42:14 -0700 (Wed, 05 Apr 2006)
New Revision: 2680

Added:
   trunk/galago-sharp/galago/Person.custom
   trunk/galago-sharp/galago/Presence.custom
Modified:
   trunk/galago-sharp/ChangeLog
   trunk/galago-sharp/galago/Makefile.am
   trunk/galago-sharp/tests/unit-tests.cs
Log:
- Added Person.GetAccount and Person.GetAccounts() convenience functions that provide a default argument for query.
- Added a Person.SetIdle() convenience function that provides a default argument for the timestamp.
- Made the unit tests on par with the Python unit tests, except these are breaking with setting a custom priority account calculator.


Modified: trunk/galago-sharp/ChangeLog
===================================================================
--- trunk/galago-sharp/ChangeLog	2006-04-05 09:29:51 UTC (rev 2679)
+++ trunk/galago-sharp/ChangeLog	2006-04-05 09:42:14 UTC (rev 2680)
@@ -1,3 +1,16 @@
+Wed Apr 05 02:40:18 PDT 2006  Christian Hammond <chipx86 at chipx86.com>
+
+	A galago/Person.custom:
+	A galago/Presence.custom:
+	* galago/Makefile.am:
+	* tests/unit-tests.cs:
+	  - Added Person.GetAccount and Person.GetAccounts() convenience
+	    functions that provide a default argument for query.
+	  - Added a Person.SetIdle() convenience function that provides a
+	    default argument for the timestamp.
+	  - Made the unit tests on par with the Python unit tests, except these
+	    are breaking with setting a custom priority account calculator.
+
 Wed Apr 05 01:25:41 PDT 2006  Christian Hammond <chipx86 at chipx86.com>
 
 	* galago/galago-sharp.metadata:

Modified: trunk/galago-sharp/galago/Makefile.am
===================================================================
--- trunk/galago-sharp/galago/Makefile.am	2006-04-05 09:29:51 UTC (rev 2679)
+++ trunk/galago-sharp/galago/Makefile.am	2006-04-05 09:42:14 UTC (rev 2680)
@@ -29,6 +29,8 @@
 	Account.custom \
 	Global.custom \
 	Object.custom \
+	Person.custom \
+	Presence.custom \
 	Service.custom \
 	Status.custom
 

Added: trunk/galago-sharp/galago/Person.custom
===================================================================
--- trunk/galago-sharp/galago/Person.custom	2006-04-05 09:29:51 UTC (rev 2679)
+++ trunk/galago-sharp/galago/Person.custom	2006-04-05 09:42:14 UTC (rev 2680)
@@ -0,0 +1,10 @@
+		public Galago.Account GetAccount(Galago.Service service,
+		                                 string username)
+		{
+			return GetAccount(service, username, true);
+		}
+
+		public GLib.List GetAccounts()
+		{
+			return GetAccounts(true);
+		}

Added: trunk/galago-sharp/galago/Presence.custom
===================================================================
--- trunk/galago-sharp/galago/Presence.custom	2006-04-05 09:29:51 UTC (rev 2679)
+++ trunk/galago-sharp/galago/Presence.custom	2006-04-05 09:42:14 UTC (rev 2680)
@@ -0,0 +1,4 @@
+		public void SetIdle(bool idle)
+		{
+			SetIdle(idle, System.DateTime.Now);
+		}

Modified: trunk/galago-sharp/tests/unit-tests.cs
===================================================================
--- trunk/galago-sharp/tests/unit-tests.cs	2006-04-05 09:29:51 UTC (rev 2679)
+++ trunk/galago-sharp/tests/unit-tests.cs	2006-04-05 09:42:14 UTC (rev 2680)
@@ -2,15 +2,218 @@
 {
 	using NUnit.Framework;
 
+	public class Utils
+	{
+		public static Galago.Person MakeDummyPerson()
+		{
+			return Galago.Global.CreatePerson("dummy-person");
+		}
+
+		public static Galago.Service MakeDummyService()
+		{
+			return Galago.Global.CreateService("dummy-service",
+											   "Dummy Service", 0);
+		}
+
+		public static Galago.Account MakeDummyAccount()
+		{
+			return MakeDummyService().CreateAccount(MakeDummyPerson(),
+													"dummy-account");
+		}
+
+		public static Galago.Presence MakeDummyPresence()
+		{
+			return MakeDummyAccount().CreatePresence();
+		}
+	}
+
 	[TestFixture]
 	public class InitTest
 	{
 		[Test]
 		public void TestInitReinit()
 		{
-			Assert.IsTrue(Galago.Global.Init("check-galago-sharp"));
+			Assert.IsTrue(Galago.Global.Init("check-galago-sharp",
+											 Galago.InitFlags.Feed),
+						  "Unable to initialize Galago");
+			Assert.IsTrue(Galago.Global.IsInitted,
+						  "Galago.Global.Init succeeded, but IsInitted failed");
 			Galago.Global.Uninit();
-			Assert.IsTrue(Galago.Global.Init("check-galago-sharp"));
+			Assert.IsFalse(Galago.Global.IsInitted,
+						   "Still initted after Galago.Global.Uninit");
+
+			Assert.IsTrue(Galago.Global.Init("check-galago-sharp"),
+						  "Unable to initialize Galago");
+			Assert.IsTrue(Galago.Global.IsInitted,
+						  "Galago.Global.Init succeeded, but IsInitted failed");
+			Galago.Global.Uninit();
+			Assert.IsFalse(Galago.Global.IsInitted,
+						   "Still initted after Galago.Global.Uninit");
 		}
 	}
+
+	public class BaseTest
+	{
+		[SetUp]
+		public void Init()
+		{
+			Assert.IsTrue(Galago.Global.Init("check-galago-python",
+											 Galago.InitFlags.Feed),
+						  "Unable to initialize Galago");
+		}
+
+		[TearDown]
+		public void Uninit()
+		{
+			Galago.Global.Uninit();
+			Assert.IsFalse(Galago.Global.IsInitted,
+						   "Still initted after Galago.Global.Uninit");
+		}
+	}
+
+	[TestFixture]
+	public class ObjectTest : BaseTest
+	{
+		[Test]
+		public void TestObjectsEqual()
+		{
+			Assert.AreEqual(Utils.MakeDummyService(),
+							Utils.MakeDummyService());
+			Assert.AreEqual(Utils.MakeDummyAccount(),
+							Utils.MakeDummyAccount());
+			Assert.AreEqual(Utils.MakeDummyPresence(),
+							Utils.MakeDummyPresence());
+		}
+
+		[Test]
+		public void TestCreatePerson()
+		{
+			CheckObject(Galago.Global.CreatePerson("dummy-person"));
+			CheckObject(Galago.Global.CreatePerson());
+		}
+
+		[Test]
+		public void TestCreateService()
+		{
+			CheckObject(Galago.Global.CreateService("dummy-service-1",
+													"Dummy Service 1", 0));
+			CheckObject(Galago.Global.CreateService("dummy-service-2",
+													"Dummy Service 2"));
+		}
+
+		[Test]
+		public void TestCreateAccount()
+		{
+			Galago.Person person;
+			Galago.Service service;
+
+			person = Galago.Global.CreatePerson("dummy-person-x");
+			service = Galago.Global.CreateService("dummy-service-x",
+												  "Dummy Service");
+			CheckObject(person);
+			CheckObject(service);
+			CheckObject(service.CreateAccount(person, "dummy-account"));
+		}
+
+		[Test]
+		public void TestCreatePresence()
+		{
+			CheckObject(Utils.MakeDummyPresence());
+		}
+
+		private void CheckObject(Galago.Object obj)
+		{
+			Assert.IsNotNull(obj, "Resulting object is null");
+			Assert.IsFalse(obj.DBusPath == "",
+						   "Resulting object's D-BUS path is empty");
+		}
+	}
+
+	[TestFixture]
+	public class ServiceTest : BaseTest
+	{
+		[Test]
+		public void TestNormalize()
+		{
+			CheckNormalizeWith(0, "joebobsmith/home");
+			CheckNormalizeWith(Galago.ServiceFlags.PreserveSpaces,
+							   "joebob  smith/home");
+			CheckNormalizeWith(Galago.ServiceFlags.PreserveCase,
+							   "JoeBobSmith/Home");
+			CheckNormalizeWith(Galago.ServiceFlags.StripSlash,
+							   "joebobsmith");
+			CheckNormalizeWith(Galago.ServiceFlags.PreserveSpaces |
+							   Galago.ServiceFlags.PreserveCase |
+							   Galago.ServiceFlags.StripSlash,
+							   "JoeBob  Smith");
+		}
+
+		private void CheckNormalizeWith(Galago.ServiceFlags flags,
+										string expectedStr)
+		{
+			Galago.Service service =
+				Galago.Global.CreateService("test-service", "Test Service",
+											flags);
+			string username = service.Normalize("JoeBob  Smith/Home");
+			Assert.IsTrue(username == expectedStr);
+			service.Destroy();
+		}
+	}
+
+	[TestFixture]
+	public class PersonTest : BaseTest
+	{
+		[Test]
+		public void TestPriorityAccounts()
+		{
+			Galago.Person  person  = Utils.MakeDummyPerson();
+			Galago.Service service = Utils.MakeDummyService();
+			Galago.Presence presence;
+
+			Galago.Account account1 = service.CreateAccount(person,
+															"account-1");
+			presence = account1.CreatePresence();
+			presence.SetIdle(true);
+
+			Galago.Account account2 = service.CreateAccount(person,
+															"account-2");
+			presence = account2.CreatePresence();
+
+			Galago.Account priorityAccount = person.PriorityAccount;
+
+			Assert.IsNotNull(priorityAccount);
+			Assert.AreEqual(priorityAccount, account2);
+
+			// Test with a dummy handler.
+			Galago.Global.Core.CalcPriorityAccount += DummyCalcPriorityAccount;
+			priorityAccount = person.PriorityAccount;
+			Assert.IsNotNull(priorityAccount, "Priority account is null");
+			Assert.AreEqual(priorityAccount, account2,
+							"Priority account was not account 2");
+			Galago.Global.Core.CalcPriorityAccount -= DummyCalcPriorityAccount;
+
+			// Test with a dummy handler.
+			Galago.Global.Core.CalcPriorityAccount += CustomCalcPriorityAccount;
+			priorityAccount = person.PriorityAccount;
+			Assert.IsNotNull(priorityAccount, "Priority account is null");
+			Assert.AreEqual(priorityAccount, account1,
+							"Priority account was not account 1");
+			Galago.Global.Core.CalcPriorityAccount -= CustomCalcPriorityAccount;
+		}
+
+		private void DummyCalcPriorityAccount(
+			object obj, Galago.CalcPriorityAccountArgs args)
+		{
+			args.RetVal = null;
+		}
+
+		private void CustomCalcPriorityAccount(
+			object obj, Galago.CalcPriorityAccountArgs args)
+		{
+			GLib.List accounts = args.Person.GetAccounts();
+			Assert.IsTrue(accounts.Count > 0,
+						  "Returned accounts list is empty");
+			args.RetVal = accounts[0];
+		}
+	}
 }



More information about the galago-commits mailing list