summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/JID/JID.h134
-rw-r--r--Swiften/Network/UnitTest/ConnectorTest.cpp57
2 files changed, 125 insertions, 66 deletions
diff --git a/Swiften/JID/JID.h b/Swiften/JID/JID.h
index ad89c85..0bfb858 100644
--- a/Swiften/JID/JID.h
+++ b/Swiften/JID/JID.h
@@ -1,68 +1,80 @@
-#ifndef SWIFTEN_JID_H
-#define SWIFTEN_JID_H
+#pragma once
#include "Swiften/Base/String.h"
namespace Swift {
- class JID
- {
- public:
- enum CompareType { WithResource, WithoutResource };
-
- explicit JID(const String& = String());
- explicit JID(const char*);
- JID(const String& node, const String& domain);
- JID(const String& node, const String& domain, const String& resource);
-
- bool isValid() const { return !domain_.isEmpty(); /* FIXME */ }
-
- const String& getNode() const { return node_; }
- const String& getDomain() const { return domain_; }
- const String& getResource() const { return resource_; }
- bool isBare() const { return !hasResource_; }
-
- JID toBare() const { return JID(getNode(), getDomain()); /* FIXME: Duplicate unnecessary nameprepping. Probably ok. */ }
-
- String toString() const;
-
- bool equals(const JID& o, CompareType compareType) const {
- return compare(o, compareType) == 0;
- }
-
- int compare(const JID& o, CompareType compareType) const;
-
- operator String () const { return toString(); }
-
- bool operator<(const Swift::JID& b) const {
- return compare(b, Swift::JID::WithResource) < 0;
- }
-
- friend std::ostream& operator<<(std::ostream& os, const Swift::JID& j) {
- os << j.toString();
- return os;
- }
-
- friend bool operator==(const Swift::JID& a, const Swift::JID& b) {
- return a.compare(b, Swift::JID::WithResource) == 0;
- }
-
- friend bool operator!=(const Swift::JID& a, const Swift::JID& b) {
- return a.compare(b, Swift::JID::WithResource) != 0;
- }
-
- protected:
- void nameprepAndSetComponents(const String& node, const String& domain, const String& resource);
+ class JID {
+ public:
+ enum CompareType {
+ WithResource, WithoutResource
+ };
+
+ explicit JID(const String& = String());
+ explicit JID(const char*);
+ JID(const String& node, const String& domain);
+ JID(const String& node, const String& domain, const String& resource);
+
+ bool isValid() const {
+ return !domain_.isEmpty(); /* FIXME */
+ }
+
+ const String& getNode() const {
+ return node_;
+ }
+ const String& getDomain() const {
+ return domain_;
+ }
+ const String& getResource() const {
+ return resource_;
+ }
+ bool isBare() const {
+ return !hasResource_;
+ }
+
+ JID toBare() const {
+ return JID(getNode(), getDomain()); /* FIXME: Duplicate unnecessary nameprepping. Probably ok. */
+ }
+
+ String toString() const;
+
+ bool equals(const JID& o, CompareType compareType) const {
+ return compare(o, compareType) == 0;
+ }
+
+ int compare(const JID& o, CompareType compareType) const;
+
+ operator String() const {
+ return toString();
+ }
+
+ bool operator<(const Swift::JID& b) const {
+ return compare(b, Swift::JID::WithResource) < 0;
+ }
+
+ friend std::ostream& operator<<(std::ostream& os, const Swift::JID& j) {
+ os << j.toString();
+ return os;
+ }
+
+ friend bool operator==(const Swift::JID& a, const Swift::JID& b) {
+ return a.compare(b, Swift::JID::WithResource) == 0;
+ }
+
+ friend bool operator!=(const Swift::JID& a, const Swift::JID& b) {
+ return a.compare(b, Swift::JID::WithResource) != 0;
+ }
+
+ protected:
+ void nameprepAndSetComponents(const String& node, const String& domain,
+ const String& resource);
+
+ private:
+ void initializeFromString(const String&);
- private:
- void initializeFromString(const String&);
-
- private:
- String node_;
- String domain_;
- bool hasResource_;
- String resource_;
+ private:
+ String node_;
+ String domain_;
+ bool hasResource_;
+ String resource_;
};
}
-
-#endif
-
diff --git a/Swiften/Network/UnitTest/ConnectorTest.cpp b/Swiften/Network/UnitTest/ConnectorTest.cpp
index 05c6e28..af1ad4e 100644
--- a/Swiften/Network/UnitTest/ConnectorTest.cpp
+++ b/Swiften/Network/UnitTest/ConnectorTest.cpp
@@ -17,13 +17,16 @@ using namespace Swift;
class ConnectorTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(ConnectorTest);
CPPUNIT_TEST(testConnect);
+ CPPUNIT_TEST(testConnect_NoSRVHost);
CPPUNIT_TEST(testConnect_NoHosts);
- CPPUNIT_TEST(testConnect_FirstHostFails);
- CPPUNIT_TEST(testConnect_AllHostsFail);
+ CPPUNIT_TEST(testConnect_FirstSRVHostFails);
+ CPPUNIT_TEST(testConnect_AllSRVHostsFailWithoutFallbackHost);
+ CPPUNIT_TEST(testConnect_AllSRVHostsFailWithFallbackHost);
+ CPPUNIT_TEST(testConnect_SRVAndFallbackHostsFail);
CPPUNIT_TEST_SUITE_END();
public:
- ConnectorTest() : host1(HostAddress("1.1.1.1"), 1234), host2(HostAddress("2.2.2.2"), 2345) {
+ ConnectorTest() : host1(HostAddress("1.1.1.1"), 1234), host2(HostAddress("2.2.2.2"), 2345), host3(HostAddress("3.3.3.3"), 5222) {
}
void setUp() {
@@ -42,6 +45,7 @@ class ConnectorTest : public CppUnit::TestFixture {
std::auto_ptr<Connector> testling(createConnector());
resolver->addXMPPClientService("foo.com", host1);
resolver->addXMPPClientService("foo.com", host2);
+ resolver->addAddress("foo.com", host3.getAddress());
testling->start();
eventLoop->processEvents();
@@ -51,6 +55,18 @@ class ConnectorTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(host1 == *(connections[0]->hostAddressPort));
}
+ void testConnect_NoSRVHost() {
+ std::auto_ptr<Connector> testling(createConnector());
+ resolver->addAddress("foo.com", host3.getAddress());
+
+ testling->start();
+ eventLoop->processEvents();
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size()));
+ CPPUNIT_ASSERT(connections[0]);
+ CPPUNIT_ASSERT(host3 == *(connections[0]->hostAddressPort));
+ }
+
void testConnect_NoHosts() {
std::auto_ptr<Connector> testling(createConnector());
@@ -61,7 +77,7 @@ class ConnectorTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(!connections[0]);
}
- void testConnect_FirstHostFails() {
+ void testConnect_FirstSRVHostFails() {
std::auto_ptr<Connector> testling(createConnector());
resolver->addXMPPClientService("foo.com", host1);
resolver->addXMPPClientService("foo.com", host2);
@@ -74,7 +90,7 @@ class ConnectorTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(host2 == *(connections[0]->hostAddressPort));
}
- void testConnect_AllHostsFail() {
+ void testConnect_AllSRVHostsFailWithoutFallbackHost() {
std::auto_ptr<Connector> testling(createConnector());
resolver->addXMPPClientService("foo.com", host1);
resolver->addXMPPClientService("foo.com", host2);
@@ -88,6 +104,36 @@ class ConnectorTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT(!connections[0]);
}
+ void testConnect_AllSRVHostsFailWithFallbackHost() {
+ std::auto_ptr<Connector> testling(createConnector());
+ resolver->addXMPPClientService("foo.com", host1);
+ resolver->addXMPPClientService("foo.com", host2);
+ resolver->addAddress("foo.com", host3.getAddress());
+ connectionFactory->failingPorts.push_back(host1);
+ connectionFactory->failingPorts.push_back(host2);
+
+ testling->start();
+ eventLoop->processEvents();
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size()));
+ CPPUNIT_ASSERT(connections[0]);
+ CPPUNIT_ASSERT(host3 == *(connections[0]->hostAddressPort));
+ }
+
+ void testConnect_SRVAndFallbackHostsFail() {
+ std::auto_ptr<Connector> testling(createConnector());
+ resolver->addXMPPClientService("foo.com", host1);
+ resolver->addAddress("foo.com", host3.getAddress());
+ connectionFactory->failingPorts.push_back(host1);
+ connectionFactory->failingPorts.push_back(host3);
+
+ testling->start();
+ eventLoop->processEvents();
+
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(connections.size()));
+ CPPUNIT_ASSERT(!connections[0]);
+ }
+
private:
Connector* createConnector() {
Connector* connector = new Connector("foo.com", resolver, connectionFactory);
@@ -131,6 +177,7 @@ class ConnectorTest : public CppUnit::TestFixture {
private:
HostAddressPort host1;
HostAddressPort host2;
+ HostAddressPort host3;
DummyEventLoop* eventLoop;
StaticDomainNameResolver* resolver;
MockConnectionFactory* connectionFactory;