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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
|
/*
* Copyright (c) 2011 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <SwifTools/URIHandler/XMPPURI.h>
using namespace Swift;
class XMPPURITest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(XMPPURITest);
CPPUNIT_TEST(testFromString_Authority);
CPPUNIT_TEST(testFromString_AuthorityWithPath);
CPPUNIT_TEST(testFromString_AuthorityWithFragment);
CPPUNIT_TEST(testFromString_AuthorityWithPathAndFragment);
CPPUNIT_TEST(testFromString_AuthorityWithIntlChars);
CPPUNIT_TEST(testFromString_AuthorityWithQueryWithoutParameters);
CPPUNIT_TEST(testFromString_AuthorityWithQueryWithParameters);
CPPUNIT_TEST(testFromString_AuthorityWithQueryWithoutParametersWithFragment);
CPPUNIT_TEST(testFromString_AuthorityWithQueryWithParametersWithFragment);
CPPUNIT_TEST(testFromString_Path);
CPPUNIT_TEST(testFromString_PathWithFragment);
CPPUNIT_TEST(testFromString_PathWithIntlChars);
CPPUNIT_TEST(testFromString_PathWithInvalidEscapedChar);
CPPUNIT_TEST(testFromString_PathWithIncompleteEscapedChar);
CPPUNIT_TEST(testFromString_PathWithIncompleteEscapedChar2);
CPPUNIT_TEST(testFromString_PathWithQueryWithoutParameters);
CPPUNIT_TEST(testFromString_PathWithQueryWithParameters);
CPPUNIT_TEST(testFromString_PathWithQueryWithoutParametersWithFragment);
CPPUNIT_TEST(testFromString_PathWithQueryWithParametersWithFragment);
CPPUNIT_TEST(testFromString_NoPrefix);
CPPUNIT_TEST_SUITE_END();
public:
void testFromString_Authority() {
XMPPURI testling = XMPPURI::fromString("xmpp://foo@bar.com");
CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), testling.getAuthority());
}
void testFromString_AuthorityWithPath() {
XMPPURI testling = XMPPURI::fromString("xmpp://foo@bar.com/baz@example.com");
CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), testling.getAuthority());
CPPUNIT_ASSERT_EQUAL(JID("baz@example.com"), testling.getPath());
}
void testFromString_AuthorityWithFragment() {
XMPPURI testling = XMPPURI::fromString("xmpp://foo@bar.com#myfragment");
CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), testling.getAuthority());
CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment());
}
void testFromString_AuthorityWithPathAndFragment() {
XMPPURI testling = XMPPURI::fromString("xmpp://foo@bar.com/baz@example.com#myfragment");
CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), testling.getAuthority());
CPPUNIT_ASSERT_EQUAL(JID("baz@example.com"), testling.getPath());
CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment());
}
void testFromString_AuthorityWithIntlChars() {
XMPPURI testling = XMPPURI::fromString("xmpp://nasty!%23$%25()*+,-.;=\%3F\%5B\%5C\%5D\%5E_\%60\%7B\%7C\%7D~node@example.com");
CPPUNIT_ASSERT_EQUAL(JID("nasty!#$\%()*+,-.;=?[\\]^_`{|}~node@example.com"), testling.getAuthority());
}
void testFromString_AuthorityWithQueryWithoutParameters() {
XMPPURI testling = XMPPURI::fromString("xmpp://test@example.com?message");
CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getAuthority());
CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType());
}
void testFromString_AuthorityWithQueryWithParameters() {
XMPPURI testling = XMPPURI::fromString("xmpp://test@example.com?message;subject=Test%20Message;body=Here%27s%20a%20test%20message");
CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getAuthority());
CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType());
CPPUNIT_ASSERT_EQUAL(std::string("Test Message"), get(testling.getQueryParameters(), "subject"));
CPPUNIT_ASSERT_EQUAL(std::string("Here's a test message"), get(testling.getQueryParameters(), "body"));
}
void testFromString_AuthorityWithQueryWithoutParametersWithFragment() {
XMPPURI testling = XMPPURI::fromString("xmpp://test@example.com?message#myfragment");
CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getAuthority());
CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType());
CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment());
}
void testFromString_AuthorityWithQueryWithParametersWithFragment() {
XMPPURI testling = XMPPURI::fromString("xmpp://test@example.com?message;subject=Test%20Message;body=Here%27s%20a%20test%20message#myfragment");
CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getAuthority());
CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType());
CPPUNIT_ASSERT_EQUAL(std::string("Test Message"), get(testling.getQueryParameters(), "subject"));
CPPUNIT_ASSERT_EQUAL(std::string("Here's a test message"), get(testling.getQueryParameters(), "body"));
CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment());
}
void testFromString_Path() {
XMPPURI testling = XMPPURI::fromString("xmpp:baz@example.com");
CPPUNIT_ASSERT_EQUAL(JID("baz@example.com"), testling.getPath());
}
void testFromString_PathWithFragment() {
XMPPURI testling = XMPPURI::fromString("xmpp:baz@example.com#myfragment");
CPPUNIT_ASSERT_EQUAL(JID("baz@example.com"), testling.getPath());
CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment());
}
void testFromString_PathWithIntlChars() {
XMPPURI testling = XMPPURI::fromString("xmpp:nasty!%23$%25()*+,-.;=\%3F\%5B\%5C\%5D\%5E_\%60\%7B\%7C\%7D~node@example.com");
CPPUNIT_ASSERT_EQUAL(JID("nasty!#$\%()*+,-.;=?[\\]^_`{|}~node@example.com"), testling.getPath());
}
void testFromString_PathWithInvalidEscapedChar() {
XMPPURI testling = XMPPURI::fromString("xmpp:test%%@example.com");
CPPUNIT_ASSERT_EQUAL(JID(), testling.getPath());
}
void testFromString_PathWithIncompleteEscapedChar() {
XMPPURI testling = XMPPURI::fromString("xmpp:test@example.com%");
CPPUNIT_ASSERT_EQUAL(JID(), testling.getPath());
}
void testFromString_PathWithIncompleteEscapedChar2() {
XMPPURI testling = XMPPURI::fromString("xmpp:test@example.com%1");
CPPUNIT_ASSERT_EQUAL(JID(), testling.getPath());
}
void testFromString_PathWithQueryWithoutParameters() {
XMPPURI testling = XMPPURI::fromString("xmpp:test@example.com?message");
CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getPath());
CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType());
}
void testFromString_PathWithQueryWithParameters() {
XMPPURI testling = XMPPURI::fromString("xmpp:test@example.com?message;subject=Test%20Message;body=Here%27s%20a%20test%20message");
CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getPath());
CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType());
CPPUNIT_ASSERT_EQUAL(std::string("Test Message"), get(testling.getQueryParameters(), "subject"));
CPPUNIT_ASSERT_EQUAL(std::string("Here's a test message"), get(testling.getQueryParameters(), "body"));
}
void testFromString_PathWithQueryWithoutParametersWithFragment() {
XMPPURI testling = XMPPURI::fromString("xmpp:test@example.com?message#myfragment");
CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getPath());
CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType());
CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment());
}
void testFromString_PathWithQueryWithParametersWithFragment() {
XMPPURI testling = XMPPURI::fromString("xmpp:test@example.com?message;subject=Test%20Message;body=Here%27s%20a%20test%20message#myfragment");
CPPUNIT_ASSERT_EQUAL(JID("test@example.com"), testling.getPath());
CPPUNIT_ASSERT_EQUAL(std::string("message"), testling.getQueryType());
CPPUNIT_ASSERT_EQUAL(std::string("Test Message"), get(testling.getQueryParameters(), "subject"));
CPPUNIT_ASSERT_EQUAL(std::string("Here's a test message"), get(testling.getQueryParameters(), "body"));
CPPUNIT_ASSERT_EQUAL(std::string("myfragment"), testling.getFragment());
}
void testFromString_NoPrefix() {
XMPPURI testling = XMPPURI::fromString("baz@example.com");
CPPUNIT_ASSERT(testling.isNull());
}
private:
std::string get(const std::map<std::string, std::string>& m, const std::string& k) {
std::map<std::string, std::string>::const_iterator i = m.find(k);
return i == m.end() ? "" : i->second;
}
};
CPPUNIT_TEST_SUITE_REGISTRATION(XMPPURITest);
|