summaryrefslogtreecommitdiff
path: root/tests/message.c
blob: 4fc08a99722bbdbbf2c54fcd4bc7898b305156cb (plain)
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
/* Tests of TpMessage
 *
 * Copyright © 2013 Collabora Ltd. <http://www.collabora.co.uk/>
 *
 * Copying and distribution of this file, with or without modification,
 * are permitted in any medium without royalty provided the copyright
 * notice and this notice are preserved.
 */

#include "tests/lib/util.h"

static void
test_delivery_report_with_body (void)
{
  TpMessage *message = tp_client_message_new ();
  guint i;
  gchar *text;
  TpChannelTextMessageFlags flags;

  g_test_bug ("61254");

  tp_message_set_uint32 (message, 0, "message-type",
      TP_CHANNEL_TEXT_MESSAGE_TYPE_DELIVERY_REPORT);
  tp_message_set_uint32 (message, 0, "delivery-status",
      TP_DELIVERY_STATUS_PERMANENTLY_FAILED);

  /* message from server (alternative in English) */
  i = tp_message_append_part (message);
  tp_message_set_string (message, i, "alternative", "404");
  tp_message_set_string (message, i, "content-type", "text/plain");
  tp_message_set_string (message, i, "lang", "en");
  tp_message_set_string (message, i, "content",
      "I have no contact with that name");

  /* message from server (alternative in German) */
  i = tp_message_append_part (message);
  tp_message_set_string (message, i, "alternative", "404");
  tp_message_set_string (message, i, "content-type", "text/plain");
  tp_message_set_string (message, i, "lang", "de");
  tp_message_set_string (message, i, "content",
      "Ich habe keinen Kontakt mit diesem Namen");

  text = tp_message_to_text (message, &flags);

  g_assert (text != NULL);
  /* tp_message_to_text should only pick one language, and it's arbitrarily the
   * first. */
  g_assert_cmpstr (text, ==, "I have no contact with that name");

  /* This is a delivery report, so old clients should know that there's
   * something more to the message than just a message.
   */
  g_assert_cmpuint (flags, ==, TP_CHANNEL_TEXT_MESSAGE_FLAG_NON_TEXT_CONTENT);

  g_free (text);
  g_object_unref (message);
}

int
main (int argc,
      char **argv)
{
  tp_tests_init (&argc, &argv);
  g_test_bug_base ("http://bugs.freedesktop.org/show_bug.cgi?id=");

  g_test_add_func ("/text-channel/delivery-report-with-body",
      test_delivery_report_with_body);

  return g_test_run ();
}