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
|
// Copyright 2011 Bertrand Lorentz <bertrand.lorentz@gmail.com>
// This software is made available under the MIT License
// See COPYING for details
using System;
using NUnit.Framework;
using DBus;
using org.freedesktop.DBus;
namespace DBus.Tests
{
[TestFixture]
public class RenamedInterfaceTest
{
string bus_name = "org.dbussharp.restaurant";
ObjectPath path = new ObjectPath ("/org/dbussharp/restaurant");
[Test]
public void FirstInterface ()
{
var restaurant = new StandingRestaurant ();
Assert.AreEqual (Bus.Session.RequestName (bus_name), RequestNameReply.PrimaryOwner);
Bus.Session.Register (path, restaurant);
try {
Assert.AreEqual ("cheese", GetFood (false));
} finally {
Bus.Session.ReleaseName (bus_name);
Bus.Session.Unregister (path);
}
}
[Test]
public void SecondInterface ()
{
var restaurant = new SeatedRestaurant ();
Bus.Session.Register (path, restaurant);
Assert.AreEqual (Bus.Session.RequestName (bus_name), RequestNameReply.PrimaryOwner);
try {
Assert.AreEqual ("bacon", GetFood (true));
} finally {
Bus.Session.ReleaseName (bus_name);
Bus.Session.Unregister (path);
}
}
string GetFood (bool second)
{
IRestaurantBase restaurant = null;
if (second)
restaurant = Bus.Session.GetObject<IRestaurantv2> (bus_name, path);
else
restaurant = Bus.Session.GetObject<IRestaurant> (bus_name, path);
return restaurant.Food ();
}
}
interface IRestaurantBase { string Food (); }
[Interface ("org.dbussharp.restaurant")] interface IRestaurant : IRestaurantBase { }
[Interface ("org.dbussharp.restaurant.table")] interface IRestaurantv2 : IRestaurantBase { }
public class StandingRestaurant : IRestaurant
{
public string Food ()
{
return "cheese";
}
}
public class SeatedRestaurant : IRestaurantv2
{
public string Food ()
{
return "bacon";
}
}
}
|