summaryrefslogtreecommitdiffstats
blob: 7d7b1bec150ba5e4080054b80d9c74832ffd6d50 (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
/*
 * Copyright (c) 2010 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 <Swiften/Serializer/AuthRequestSerializer.h>
#include <Swiften/Elements/AuthRequest.h>
#include <Swiften/Base/ByteArray.h>
#include <QA/Checker/IO.h>

using namespace Swift;

class AuthRequestSerializerTest : public CppUnit::TestFixture {
		CPPUNIT_TEST_SUITE(AuthRequestSerializerTest);
		CPPUNIT_TEST(testSerialize);
		CPPUNIT_TEST(testSerialize_NoMessage);
		CPPUNIT_TEST(testSerialize_EmptyMessage);
		CPPUNIT_TEST_SUITE_END();

	public:
		void testSerialize() {
			AuthRequestSerializer testling;
			boost::shared_ptr<AuthRequest> authRequest(new AuthRequest("PLAIN"));
			authRequest->setMessage(createSafeByteArray("foo"));

			CPPUNIT_ASSERT_EQUAL(SafeString(
				"<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"PLAIN\">"
					"Zm9v"
				"</auth>"), testling.serialize(authRequest));
		}

		void testSerialize_NoMessage() {
			AuthRequestSerializer testling;
			boost::shared_ptr<AuthRequest> authRequest(new AuthRequest("PLAIN"));

			CPPUNIT_ASSERT_EQUAL(SafeString(
				"<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"PLAIN\">"
				"</auth>"), testling.serialize(authRequest));
		}

		void testSerialize_EmptyMessage() {
			AuthRequestSerializer testling;
			boost::shared_ptr<AuthRequest> authRequest(new AuthRequest("PLAIN"));
			authRequest->setMessage(SafeByteArray());

			CPPUNIT_ASSERT_EQUAL(SafeString(
				"<auth xmlns=\"urn:ietf:params:xml:ns:xmpp-sasl\" mechanism=\"PLAIN\">"
					"="
				"</auth>"), testling.serialize(authRequest));
		}
};

CPPUNIT_TEST_SUITE_REGISTRATION(AuthRequestSerializerTest);