Debian Codegraph @

xmpp-vala/tests/jid.vala

raw
1 namespace Xmpp.Test {
2
3 class JidTest : Gee.TestCase {
4 public JidTest() {
5 base("Jid");
6
7 add_test("jid_valid_domain_only", () => { test_jid_valid("example.com"); });
8 add_test("jid_valid_bare", () => { test_jid_valid("[email protected]"); });
9 add_test("jid_valid_domain_with_resource", () => { test_jid_valid("example.com/test"); });
10 add_test("jid_valid_full", () => { test_jid_valid("[email protected]/test"); });
11
12 // These should not be valid in "strict-mode"
13 add_test("jid_valid_emoji_only", () => { test_jid_valid("๐Ÿ˜…"); });
14 add_test("jid_valid_emoji_local", () => { test_jid_valid("๐Ÿ˜…@example.com"); });
15 add_test("jid_valid_emoji_resource", () => { test_jid_valid("[email protected]/๐Ÿ˜…"); });
16 add_test("jid_valid_emoji_domain", () => { test_jid_valid("test@๐Ÿ˜….com"); });
17
18 add_test("jid_invalid_bidi_local", () => { test_jid_invalid("teโ€[email protected]"); });
19 add_test("jid_invalid_bidi_resource", () => { test_jid_invalid("[email protected]/teโ€st"); });
20 add_test("jid_invalid_bidi_domain", () => { test_jid_invalid("test@exaโ€mple.com"); });
21 add_test("jid_invalid_overlong_idn", () => { test_jid_invalid("test@รงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรงรง.com"); });
22
23 add_test("jid_equal_end_domain", () => { test_jids_equal("[email protected]", "[email protected]."); });
24 add_test("jid_equal_case_domain", () => { test_jids_equal("[email protected]", "[email protected]"); });
25 add_test("jid_equal_norm_domain", () => { test_jids_equal("test@garรงon.com", "test@garcฬงon.com"); });
26 add_test("jid_equal_puny_domain", () => { test_jids_equal("test@garรงon.com", "[email protected]"); });
27 add_test("jid_equal_case_local", () => { test_jids_equal("[email protected]", "[email protected]"); });
28 add_test("jid_equal_norm_local", () => { test_jids_equal("garรง[email protected]", "garcฬง[email protected]"); });
29 add_test("jid_equal_norm_resource", () => { test_jids_equal("[email protected]/garรงon", "[email protected]/garcฬงon"); });
30
31 add_test("jid_non_equal_case_resource", () => { test_jids_unequal("example.com/test", "example.com/tEst"); });
32
33 add_test("jid_to_string_end_domain", () => { test_jid_to_string("[email protected].", "[email protected]"); });
34 add_test("jid_to_string_case_domain", () => { test_jid_to_string("[email protected]", "[email protected]"); });
35 add_test("jid_to_string_norm_domain", () => { test_jid_to_string("test@garcฬงon.com", "test@garรงon.com"); });
36 add_test("jid_to_string_puny_domain", () => { test_jid_to_string("[email protected]", "test@garรงon.com"); });
37 add_test("jid_to_string_case_local", () => { test_jid_to_string("[email protected]", "[email protected]"); });
38 add_test("jid_to_string_norm_local", () => { test_jid_to_string("garcฬง[email protected]", "garรง[email protected]"); });
39 add_test("jid_to_string_case_resource", () => { test_jid_to_string("example.com/tEst", "example.com/tEst"); });
40 add_test("jid_to_string_norm_resource", () => { test_jid_to_string("[email protected]/garcฬงon", "[email protected]/garรงon"); });
41 }
42
43 private void test_jid_valid(string jid) {
44 try {
45 new Jid(jid);
46 } catch (Error e) {
47 fail_if_reached(@"Throws $(e.message)");
48 }
49 }
50
51 private void test_jid_invalid(string jid) {
52 try {
53 new Jid(jid);
54 fail_if_reached();
55 } catch (Error e) {
56 // try {
57 // fail_if_not_eq_str(Jid.parse(jid).to_string(), jid);
58 // } catch (Error e) {
59 // fail_if_reached();
60 // }
61 }
62 }
63
64 private void test_jids_equal(string jid1, string jid2) {
65 try {
66 var t1 = new Jid(jid1);
67 var t2 = new Jid(jid2);
68 fail_if_not_eq_str(t1.to_string(), t2.to_string());
69 } catch (Error e) {
70 fail_if_reached(@"Throws $(e.message)");
71 }
72 }
73
74 private void test_jid_to_string(string jid1, string jid2) {
75 try {
76 var t1 = new Jid(jid1);
77 fail_if_not_eq_str(t1.to_string(), jid2);
78 } catch (Error e) {
79 fail_if_reached(@"Throws $(e.message)");
80 }
81 }
82
83 private void test_jids_unequal(string jid1, string jid2) {
84 try {
85 var t1 = new Jid(jid1);
86 var t2 = new Jid(jid2);
87 fail_if_eq_str(t1.to_string(), t2.to_string());
88 } catch (Error e) {
89 fail_if_reached(@"Throws $(e.message)");
90 }
91 }
92 }
93
94 }