#
# Test alias setting for the self handle
#

from sofiatest import exec_test
from servicetest import tp_name_prefix

import dbus

TEXT_TYPE = tp_name_prefix + '.Channel.Type.Text'

def test(q, bus, conn, sip_proxy):
    conn.Connect()
    q.expect('dbus-signal', signal='StatusChanged', args=[0, 1])

    self_handle = conn.GetSelfHandle()

    conn.Aliasing.SetAliases({self_handle: 'foo@bar.baz'})

    event = q.expect('dbus-signal', signal='AliasesChanged',
        args=[[(self_handle, u'foo@bar.baz')]])

    handle = conn.RequestHandles(1, ['sip:user@somewhere.com'])[0]
    conn.RequestChannel(TEXT_TYPE, 1, handle, True)

    event = q.expect('dbus-signal', signal='NewChannel')

    text_iface = dbus.Interface(bus.get_object(conn.bus_name, event.args[0]),
                               TEXT_TYPE)
    text_iface.Send(0, 'Hello')

    event = q.expect('sip-message')

    self_uri = conn.InspectHandles(1, [self_handle])[0]

    from_header = event.sip_message.headers['from'][0]
    assert from_header.startswith('"foo@bar.baz" <' + self_uri + '>'), from_header

if __name__ == '__main__':
    exec_test(test)

@@ -1069,16 +1069,365 @@
 header%0A%0A
+    # test if escaping and whitespace normalization works%0A    conn.Aliasing.SetAliases(%7Bself_handle: 'foo %22 bar %5C%5C%5Cr%5Cn baz%5Ct'%7D)%0A    text_iface.Send(0, 'Hello again')%0A    event = q.expect('sip-message')%0A    from_header = event.sip_message.headers%5B'from'%5D%5B0%5D%0A    assert from_header.startswith(r'%22foo %5C%22 bar %5C%5C baz %22 %3C' + self_uri + '%3E'), from_header%0A%0A
 if __nam

Test quoting and whitespace normalization of the display name