tester: activate it in CMake

parent 8ae3f927
......@@ -33,3 +33,4 @@ tests/belcard-folder
tests/belcard-unfolder
tests/belcard-parser
tools/output.vcf
tester/belcard-tester
......@@ -66,19 +66,11 @@ else()
find_package(Belr REQUIRED)
endif()
if(ENABLE_UNIT_TESTS)
find_package(CUnit)
if(CUNIT_FOUND)
cmake_push_check_state(RESET)
list(APPEND CMAKE_REQUIRED_INCLUDES ${CUNIT_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CUNIT_LIBRARIES})
check_symbol_exists("CU_get_suite" "CUnit/CUnit.h" HAVE_CU_GET_SUITE)
check_symbol_exists("CU_curses_run_tests" "CUnit/CUnit.h" HAVE_CU_CURSES)
cmake_pop_check_state()
else()
message(WARNING "Could not find the cunit library!")
set(ENABLE_UNIT_TESTS OFF CACHE BOOL "Enable compilation of unit tests." FORCE)
endif()
if(LINPHONE_BUILDER_GROUP_EXTERNAL_SOURCE_PATH_BUILDERS)
set(BcToolbox_FIND_COMPONENTS tester)
include("${EP_bctoolbox_CONFIG_DIR}/BcToolboxConfig.cmake")
else()
find_package(BcToolbox REQUIRED OPTIONAL_COMPONENTS tester)
endif()
if(UNIX AND NOT APPLE)
......@@ -134,10 +126,10 @@ endif()
add_subdirectory(include)
add_subdirectory(src)
if(ENABLE_UNIT_TESTS)
# add_subdirectory(tests)
if(ENABLE_UNIT_TESTS AND BCTOOLBOX_TESTER_FOUND)
add_subdirectory(tester)
endif()
add_subdirectory(tools)
include(CMakePackageConfigHelpers)
export(EXPORT ${EXPORT_TARGETS_NAME}Targets
......@@ -155,4 +147,4 @@ install(EXPORT ${EXPORT_TARGETS_NAME}Targets
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/BelcardConfig.cmake"
DESTINATION ${ConfigPackageLocation}
)
\ No newline at end of file
)
SUBDIRS=include src tests
SUBDIRS=include src tester tools
......@@ -20,31 +20,15 @@
#
############################################################################
set(SOURCE_FILES_C
common/bc_tester_utils.c
)
file(GLOB SOURCE_FILES_CXX "belcard-*.cpp")
set(SOURCE_FILES_CXX
belcard-addressing-tester.cpp
belcard-calendar-tester.cpp
belcard-communication-tester.cpp
belcard-explanatory-tester.cpp
belcard-general-tester.cpp
belcard-geographical-tester.cpp
belcard-identification-tester.cpp
belcard-organizational-tester.cpp
belcard-rfc6474-tester.cpp
belcard-security-tester.cpp
belcard-tester.cpp
belcard-vcard-tester.cpp
)
apply_compile_flags(SOURCE_FILES_C "CPP" "C")
apply_compile_flags(SOURCE_FILES_CXX "CPP" "CXX")
add_definitions(-DBC_CONFIG_FILE="config.h")
add_executable(belcard-tester ${SOURCE_FILES_C} ${SOURCE_FILES_CXX})
add_executable(belcard-tester ${SOURCE_FILES_CXX})
set_target_properties(belcard-tester PROPERTIES LINKER_LANGUAGE CXX)
target_include_directories(belcard-tester PUBLIC ${CUNIT_INCLUDE_DIRS} PRIVATE common)
target_link_libraries(belcard-tester belcard ${CUNIT_LIBRARIES})
\ No newline at end of file
target_include_directories(belcard-tester PUBLIC ${BCTOOLBOX_TESTER_INCLUDE_DIRS})
target_link_libraries(belcard-tester belcard ${BCTOOLBOX_TESTER_LIBRARIES})
if(APPLE)
set_target_properties(belcard-tester PROPERTIES LINK_FLAGS "-stdlib=libc++")
endif()
EXTRA_DIST=vcards/vcard.vcf vcards/unfoldtest.vcf vcards/foldtest.vcf
bin_PROGRAMS=belcard-folder belcard-unfolder belcard-parser
if BUILD_TESTS
noinst_PROGRAMS=belcard-tester
......@@ -24,18 +22,9 @@ belcard_tester_CFLAGS=\
$(CUNIT_CFLAGS)
belcard_tester_AM_CPPFLAGS=-I$(top_srcdir)/include \
-I$(top_srcdir)/tester \
-I$(top_srcdir)/tester/common
-I$(top_srcdir)/tester \
-I$(top_srcdir)/tester/common
endif # BUILD_TESTS
belcard_folder_SOURCES=belcard-folder.cpp
belcard_folder_LDADD=$(top_builddir)/src/libbelcard.la -lbelr
belcard_unfolder_SOURCES=belcard-unfolder.cpp
belcard_unfolder_LDADD=$(top_builddir)/src/libbelcard.la -lbelr
belcard_parser_SOURCES=belcard-parser.cpp
belcard_parser_LDADD=$(top_builddir)/src/libbelcard.la -lbelr
AM_CPPFLAGS=-I$(top_srcdir)/include
......@@ -27,7 +27,7 @@ int main(int argc, char *argv[]) {
int ret;
belcard_tester_init(NULL);
if (strstr(argv[0], ".libs")) {
int prefix_length = strstr(argv[0], ".libs") - argv[0] + 1;
char prefix[200];
......@@ -35,7 +35,7 @@ int main(int argc, char *argv[]) {
bc_tester_set_resource_dir_prefix(prefix);
bc_tester_set_writable_dir_prefix(prefix);
}
for(i = 1; i < argc; ++i) {
int ret = bc_tester_parse_args(argc, argv, i);
if (ret>0) {
......@@ -68,8 +68,8 @@ static void log_handler(int lev, const char *fmt, va_list args) {
void belcard_tester_init(void(*ftester_printf)(int level, const char *fmt, va_list args)) {
if (ftester_printf == NULL) ftester_printf = log_handler;
bc_tester_init(ftester_printf, MESSAGE, ERROR);
bc_tester_init(ftester_printf, MESSAGE, ERROR, "vcards");
bc_tester_add_suite(&vcard_general_properties_test_suite);
bc_tester_add_suite(&vcard_identification_properties_test_suite);
bc_tester_add_suite(&vcard_addressing_properties_test_suite);
......@@ -85,4 +85,4 @@ void belcard_tester_init(void(*ftester_printf)(int level, const char *fmt, va_li
void belcard_tester_uninit(void) {
bc_tester_uninit();
}
\ No newline at end of file
}
......@@ -19,7 +19,7 @@
#ifndef belcard_tester_hpp
#define belcard_tester_hpp
#include "common/bc_tester_utils.h"
#include <bctoolbox/tester.h>
#include <string>
#include <memory>
......@@ -56,7 +56,7 @@ void test_property(const std::string& input) {
std::cout << "Couldn't parse " << input << std::endl;
}
BC_ASSERT_TRUE_FATAL(ptr != NULL);
std::string str = ptr->toString();
int compare = input.compare(str);
BC_ASSERT_EQUAL(compare, 0, int, "%d");
......
......@@ -16,10 +16,11 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "belcard/belcard_parser.hpp"
#include "belcard/belcard_utils.hpp"
#include "common/bc_tester_utils.h"
#include <bctoolbox/tester.h>
#include <iostream>
#include <fstream>
#include <sstream>
......@@ -33,7 +34,7 @@ static string openFile(const char *name) {
if (!istr.is_open()) {
BC_FAIL(name);
}
stringstream vcardStream;
vcardStream << istr.rdbuf();
string vcard = vcardStream.str();
......@@ -56,24 +57,24 @@ static void unfolding(void) {
static void vcard_parsing(void) {
string vcard = openFile("vcards/vcard.vcf");
BelCardParser parser = BelCardParser::getInstance();
shared_ptr<BelCard> belCard = parser.parseOne(vcard);
BC_ASSERT_TRUE_FATAL(belCard != NULL);
BC_ASSERT_TRUE(belCard->assertRFCCompliance());
string vcard2 = belCard->toFoldedString();
BC_ASSERT_EQUAL(vcard2.compare(vcard), 0, int, "%d");
}
static void vcards_parsing(void) {
string vcards = openFile("vcards/vcards.vcf");
BelCardParser parser = BelCardParser::getInstance();
shared_ptr<BelCardList> belCards = parser.parse(vcards);
BC_ASSERT_TRUE_FATAL(belCards != NULL);
BC_ASSERT_TRUE(belCards->getCards().size() == 2);
string vcards2 = belCards->toString();
BC_ASSERT_EQUAL(vcards2.compare(vcards), 0, int, "%d");
}
......@@ -82,12 +83,12 @@ static void create_vcard_from_api(void) {
shared_ptr<BelCard> belCard = BelCard::create<BelCard>();
BC_ASSERT_TRUE_FATAL(belCard != NULL);
BC_ASSERT_FALSE(belCard->assertRFCCompliance());
shared_ptr<BelCardFullName> fn = BelCard::create<BelCardFullName>();
fn->setValue("Sylvain Berfini");
belCard->setFullName(fn);
BC_ASSERT_TRUE(belCard->assertRFCCompliance());
string vcard = belCard->toString();
BelCardParser parser = BelCardParser::getInstance();
shared_ptr<BelCard> belCard2 = parser.parseOne(vcard);
......@@ -100,16 +101,16 @@ static void create_vcard_from_api(void) {
static void property_sort_using_pref_param(void) {
shared_ptr<BelCard> belCard = BelCard::create<BelCard>();
BC_ASSERT_TRUE(belCard != NULL);
shared_ptr<BelCardImpp> impp1 = BelCardImpp::parse("IMPP;TYPE=home;PREF=2:sip:viish@sip.linphone.org\r\n");
BC_ASSERT_TRUE(impp1 != NULL);
shared_ptr<BelCardImpp> impp2 = BelCardImpp::parse("IMPP;PREF=1;TYPE=work:sip:sylvain@sip.linphone.org\r\n");
BC_ASSERT_TRUE(impp2 != NULL);
belCard->addImpp(impp1);
belCard->addImpp(impp2);
const list<shared_ptr<BelCardImpp>> imppList = belCard->getImpp();
BC_ASSERT_TRUE(imppList.size() == 2);
BC_ASSERT_TRUE(imppList.front() == impp2);
......@@ -133,4 +134,4 @@ test_suite_t vcard_test_suite = {
NULL,
sizeof(tests) / sizeof(tests[0]),
tests
};
\ No newline at end of file
};
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
# Copyright (C) 2012 Belledonne Comunications, Grenoble, France
#
# 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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Created by Gautier Pelloux-Prayer on 2014/10/24.
# This script adds auto-completion for liblinphone_tester binary for Bash and
# Zsh. To use it, just type: `source liblinphone_completion`, then for each
# supported exectuable (see end of file), you will get auto-completions.
# To use it permanently, source this file in your .rc file (.bashrc or .zshrc).
_liblinphone_complete() {
local completions command_requiring_argument prev_arg latest_arg available_tasks has_not_set_suite suite_name
if [ -n "$BASH_VERSION" ]; then
set -- "${COMP_WORDS[@]}" #convert them to arguments (eg $1,$#,$@,etc.)
elif [ -n "$ZSH_VERSION" ]; then
local args
read -cA args #read list of arguments user entered
set -- "${args[@]}" #convert them to arguments (eg $1,$#,$@,etc.)
fi
#skip program name
program=$1
shift
# if user required help, do not complete anything
if ! grep -q -- "--help" <<< "$@"; then
# retrieve the last argument
latest_arg=""
prev_arg=""
latest_is_empty=0
for arg in "$@"; do
if [ ! -z "$arg" ]; then
prev_arg="$latest_arg"
latest_arg="$arg"
else
latest_is_empty=1
fi
done
# get the tasks available, from --help
available_tasks="$($program 2>&1 --help | sed -nE "s/.*--([^ ]*).*/--\\1/p")"
# these commands expect an argument
command_requiring_argument="$($program 2>&1 --help | sed -nE "s/.*--(.*) <.*/--\\1/p")"
# remove all already provided tasks (it's useless to provide them twice)
if [[ ! -z "$@" ]]; then
current_tasks=$(echo $@ | grep -Eo -- "--([^ ])*" | tr '\n' '|' | sed 's/|/$|/g')--$
if [ ! -z "$current_tasks" ]; then
available_tasks=$(echo "$available_tasks" | grep -vE -- "(${current_tasks})")
fi
fi
# remove --test option if --suite is not provided yet!
has_not_set_suite=$(grep -q -- "--suite" <<< "$@"; echo $?)
if [ $has_not_set_suite = 1 ]; then
available_tasks=$(echo "$available_tasks" | grep -v -- --test)
fi
# if latest arg does not start with '--', it is a custom value
if [ $latest_is_empty = 0 ] && ! grep -q -- '^--' <<< "$latest_arg"; then
if [ "$prev_arg" = "--test" ] && [ $has_not_set_suite = 0 ]; then
suite_name=$(echo $@ | sed -nE 's/.*--suite ([^(--)]*) (--.*)$/\1/p' |sed "s@\\\\@@g")
completions="$($program --list-tests $suite_name)"
elif [ "$prev_arg" = "--suite" ] || [ "$prev_arg" = "--list-tests" ]; then
completions="$($program --list-suites)"
fi
elif [ "$latest_arg" = "--test" ]; then
# list available tests if --suite was provided
if [ $has_not_set_suite = 0 ]; then
suite_name=$(echo $@ | sed -nE 's/.*--suite ([^(--)]*) (--.*)/\1/p' |sed "s@\\\\@@g")
completions="$($program --list-tests $suite_name)"
fi
elif [ "$latest_arg" = "--suite" ] || [ "$latest_arg" = "--list-tests" ]; then
completions="$($program --list-suites)"
# we are waiting for a custom value, so do not hint anything
elif [[ ! -z "$latest_arg" ]] && grep -q -- "^$latest_arg$" <<< "$command_requiring_argument"; then
completions=""
else
completions="$available_tasks"
fi
fi
if [ ! -z "$completions" ]; then
if [ -n "$BASH_VERSION" ]; then
IFS=$'\n' #if that even necessary?
COMPREPLY=($(compgen -W "${completions}" -- ${COMP_WORDS[COMP_CWORD]}))
elif [ -n "$ZSH_VERSION" ]; then
reply=( "${(ps:\n:)completions}" )
fi
fi
}
for tester in belcard-tester; do
if [ -n "$BASH_VERSION" ]; then
complete -F _liblinphone_complete $tester
elif [ -n "$ZSH_VERSION" ]; then
compctl -K _liblinphone_complete $tester
else
echo "Your shell might be not supported! Only bash and zsh tested."
fi
done
This diff is collapsed.
This diff is collapsed.
############################################################################
# CMakeLists.txt
# Copyright (C) 2015 Belledonne Communications, Grenoble France
#
############################################################################
#
# 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 2
# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
############################################################################
foreach(EXECTUABLE belcard-folder belcard-unfolder belcard-parser)
set(SOURCE_FILES_CXX ${EXECTUABLE}.cpp)
apply_compile_flags(SOURCE_FILES_CXX "CPP" "CXX")
add_executable(${EXECTUABLE} ${SOURCE_FILES_CXX})
set_target_properties(${EXECTUABLE} PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(${EXECTUABLE} belcard)
if(APPLE)
set_target_properties(${EXECTUABLE} PROPERTIES LINK_FLAGS "-stdlib=libc++")
endif()
install(TARGETS ${EXECTUABLE}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
)
endforeach()
bin_PROGRAMS=belcard-folder belcard-unfolder belcard-parser
belcard_folder_SOURCES=belcard-folder.cpp
belcard_folder_LDADD=$(top_builddir)/src/libbelcard.la -lbelr
belcard_unfolder_SOURCES=belcard-unfolder.cpp
belcard_unfolder_LDADD=$(top_builddir)/src/libbelcard.la -lbelr
belcard_parser_SOURCES=belcard-parser.cpp
belcard_parser_LDADD=$(top_builddir)/src/libbelcard.la -lbelr
AM_CPPFLAGS=-I$(top_srcdir)/include
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment