1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include <sal/types.h>
12 #include <cppunit/TestFixture.h>
13 #include <cppunit/extensions/HelperMacros.h>
14 #include <cppunit/plugin/TestPlugIn.h>
16 #include <rtl/bootstrap.hxx>
17 #include <rtl/string.hxx>
18 #include <rtl/ustring.hxx>
19 #include <tubes/collaboration.hxx>
20 #include <tubes/manager.hxx>
21 #include <unotools/localfilehelper.hxx>
23 #include <telepathy-glib/telepathy-glib.h>
29 class TestTeleTubes
: public CppUnit::TestFixture
34 virtual void tearDown();
38 // There is only one method because the code in setUp
39 // and tearDown is expected to be executed only once.
40 CPPUNIT_TEST_SUITE( TestTeleTubes
);
41 CPPUNIT_TEST( testSession
);
42 CPPUNIT_TEST_SUITE_END();
45 class TestCollaboration
;
46 // static, not members, so they actually survive cppunit test iteration
47 static TestCollaboration
* mpCollaboration1
= NULL
;
48 static TestCollaboration
* mpCollaboration2
= NULL
;
49 //static bool mbFileSentSuccess = false;
50 static bool mbPacketReceived
= false;
51 static OUString maTestConfigIniURL
;
52 static OString maOffererIdentifier
;
53 static OString maAccepterIdentifier
;
55 class TestCollaboration
: public Collaboration
57 virtual void EndCollaboration() const {}
58 virtual void PacketReceived( const OString
& rPacket
) const
60 CPPUNIT_ASSERT( rPacket
== "from 1 to 2");
61 mbPacketReceived
= true;
63 virtual void SaveAndSendFile( TpContact
* ) const {}
64 virtual void StartCollaboration( TeleConference
* ) {}
67 static gboolean
timed_out( void * )
69 CPPUNIT_ASSERT_MESSAGE( "Test took longer than ten seconds!", false);
74 void TestTeleTubes::setUp()
76 g_timeout_add_seconds (10, timed_out
, NULL
);
77 maTestConfigIniURL
= "file://" +
78 OUString::createFromAscii( getenv("SRCDIR") ) + "/tubes/qa/test-config.ini";
79 rtl::Bootstrap
aTestConfig( maTestConfigIniURL
);
81 TeleManager::addSuffixToNames( "TeleTest");
83 OUString aOffererIdentifier
;
84 CPPUNIT_ASSERT_MESSAGE( "See README for how to set up test-config.ini",
85 aTestConfig
.getFrom("offerer", aOffererIdentifier
));
86 maOffererIdentifier
= OUStringToOString( aOffererIdentifier
, RTL_TEXTENCODING_UTF8
);
88 OUString aAccepterIdentifier
;
89 CPPUNIT_ASSERT_MESSAGE( "See README for how to set up test-config.ini",
90 aTestConfig
.getFrom("accepter", aAccepterIdentifier
));
91 maAccepterIdentifier
= OUStringToOString( aAccepterIdentifier
, RTL_TEXTENCODING_UTF8
);
93 mpCollaboration1
= new TestCollaboration();
94 mpCollaboration2
= new TestCollaboration();
96 CPPUNIT_ASSERT( TeleManager::init( true));
99 /* FIXME: do we need the possibility to pass function to Collaboration::SendFile() ?
100 static void lcl_FileSent( bool success, void * )
102 mbFileSentSuccess = success;
106 void TestTeleTubes::testSession()
108 // First try to get account and contact
109 AccountContactPairV pairs
= TeleManager::getContacts();
110 /* Both our accounts are meant to be signed in, and they both should be
111 * capable of LibreOffice tubes because this test runs after we register
113 CPPUNIT_ASSERT_MESSAGE(
114 "Make sure both your test accounts are signed in "
115 "and are on each other's contact lists",
118 TpAccount
* mpOffererAccount
= NULL
;
119 TpContact
* mpAccepterContact
= NULL
;
121 for (guint i
= 0; i
< pairs
.size(); i
++)
123 AccountContactPair pair
= pairs
[i
];
125 if (tp_account_get_normalized_name (pair
.first
) == maOffererIdentifier
&&
126 tp_contact_get_identifier (pair
.second
) == maAccepterIdentifier
)
128 mpOffererAccount
= pair
.first
;
129 g_object_ref (mpOffererAccount
);
130 mpAccepterContact
= pair
.second
;
131 g_object_ref (mpAccepterContact
);
133 g_object_unref (pair
.first
);
134 g_object_unref (pair
.second
);
137 CPPUNIT_ASSERT_MESSAGE(
138 "Couldn't find offerer account. "
139 "Make sure both your test accounts are signed in "
140 "and are on each other's contact lists",
142 CPPUNIT_ASSERT_MESSAGE(
143 "Couldn't find accepter contact. "
144 "Make sure both your test accounts are signed in "
145 "and are on each other's contact lists",
148 // Now we can start session
149 TeleConference
* pConference
= NULL
;
150 pConference
= TeleManager::startBuddySession( mpOffererAccount
, mpAccepterContact
);
151 CPPUNIT_ASSERT( pConference
!= NULL
);
152 mpCollaboration1
->SetConference( pConference
);
153 mpCollaboration1
->SendFile( mpAccepterContact
, maTestConfigIniURL
);
155 g_object_unref(mpOffererAccount
);
156 mpOffererAccount
= NULL
;
157 g_object_unref(mpAccepterContact
);
158 mpAccepterContact
= NULL
;
160 //while (!mbFileSentSuccess)
161 // g_main_context_iteration( NULL, TRUE);
163 // This checks that the file was received and msCurrentUUID set (see manager.cxx)
164 while (!TeleManager::hasWaitingConference())
165 g_main_context_iteration( NULL
, TRUE
);
167 pConference
= TeleManager::getConference();
168 CPPUNIT_ASSERT( pConference
!= NULL
);
169 mpCollaboration2
->SetConference( pConference
);
171 mpCollaboration1
->SendPacket( "from 1 to 2");
173 while (!mbPacketReceived
)
174 g_main_context_iteration( NULL
, TRUE
);
177 void TestTeleTubes::tearDown()
179 // Closes the TeleConference in destructor:
180 delete mpCollaboration1
;
181 delete mpCollaboration2
;
183 TeleManager::finalize();
186 CPPUNIT_TEST_SUITE_REGISTRATION( TestTeleTubes
);
190 CPPUNIT_PLUGIN_IMPLEMENT();
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */