~singpolyma/biboumi

ref: f370ce3a80ef77f58a13b0328aa09c7becbf4f0e biboumi/tests/jid.cpp -rw-r--r-- 1.6 KiB
f370ce3aStephen Paul Weber Add CI 8 months ago
                                                                                
3c1889fb Florent Le Coz
0ab40dc1 louiz’
3c1889fb Florent Le Coz
fef585ad louiz’
3c1889fb Florent Le Coz
fef585ad louiz’
3c1889fb Florent Le Coz
4a583c7b louiz’
3c1889fb Florent Le Coz
fef585ad louiz’
3c1889fb Florent Le Coz
fef585ad louiz’
3c1889fb Florent Le Coz
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
#include "catch.hpp"

#include <xmpp/jid.hpp>
#include <biboumi.h>

TEST_CASE("Jid")
{
  Jid jid1("♥@ツ.coucou/coucou@coucou/coucou");
  CHECK(jid1.local == "♥");
  CHECK(jid1.domain == "ツ.coucou");
  CHECK(jid1.resource == "coucou@coucou/coucou");

  // Domain and resource
  Jid jid2("ツ.coucou/coucou@coucou/coucou");
  CHECK(jid2.local == "");
  CHECK(jid2.domain == "ツ.coucou");
  CHECK(jid2.resource == "coucou@coucou/coucou");
}

TEST_CASE("jidprep")
{
  // Jidprep
  const std::string badjid("~zigougou™@EpiK-7D9D1FDE.poez.io/Boujour/coucou/slt™");
#ifdef LIBIDN_FOUND
  const std::string correctjid = jidprep(badjid);
  CHECK(correctjid == "~zigougoutm@epik-7d9d1fde.poez.io/Boujour/coucou/sltTM");
  // Check that the cache does not break things when we prep the same string
  // multiple times
  CHECK(jidprep(badjid) == "~zigougoutm@epik-7d9d1fde.poez.io/Boujour/coucou/sltTM");
  CHECK(jidprep(badjid) == "~zigougoutm@epik-7d9d1fde.poez.io/Boujour/coucou/sltTM");

  CHECK(jidprep("Zigougou@poez.io") == "zigougou@poez.io");

  CHECK(jidprep("~Bisous@88.123.43.45") == "~bisous@88.123.43.45");

  CHECK(jidprep("~Bisous@::ffff:42.156.139.46") == "~bisous@[::ffff:42.156.139.46]");

  CHECK(jidprep("louiz!6bf74289@2001:bc8:38e7::") == "louiz!6bf74289@[2001:bc8:38e7::]");

  CHECK(jidprep("louiz@+:::::----coucou.com78--.") == "louiz@coucou.com78");
  CHECK(jidprep("louiz@coucou.com78--.") == "louiz@coucou.com78");
  CHECK(jidprep("louiz@+:::::----coucou.com78") == "louiz@coucou.com78");
  CHECK(jidprep("louiz@:::::") == "louiz@empty");
#else // Without libidn, jidprep always returns an empty string
  CHECK(jidprep(badjid) == "");
#endif
}