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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
// 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 DBus.Protocol;
namespace DBus.Tests
{
[TestFixture]
public class MatchRuleTest
{
[Test]
public void Parse ()
{
string ruleText = @"member='Lala'";
MatchRule rule = MatchRule.Parse (ruleText);
Assert.AreEqual (MessageType.All, rule.MessageType);
Assert.AreEqual (0, rule.Args.Count);
Assert.AreEqual (ruleText, rule.ToString ());
}
[Test]
public void ParsePathArgs ()
{
string ruleText = @"arg0='La',arg1path='/Foo'";
MatchRule rule = MatchRule.Parse (ruleText);
Assert.AreEqual (ruleText, rule.ToString ());
}
[Test]
public void CanonicalOrdering ()
{
string ruleText = @"arg0='La',arg5path='/bar',arg2='Fa',destination='org.ndesk.Recipient',interface='org.ndesk.ITest',arg1path='/foo'";
string sortedRuleText = @"interface='org.ndesk.ITest',destination='org.ndesk.Recipient',arg0='La',arg1path='/foo',arg2='Fa',arg5path='/bar'";
MatchRule rule = MatchRule.Parse (ruleText);
Assert.AreEqual (4, rule.Args.Count);
Assert.AreEqual (sortedRuleText, rule.ToString ());
}
// TODO: Should fail
/*
[Test]
public void ParseArgsPartiallyBad ()
{
string ruleText = @"arg0='A',arg4='Foo\'";
MatchRule.Parse (ruleText);
}
*/
// TODO: Should fail
/*
[Test]
[ExpectedException]
public void ParseRepeated ()
{
string ruleText = @"interface='org.ndesk.ITest',interface='org.ndesk.ITest2'";
MatchRule.Parse (ruleText);
}
*/
// TODO: Should fail
/*
[Test]
//[ExpectedException]
public void ParseArgsRepeated ()
{
string ruleText = @"arg0='A',arg0='A'";
MatchRule.Parse (ruleText);
}
*/
[Test]
public void ParseArgsMaxAllowed ()
{
string ruleText = @"arg63='Foo'";
MatchRule.Parse (ruleText);
}
[Test]
[ExpectedException]
public void ParseArgsMoreThanAllowed ()
{
string ruleText = @"arg64='Foo'";
MatchRule.Parse (ruleText);
}
[Test]
public void ParseArgs ()
{
string ruleText = @"arg5='F,o\'o\\\'\\',arg8=''";
MatchRule rule = MatchRule.Parse (ruleText);
Assert.AreEqual (MessageType.All, rule.MessageType);
Assert.AreEqual (2, rule.Args.Count);
//Assert.AreEqual (@"F,o'o\'\", rule.Args[5].Value);
//Assert.AreEqual (@"", rule.Args[8].Value);
Assert.AreEqual (ruleText, rule.ToString ());
}
}
}
|