mirror of
https://git.jami.net/savoirfairelinux/jami-daemon.git
synced 2025-08-07 22:02:12 +08:00
misc: fix tests build
Change-Id: I238f452f77e10c16ebc5f69bef1b768f44e57e2e
This commit is contained in:
@ -655,6 +655,7 @@ AC_CONFIG_FILES([Makefile \
|
||||
src/Makefile \
|
||||
ringtones/Makefile \
|
||||
test/Makefile\
|
||||
test/sip/Makefile
|
||||
test/unitTest/Makefile \
|
||||
man/Makefile \
|
||||
doc/Makefile \
|
||||
|
@ -1,5 +1,5 @@
|
||||
SUBDIRS = unitTest
|
||||
|
||||
SUBDIRS += sip
|
||||
if ENABLE_FUZZING
|
||||
SUBDIRS += fuzzing
|
||||
endif
|
||||
|
2
test/sip/.gitignore
vendored
Normal file
2
test/sip/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
#test binaries
|
||||
sip
|
10
test/sip/Makefile.am
Normal file
10
test/sip/Makefile.am
Normal file
@ -0,0 +1,10 @@
|
||||
# Rules for the test code (use `make check` to execute)
|
||||
include $(top_srcdir)/globals.mk
|
||||
|
||||
AM_CXXFLAGS += -I$(top_srcdir)/src
|
||||
AM_LDFLAGS += $(CPPUNIT_LIBS) $(top_builddir)/src/libring.la
|
||||
|
||||
check_PROGRAMS = ut_sip
|
||||
ut_sip_SOURCES = sip.cpp test_SIP.h test_SIP.cpp
|
||||
|
||||
TESTS = $(check_PROGRAMS)
|
60
test/sip/sip.cpp
Normal file
60
test/sip/sip.cpp
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2022 Savoir-faire Linux Inc.
|
||||
* Author: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <cppunit/ui/text/TestRunner.h>
|
||||
#include <cppunit/extensions/TestFactoryRegistry.h>
|
||||
#include <cppunit/CompilerOutputter.h>
|
||||
|
||||
#include "jami.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
void init_daemon()
|
||||
{
|
||||
DRing::init(DRing::InitFlag(DRing::DRING_FLAG_DEBUG | DRing::DRING_FLAG_CONSOLE_LOG));
|
||||
DRing::start("test/unitTest/jami-sample.yml");
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
init_daemon();
|
||||
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
|
||||
// Register all tests
|
||||
auto& registry = CppUnit::TestFactoryRegistry::getRegistry();
|
||||
runner.addTest(registry.makeTest());
|
||||
|
||||
// Use a compiler error format outputter for results and output into stderr
|
||||
runner.setOutputter(new CppUnit::CompilerOutputter(&runner.result(), std::cerr ));
|
||||
|
||||
bool ret;
|
||||
|
||||
try {
|
||||
// Run tests
|
||||
ret = !runner.run("", false);
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Exception catched during tests: " << e.what() << '\n';
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
DRing::fini();
|
||||
|
||||
return ret;
|
||||
}
|
136
test/sip/test_SIP.cpp
Normal file
136
test/sip/test_SIP.cpp
Normal file
@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2022 Savoir-faire Linux Inc.
|
||||
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
|
||||
* Author: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
|
||||
* Author: Olivier Gregoire <olivier.gregoire@savoirfairelinux.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include "test_SIP.h"
|
||||
#include "call_const.h"
|
||||
|
||||
using namespace jami;
|
||||
using namespace std::literals;
|
||||
|
||||
static pthread_mutex_t count_mutex;
|
||||
static pthread_cond_t count_nb_thread;
|
||||
static int counter = 0;
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(test_SIP);
|
||||
|
||||
/*
|
||||
return an error if all call are not successful
|
||||
*/
|
||||
void*
|
||||
sippThreadWithCount(void* str)
|
||||
{
|
||||
// number of time we use the mutex. Lock the utilisation of counter
|
||||
pthread_mutex_lock(&count_mutex);
|
||||
counter++;
|
||||
pthread_mutex_unlock(&count_mutex);
|
||||
|
||||
// display what is send on the parameter of the method
|
||||
std::string* command = (std::string*) (str);
|
||||
|
||||
std::cout << "test_SIP: " << command << std::endl;
|
||||
|
||||
// Set up the sipp instance in this thread in order to catch return value
|
||||
// 0: All calls were successful
|
||||
// 1: At least one call failed
|
||||
// 97: exit on internal command. Calls may have been processed
|
||||
// 99: Normal exit without calls processed
|
||||
// -1: Fatal error
|
||||
// -2: Fatal error binding a socket
|
||||
int i = system(command->c_str()); // c_str() retrieve the *char of the string
|
||||
|
||||
CPPUNIT_ASSERT(i);
|
||||
|
||||
pthread_mutex_lock(&count_mutex);
|
||||
counter--;
|
||||
// ???
|
||||
if (counter == 0)
|
||||
pthread_cond_signal(&count_nb_thread);
|
||||
|
||||
pthread_mutex_unlock(&count_mutex);
|
||||
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
RAIIThread
|
||||
sippThread(const std::string& command)
|
||||
{
|
||||
return std::thread([command] {
|
||||
std::cout << "test_SIP: " << command << std::endl;
|
||||
|
||||
// Set up the sipp instance in this thread in order to catch return value
|
||||
// 0: All calls were successful
|
||||
// 1: At least one call failed
|
||||
// 97: exit on internal command. Calls may have been processed
|
||||
// 99: Normal exit without calls processed
|
||||
// -1: Fatal error
|
||||
// -2: Fatal error binding a socket
|
||||
auto ret = system(command.c_str());
|
||||
std::cout << "test_SIP: Command executed by system returned: " << ret << std::endl;
|
||||
});
|
||||
}
|
||||
|
||||
void
|
||||
test_SIP::setUp()
|
||||
{
|
||||
std::cout << "setup test SIP" << std::endl;
|
||||
pthread_mutex_lock(&count_mutex);
|
||||
counter = 0;
|
||||
pthread_mutex_unlock(&count_mutex);
|
||||
|
||||
running_ = true;
|
||||
eventLoop_ = RAIIThread(std::thread([this] {
|
||||
while (running_) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
void
|
||||
test_SIP::tearDown()
|
||||
{
|
||||
running_ = false;
|
||||
eventLoop_.join();
|
||||
|
||||
// in order to stop any currently running threads
|
||||
std::cout << "test_SIP: Clean all remaining sipp instances" << std::endl;
|
||||
int ret = system("killall sipp");
|
||||
if (ret)
|
||||
std::cout << "test_SIP: Error from system call, killall sipp"
|
||||
<< ", ret=" << ret << '\n';
|
||||
Manager::instance().callFactory.clear();
|
||||
}
|
||||
void
|
||||
test_SIP::testSIPURI()
|
||||
{
|
||||
std::cout << ">>>> test SIPURI <<<< " << '\n';
|
||||
|
||||
auto foo = sip_utils::stripSipUriPrefix("<sip:17771234567@callcentric.com>"sv);
|
||||
CPPUNIT_ASSERT_EQUAL("17771234567"sv, foo);
|
||||
}
|
94
test/sip/test_SIP.h
Normal file
94
test/sip/test_SIP.h
Normal file
@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (C) 2004-2022 Savoir-faire Linux Inc.
|
||||
* Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
|
||||
* Author: Guillaume Roguez <guillaume.roguez@savoirfairelinux.com>
|
||||
* Author: Olivier Gregoire <olivier.gregoire@savoirfairelinux.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
// Cppunit import
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <cppunit/TestCaller.h>
|
||||
#include <cppunit/TestCase.h>
|
||||
#include <cppunit/TestSuite.h>
|
||||
|
||||
// Application import
|
||||
#include "manager.h"
|
||||
|
||||
#include "sip/sipvoiplink.h"
|
||||
#include "sip/sip_utils.h"
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#include <thread>
|
||||
class RAIIThread
|
||||
{
|
||||
public:
|
||||
RAIIThread() = default;
|
||||
|
||||
RAIIThread(std::thread&& t)
|
||||
: thread_ {std::move(t)} {};
|
||||
|
||||
~RAIIThread() { join(); }
|
||||
|
||||
void join()
|
||||
{
|
||||
if (thread_.joinable())
|
||||
thread_.join();
|
||||
}
|
||||
|
||||
RAIIThread(RAIIThread&&) = default;
|
||||
RAIIThread& operator=(RAIIThread&&) = default;
|
||||
|
||||
private:
|
||||
std::thread thread_;
|
||||
};
|
||||
|
||||
/*
|
||||
* @file Test-sip.h
|
||||
* @brief Regroups unitary tests related to the SIP module
|
||||
*/
|
||||
|
||||
class test_SIP : public CppUnit::TestFixture
|
||||
{
|
||||
public:
|
||||
/*
|
||||
* Code factoring - Common resources can be initialized here.
|
||||
* This method is called by unitcpp before each test
|
||||
*/
|
||||
void setUp();
|
||||
|
||||
/*
|
||||
* Code factoring - Common resources can be released here.
|
||||
* This method is called by unitcpp after each test
|
||||
*/
|
||||
void tearDown();
|
||||
|
||||
private:
|
||||
void testSIPURI(void);
|
||||
|
||||
/**
|
||||
* Use cppunit library macros to add unit test to the factory
|
||||
*/
|
||||
CPPUNIT_TEST_SUITE(test_SIP);
|
||||
CPPUNIT_TEST(testSIPURI);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
RAIIThread eventLoop_;
|
||||
std::atomic_bool running_;
|
||||
};
|
@ -42,6 +42,7 @@
|
||||
#include <filesystem>
|
||||
|
||||
using namespace std::string_literals;
|
||||
using namespace std::literals::chrono_literals;
|
||||
using namespace DRing::Account;
|
||||
|
||||
namespace jami {
|
||||
@ -199,7 +200,7 @@ AccountArchiveTest::testExportDht()
|
||||
}));
|
||||
DRing::registerSignalHandlers(confHandlers);
|
||||
CPPUNIT_ASSERT(DRing::exportOnRing(bobId, "test"));
|
||||
CPPUNIT_ASSERT(cv.wait_for(lk, std::chrono::seconds(10), [&] { return !pin.empty(); }));
|
||||
CPPUNIT_ASSERT(cv.wait_for(lk, 20s, [&] { return !pin.empty(); }));
|
||||
|
||||
auto bobAccount = Manager::instance().getAccount<JamiAccount>(bobId);
|
||||
|
||||
@ -229,7 +230,7 @@ AccountArchiveTest::testExportDhtWrongPassword()
|
||||
}));
|
||||
DRing::registerSignalHandlers(confHandlers);
|
||||
CPPUNIT_ASSERT(DRing::exportOnRing(bobId, "wrong"));
|
||||
CPPUNIT_ASSERT(cv.wait_for(lk, std::chrono::seconds(10), [&] { return status == 1; }));
|
||||
CPPUNIT_ASSERT(cv.wait_for(lk, 10s, [&] { return status == 1; }));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -3163,15 +3163,15 @@ ConversationTest::testSearchInConv()
|
||||
messageReceived = false;
|
||||
DRing::sendMessage(aliceId, convId, "message 3"s, "");
|
||||
CPPUNIT_ASSERT(cv.wait_for(lk, 30s, [&]() { return messageReceived; }));
|
||||
DRing::searchConversation(aliceId, convId, "", "", "message", 0, 0, 0);
|
||||
DRing::searchConversation(aliceId, convId, "", "", "message", "", 0, 0, 0);
|
||||
CPPUNIT_ASSERT(cv.wait_for(lk, 30s, [&]() { return messages.size() == 3 && finished; }));
|
||||
messages.clear();
|
||||
finished = false;
|
||||
DRing::searchConversation(aliceId, convId, "", "", "message 2", 0, 0, 0);
|
||||
DRing::searchConversation(aliceId, convId, "", "", "message 2", "", 0, 0, 0);
|
||||
CPPUNIT_ASSERT(cv.wait_for(lk, 30s, [&]() { return messages.size() == 1 && finished; }));
|
||||
messages.clear();
|
||||
finished = false;
|
||||
DRing::searchConversation(aliceId, convId, "", "", "foo", 0, 0, 0);
|
||||
DRing::searchConversation(aliceId, convId, "", "", "foo", "", 0, 0, 0);
|
||||
CPPUNIT_ASSERT(cv.wait_for(lk, 30s, [&]() { return messages.size() == 0 && finished; }));
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user