diff options
author | Matúš Kukan <matus.kukan@gmail.com> | 2012-08-15 14:50:03 +0200 |
---|---|---|
committer | Matúš Kukan <matus.kukan@gmail.com> | 2012-08-16 11:41:51 +0200 |
commit | ece8eadbc0ba433c85c313eb11f0233aeae24cb9 (patch) | |
tree | d99bd75cb1db46d02986673edfd66cb4d7d0d4a0 /tubes/qa | |
parent | 766a0247fc3ac49b25aab69948e4d0a5df334ff9 (diff) |
tubes: fix unittest again and simplify
- killed GMailLoop, seems to work with g_main_context_iteration( NULL, TRUE);
- added test for sending and also receiving file
Change-Id: Ida11f875709dab71d404697e8c39fe4548f653b0
Diffstat (limited to 'tubes/qa')
-rw-r--r-- | tubes/qa/test_manager.cxx | 138 |
1 files changed, 61 insertions, 77 deletions
diff --git a/tubes/qa/test_manager.cxx b/tubes/qa/test_manager.cxx index 76f093c748b7..fbd9a642cedc 100644 --- a/tubes/qa/test_manager.cxx +++ b/tubes/qa/test_manager.cxx @@ -58,12 +58,9 @@ public: void testStartBuddySession(); void testSendPacket(); void testReceivePacket(); - void testSendFile(); void testDestroyTeleTubes(); void testFailAlways(); - static void FileSent( bool success, void *user_data); - // Order is significant. CPPUNIT_TEST_SUITE( TestTeleTubes ); CPPUNIT_TEST( testInitialize ); @@ -71,9 +68,8 @@ public: CPPUNIT_TEST( testRegisterClients ); CPPUNIT_TEST( testContactList ); CPPUNIT_TEST( testStartBuddySession ); - CPPUNIT_TEST( testSendPacket ); - CPPUNIT_TEST( testReceivePacket ); - CPPUNIT_TEST( testSendFile ); + //CPPUNIT_TEST( testSendPacket ); + //CPPUNIT_TEST( testReceivePacket ); CPPUNIT_TEST( testDestroyTeleTubes ); #if 0 CPPUNIT_TEST( testFailAlways ); // test failure displays SAL_LOG, uncomment for debugging @@ -83,22 +79,18 @@ public: // static, not members, so they actually survive cppunit test iteration static TeleConference* mpConference1 = NULL; +static TeleConference* mpConference2 = NULL; +static TpAccount* mpOffererAccount = NULL; static TpContact* mpAccepterContact = NULL; -static GMainLoop* mpMainLoop = NULL; -static bool maFileSentSuccess = false; -static sal_uInt32 mnSentPackets = 0; +static bool mbFileSentSuccess = false; static OUString maTestConfigIniURL; static OString maOffererIdentifier; static OString maAccepterIdentifier; -static gboolean -timed_out (void *user_data) +static gboolean timed_out( void * ) { CPPUNIT_ASSERT_MESSAGE( "Test took longer than ten seconds!", false); - GMainLoop *loop = reinterpret_cast<GMainLoop *>(user_data); - - g_main_loop_quit (loop); return FALSE; } @@ -121,24 +113,24 @@ void TestTeleTubes::testInitialize() aTestConfig.getFrom("accepter", aAccepterIdentifier)); maAccepterIdentifier = OUStringToOString( aAccepterIdentifier, RTL_TEXTENCODING_UTF8); - mpMainLoop = g_main_loop_new (NULL, FALSE); - g_timeout_add_seconds (10, timed_out, mpMainLoop); + g_timeout_add_seconds (10, timed_out, NULL); } -void TestTeleTubes::testContactList() +void TestTeleTubes::testCreateAccountManager() { - ContactList *cl = TeleManager::getContactList(); - - AccountContactPairV pairs; - - pairs = cl->getContacts(); - guint i; + bool bConnected = TeleManager::createAccountManager(); + CPPUNIT_ASSERT( bConnected == true); +} - /* FIXME: this is racy, because we can't be 100% sure that MC has finished - * discovering what we support and passing that on to the connection - * manager... - */ +void TestTeleTubes::testRegisterClients() +{ + bool bRegistered = TeleManager::registerClients(); + CPPUNIT_ASSERT( bRegistered == true); +} +void TestTeleTubes::testContactList() +{ + AccountContactPairV pairs = TeleManager::getContactList()->getContacts(); /* Both our accounts are meant to be signed in, and they both should be * capable of LibreOffice tubes because this test runs after we register * our handler. */ @@ -148,97 +140,90 @@ void TestTeleTubes::testContactList() pairs.size() > 0 ); CPPUNIT_ASSERT(!mpAccepterContact); - for (i = 0; i < pairs.size(); i++) + for (guint i = 0; i < pairs.size(); i++) { AccountContactPair pair = pairs[i]; - /* FIXME: verify that pair.first is the offerer account */ - if (tp_contact_get_identifier(pair.second) == maAccepterIdentifier) { + if (tp_account_get_normalized_name (pair.first) == maOffererIdentifier && + tp_contact_get_identifier (pair.second) == maAccepterIdentifier) + { + mpOffererAccount = pair.first; + g_object_ref (mpOffererAccount); mpAccepterContact = pair.second; - g_object_ref(mpAccepterContact); + g_object_ref (mpAccepterContact); } g_object_unref (pair.first); g_object_unref (pair.second); } CPPUNIT_ASSERT_MESSAGE( + "Couldn't find offerer account. " + "Make sure both your test accounts are signed in " + "and are on each other's contact lists", + mpOffererAccount); + CPPUNIT_ASSERT_MESSAGE( "Couldn't find accepter contact. " "Make sure both your test accounts are signed in " "and are on each other's contact lists", mpAccepterContact); } +static void lcl_FileSent( bool success, void * ) +{ + mbFileSentSuccess = success; +} + void TestTeleTubes::testStartBuddySession() { - TpAccount *pAcc1 = TeleManager::getAccount(maOffererIdentifier); - CPPUNIT_ASSERT( pAcc1 != 0); - /* This has to run after testContactList has run successfully. */ + CPPUNIT_ASSERT( mpOffererAccount != 0); CPPUNIT_ASSERT( mpAccepterContact != 0); - mpConference1 = TeleManager::startBuddySession( pAcc1, mpAccepterContact); + mpConference1 = TeleManager::startBuddySession( mpOffererAccount, mpAccepterContact); CPPUNIT_ASSERT( mpConference1 != NULL); -} + mpConference1->sendFile( mpAccepterContact, maTestConfigIniURL, lcl_FileSent, NULL); -void TestTeleTubes::testCreateAccountManager() -{ - bool bConnected = TeleManager::createAccountManager(); - CPPUNIT_ASSERT( bConnected == true); -} + while (!mbFileSentSuccess) + g_main_context_iteration( NULL, TRUE); -void TestTeleTubes::testRegisterClients() -{ - bool bRegistered = TeleManager::registerClients(); - CPPUNIT_ASSERT( bRegistered == true); + // This checks that the file was received and msCurrentUUID set (see manager.cxx) + while (!TeleManager::hasWaitingConference()) + g_main_context_iteration( NULL, TRUE); + + mpConference2 = TeleManager::getConference(); + CPPUNIT_ASSERT( mpConference2 != NULL); } void TestTeleTubes::testSendPacket() { - OString aPacket( "from 1 to 2" ); - - bool bSentPacket = mpConference1->sendPacket( aPacket ); - CPPUNIT_ASSERT( bSentPacket ); - mnSentPackets++; + bool bSentPacket = false; + if (mpConference1) + bSentPacket = mpConference1->sendPacket( "from 1 to 2"); + CPPUNIT_ASSERT( bSentPacket); } void TestTeleTubes::testReceivePacket() { - /* We can't get to the TeleConference accepting our packets. - * It's stored in TeleManager but available only after receiving file - * and extracting UUID from the name. - */ - // TODO implement me } -void TestTeleTubes::FileSent( bool success, void * ) -{ - maFileSentSuccess = success; - g_main_loop_quit (mpMainLoop); -} - -void TestTeleTubes::testSendFile() -{ - /* This has to run after testContactList has run successfully. */ - CPPUNIT_ASSERT( mpAccepterContact != 0); - - mpConference1->sendFile( mpAccepterContact, maTestConfigIniURL, - &TestTeleTubes::FileSent, NULL); - /* Waiting for event: FileSent quits the mainloop */ - g_main_loop_run( mpMainLoop); - - CPPUNIT_ASSERT( maFileSentSuccess); - // Currently there is no way to check that the file was received ! -} - void TestTeleTubes::testDestroyTeleTubes() { + if (mpOffererAccount) { + g_object_unref(mpOffererAccount); + mpOffererAccount = NULL; + } if (mpAccepterContact) { g_object_unref(mpAccepterContact); mpAccepterContact = NULL; } - g_main_loop_unref( mpMainLoop ); + if (mpConference1) mpConference1->close(); delete mpConference1; + + if (mpConference2) + mpConference2->close(); + delete mpConference2; + TeleManager::finalize(); } @@ -247,7 +232,6 @@ void TestTeleTubes::testFailAlways() CPPUNIT_ASSERT( false); } - CPPUNIT_TEST_SUITE_REGISTRATION( TestTeleTubes); } |