From a91d2fc4ab6a7671ad669a594a1c7114ed442636 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Sat, 16 Feb 2008 02:01:57 +0000 Subject: [PATCH] - rework the testsuite after new boost in factory broke it. - remove the feature to test on arbitrary directories - use testcase auto registration - remove lot lot of registration code - use a macro to add testcases, following the convention: Class1_test.cc then just use ADD_TESTS(Class1 Class2..) - port some testcases missing to boost --- CMakeLists.txt | 9 ++ tests/CMakeLists.txt | 9 +- tests/media/CMakeLists.txt | 180 +-------------------- tests/media/file_exists_test.cc | 21 +-- tests/media/{media1.cc => media1_test.cc} | 12 +- tests/media/{media2.cc => media2_test.cc} | 13 +- tests/media/{media3.cc => media3_test.cc} | 33 ++-- tests/media/{media4.cc => media4_test.cc} | 11 +- ...f_not_exists.cc => throw_if_not_exists_test.cc} | 0 tests/parser/inifile/CMakeLists.txt | 11 +- tests/parser/inifile/inidict_test.cc | 38 +---- tests/parser/inifile/iniparser_test.cc | 41 +---- tests/parser/yum/CMakeLists.txt | 14 +- tests/parser/yum/PatchFileReader_test.cc | 25 +-- tests/parser/yum/PatchesFileReader_test.cc | 34 +--- tests/parser/yum/RepomdFileReader_test.cc | 25 +-- tests/repo/CMakeLists.txt | 7 +- tests/repo/RepoVariables_test.cc | 33 +--- tests/repo/susetags/CMakeLists.txt | 9 +- tests/repo/susetags/Downloader_test.cc | 41 +---- tests/repo/yum/CMakeLists.txt | 6 +- tests/repo/yum/YUMDownloader_test.cc | 35 +--- tests/zypp/Arch_test.cc | 10 +- tests/zypp/CMakeLists.txt | 23 +-- tests/zypp/Capabilities_test.cc | 9 +- tests/zypp/CheckSum_test.cc | 20 +-- tests/zypp/Digest_test.cc | 22 +-- tests/zypp/Edition_test.cc | 11 +- tests/zypp/Fetcher_test.cc | 26 +-- tests/zypp/FileChecker_test.cc | 52 ++---- tests/zypp/KeyRing_test.cc | 56 ++----- tests/zypp/PathInfo_test.cc | 30 +--- tests/zypp/PoolQuery_test.cc | 26 +-- tests/zypp/ProgressData_test.cc | 15 +- tests/zypp/{PtrTypes.cc => PtrTypes_test.cc} | 8 +- tests/zypp/PublicKey_test.cc | 10 +- tests/zypp/{RWPtr.cc => RWPtr_test.cc} | 11 +- tests/zypp/RepoInfo_test.cc | 26 +-- tests/zypp/RepoManager_test.cc | 37 +---- tests/zypp/RepoStatus_test.cc | 14 +- tests/zypp/ResKind_test.cc | 9 +- tests/zypp/TranslatedText_test.cc | 17 +- tests/zypp/Url_test.cc | 23 +-- tests/zypp/Vendor1_test.cc | 49 ------ tests/zypp/{Vendor2_test.cc => Vendor_test.cc} | 37 ++--- tests/zypp/base/CMakeLists.txt | 7 +- tests/zypp/base/Sysconfig_test.cc | 49 +----- 47 files changed, 203 insertions(+), 1001 deletions(-) rename tests/media/{media1.cc => media1_test.cc} (79%) rename tests/media/{media2.cc => media2_test.cc} (92%) rename tests/media/{media3.cc => media3_test.cc} (84%) rename tests/media/{media4.cc => media4_test.cc} (89%) rename tests/media/{throw_if_not_exists.cc => throw_if_not_exists_test.cc} (100%) rename tests/zypp/{PtrTypes.cc => PtrTypes_test.cc} (97%) rename tests/zypp/{RWPtr.cc => RWPtr_test.cc} (92%) delete mode 100644 tests/zypp/Vendor1_test.cc rename tests/zypp/{Vendor2_test.cc => Vendor_test.cc} (62%) diff --git a/CMakeLists.txt b/CMakeLists.txt index cfd024d..6519983 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,15 @@ GENERATE_PACKAGING(${PACKAGE} ${VERSION}) INCLUDE(CPack) +MACRO(ADD_TESTS) + FOREACH( loop_var ${ARGV} ) + SET_SOURCE_FILES_PROPERTIES( ${loop_var}_test.cc COMPILE_FLAGS "-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN" ) + ADD_EXECUTABLE( ${loop_var}_test ${loop_var}_test.cc ) + TARGET_LINK_LIBRARIES( ${loop_var}_test zypp boost_unit_test_framework) + ADD_TEST( ${loop_var}_test ${CMAKE_CURRENT_BINARY_DIR}/${loop_var}_test) + ENDFOREACH( loop_var ) +ENDMACRO(ADD_TESTS) + #################################################################### FIND_PACKAGE(Rpm REQUIRED) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 23ea42b..0d5d8c7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,8 +2,7 @@ ENABLE_TESTING() ADD_DEFINITIONS( -DTESTS_SRC_DIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\" ) -#ADD_SUBDIRECTORY( cache ) -#ADD_SUBDIRECTORY( media ) -#ADD_SUBDIRECTORY( zypp ) -#ADD_SUBDIRECTORY( parser ) -#ADD_SUBDIRECTORY( repo ) +#ADD_SUBDIRECTORY( media EXCLUDE_FROM_ALL ) +ADD_SUBDIRECTORY( zypp ) +ADD_SUBDIRECTORY( parser ) +ADD_SUBDIRECTORY( repo ) diff --git a/tests/media/CMakeLists.txt b/tests/media/CMakeLists.txt index 937274d..ac4196c 100644 --- a/tests/media/CMakeLists.txt +++ b/tests/media/CMakeLists.txt @@ -1,180 +1,2 @@ -########### next target ############### - -SET(media2_SRCS -media2.cc -mymediaverifier.h -) - -KDE3_AUTOMOC(${media2_SRCS}) - -KDE3_ADD_EXECUTABLE(media2 ${media2_SRCS}) - -TARGET_LINK_LIBRARIES(media2 ${QT_AND_KDECORE_LIBS} ) - - -########### next target ############### - -SET(media3_SRCS -media3.cc -mymediaverifier.h -) - -KDE3_AUTOMOC(${media3_SRCS}) - -KDE3_ADD_EXECUTABLE(media3 ${media3_SRCS}) - -TARGET_LINK_LIBRARIES(media3 ${QT_AND_KDECORE_LIBS} ) - - -########### next target ############### - -SET(media4_SRCS -media4.cc -mymediaverifier.h -) - -KDE3_AUTOMOC(${media4_SRCS}) - -KDE3_ADD_EXECUTABLE(media4 ${media4_SRCS}) - -TARGET_LINK_LIBRARIES(media4 ${QT_AND_KDECORE_LIBS} ) - - -########### next target ############### - -SET(fileexists_SRCS -file_exists_test.cc -mymediaverifier.h -) - -KDE3_AUTOMOC(${fileexists_SRCS}) - -KDE3_ADD_EXECUTABLE(fileexists ${fileexists_SRCS}) - -TARGET_LINK_LIBRARIES(fileexists ${QT_AND_KDECORE_LIBS} boost_unit_test_framework ) - - -########### next target ############### - -SET(throw_if_not_exists_SRCS -throw_if_not_exists.cc -mymediaverifier.h -) - -KDE3_AUTOMOC(${throw_if_not_exists_SRCS}) - -KDE3_ADD_EXECUTABLE(throw_if_not_exists ${throw_if_not_exists_SRCS}) - -TARGET_LINK_LIBRARIES(throw_if_not_exists ${QT_AND_KDECORE_LIBS} boost_unit_test_framework ) - - -########### next target ############### - -SET(media1_SRCS -media1.cc -mymediaverifier.h -) - -KDE3_AUTOMOC(${media1_SRCS}) - -IF(KDE3_BUILD_TESTS) - -KDE3_ADD_EXECUTABLE(media1 ${media1_SRCS}) - -TARGET_LINK_LIBRARIES(media1 ${QT_AND_KDECORE_LIBS} boost_unit_test_framework ) - -ENDIF(KDE3_BUILD_TESTS) - -########### next target ############### - -SET(fileexists_SRCS -dummy.cpp -) - -KDE3_AUTOMOC(${fileexists_SRCS}) - -FILE(WRITE dummy.cpp "//autogenerated file by cmake\n") -IF(KDE3_BUILD_TESTS) - -KDE3_ADD_EXECUTABLE(fileexists ${fileexists_SRCS}) - -TARGET_LINK_LIBRARIES(fileexists ${QT_AND_KDECORE_LIBS} ) - -ENDIF(KDE3_BUILD_TESTS) - -########### next target ############### - -SET(throw_if_not_exists_SRCS -dummy.cpp -) - -KDE3_AUTOMOC(${throw_if_not_exists_SRCS}) - -FILE(WRITE dummy.cpp "//autogenerated file by cmake\n") -IF(KDE3_BUILD_TESTS) - -KDE3_ADD_EXECUTABLE(throw_if_not_exists ${throw_if_not_exists_SRCS}) - -TARGET_LINK_LIBRARIES(throw_if_not_exists ${QT_AND_KDECORE_LIBS} ) - -ENDIF(KDE3_BUILD_TESTS) - -########### install files ############### - - - - -#original Makefile.am contents follow: - -### Process this file with automake to produce Makefile.in -### ################################################## -# -## Do NOT list devel.* in subdirs. It's developers playgound and -## must not prevent anything from building. -#SUBDIRS = -# -### ################################################## -# -# -#TESTS = media1 fileexists -# -#noinst_PROGRAMS = media2 media3 media4 fileexists throw_if_not_exists -# -#check_PROGRAMS = media1 fileexists throw_if_not_exists -# -# -### ################################################## -# -#LDADD = $(top_srcdir)/zypp/lib@PACKAGE@.la -# -### ################################################## -# -#media1_SOURCES = media1.cc mymediaverifier.h -#media1_LDADD = $(LDADD) -lboost_unit_test_framework -# -#fileexists_SOURCES = file_exists_test.cc mymediaverifier.h -#fileexists_LDADD = $(LDADD) -lboost_unit_test_framework -# -#media2_SOURCES = media2.cc mymediaverifier.h -#media2_LDADD = $(LDADD) -# -#media3_SOURCES = media3.cc mymediaverifier.h -#media3_LDADD = $(LDADD) -# -#media4_SOURCES = media4.cc mymediaverifier.h -#media4_LDADD = $(LDADD) -# -#throw_if_not_exists_SOURCES = throw_if_not_exists.cc mymediaverifier.h -#throw_if_not_exists_LDADD = $(LDADD) -lboost_unit_test_framework -# -### ################################################## -# -#.PHONY: always -# -#$(noinst_PROGRAMS): $(top_srcdir)/zypp/lib@PACKAGE@.la -# -##$(top_srcdir)/zypp/lib@PACKAGE@.la: always -## $(MAKE) -C $(top_srcdir)/zypp -# -### ################################################## \ No newline at end of file +ADD_TESTS(media1 media2 media3 media4 file_exists throw_if_not_exists) \ No newline at end of file diff --git a/tests/media/file_exists_test.cc b/tests/media/file_exists_test.cc index b65bedd..3a06301 100644 --- a/tests/media/file_exists_test.cc +++ b/tests/media/file_exists_test.cc @@ -18,7 +18,7 @@ using namespace zypp::media; using boost::unit_test::test_suite; using boost::unit_test::test_case; -void http_test() +BOOST_AUTO_TEST_CASE(http_test) { //MediaVerifierRef verifier( new MyMediaVerifier() ); MediaManager mm; @@ -58,7 +58,7 @@ void ftp_test() mm.release(id); } -void iso_test() +BOOST_AUTO_TEST_CASE(isotest) { if ( geteuid() != 0 ) { @@ -83,7 +83,7 @@ void iso_test() mm.release(id); } -void nfs_test() +BOOST_AUTO_TEST_CASE(nfs_tst) { if ( geteuid() != 0 ) { @@ -103,19 +103,4 @@ void nfs_test() } -test_suite* -init_unit_test_suite( int, char* [] ) -{ - //tests would need root-privileges - test_suite* test= BOOST_TEST_SUITE( "MediaFileExistTest" ); - //test->add( BOOST_TEST_CASE( &nfs_test ), 0 /* expected zero error */ ); - test->add( BOOST_TEST_CASE( &http_test ), 0 /* expected zero error */ ); - test->add( BOOST_TEST_CASE( &ftp_test ), 0 /* expected zero error */ ); - //test->add( BOOST_TEST_CASE( &iso_test ), 0 /* expected zero error */ ); - //test->add( BOOST_TEST_CASE( &nfs_test ), 0 /* expected zero error */ ); - return test; -} - - - // vim: set ts=2 sts=2 sw=2 ai et: diff --git a/tests/media/media1.cc b/tests/media/media1_test.cc similarity index 79% rename from tests/media/media1.cc rename to tests/media/media1_test.cc index 867ecc2..31e12c5 100644 --- a/tests/media/media1.cc +++ b/tests/media/media1_test.cc @@ -17,7 +17,7 @@ using namespace zypp::media; using boost::unit_test::test_suite; using boost::unit_test::test_case; -void verifier_test() +BOOST_AUTO_TEST_CASE(verifier_test) { MediaVerifierRef verifier( new MyMediaVerifier(/* "SUSE-Linux-CORE-i386 9" */) @@ -35,14 +35,4 @@ void verifier_test() mm.provideFile(id, Pathname("/suse/setup/descr/EXTRA_PROV")); } -test_suite* -init_unit_test_suite( int, char* [] ) -{ - test_suite* test= BOOST_TEST_SUITE( "MediaVerifierTest" ); - test->add( BOOST_TEST_CASE( &verifier_test ), 0 /* expected zero error */ ); - return test; -} - - - // vim: set ts=2 sts=2 sw=2 ai et: diff --git a/tests/media/media2.cc b/tests/media/media2_test.cc similarity index 92% rename from tests/media/media2.cc rename to tests/media/media2_test.cc index aa8716a..39e842a 100644 --- a/tests/media/media2.cc +++ b/tests/media/media2_test.cc @@ -12,6 +12,11 @@ #include "mymediaverifier.h" +#include + +using boost::unit_test::test_suite; +using boost::unit_test::test_case; + using namespace zypp; using namespace zypp::media; @@ -36,7 +41,7 @@ do { \ if( do_step) { pause(); if( do_quit) exit(0); } \ } while(0); -int main(int argc, char *argv[]) +BOOST_AUTO_TEST_CASE(strange_test) { { struct sigaction sa; @@ -47,8 +52,8 @@ int main(int argc, char *argv[]) sa.sa_handler = quit; sigaction(SIGTERM, &sa, NULL); - if( argc > 1 && std::string(argv[1]) == "-i") - do_step = true; + //if( argc > 1 && std::string(argv[1]) == "-i") + // do_step = true; } MediaVerifierRef verifier( @@ -142,8 +147,6 @@ int main(int argc, char *argv[]) // hmm... ERR << "Catched *unknown* exception" << std::endl; } - - return 0; } // vim: set ts=2 sts=2 sw=2 ai et: diff --git a/tests/media/media3.cc b/tests/media/media3_test.cc similarity index 84% rename from tests/media/media3.cc rename to tests/media/media3_test.cc index 0679b1f..988f291 100644 --- a/tests/media/media3.cc +++ b/tests/media/media3_test.cc @@ -12,6 +12,11 @@ #include "mymediaverifier.h" +#include + +using boost::unit_test::test_suite; +using boost::unit_test::test_case; + using namespace zypp; using namespace zypp::media; @@ -35,7 +40,7 @@ do { \ if( do_step) { pause(); if( do_quit) exit(0); } \ } while(0); -int main(int argc, char *argv[]) +BOOST_AUTO_TEST_CASE(strange_test) { bool eject_src = false; bool close_src = false; @@ -48,18 +53,18 @@ int main(int argc, char *argv[]) sa.sa_handler = quit; sigaction(SIGTERM, &sa, NULL); - std::cerr << "ARGS=" << argc << std::endl; - for(int i=1; i < argc; i++) - { - if( std::string(argv[i]) == "-i") - do_step = true; - else - if( std::string(argv[i]) == "-e") - eject_src = true; - else - if( std::string(argv[i]) == "-c") - close_src = true; - } +// std::cerr << "ARGS=" << argc << std::endl; +// for(int i=1; i < argc; i++) +// { +// if( std::string(argv[i]) == "-i") +// do_step = true; +// else +// if( std::string(argv[i]) == "-e") +// eject_src = true; +// else +// if( std::string(argv[i]) == "-c") +// close_src = true; +// } } MediaVerifierRef verifier( @@ -148,8 +153,6 @@ int main(int argc, char *argv[]) // hmm... ERR << "Catched *unknown* exception" << std::endl; } - - return 0; } // vim: set ts=2 sts=2 sw=2 ai et: diff --git a/tests/media/media4.cc b/tests/media/media4_test.cc similarity index 89% rename from tests/media/media4.cc rename to tests/media/media4_test.cc index e731b4d..4f4e93a 100644 --- a/tests/media/media4.cc +++ b/tests/media/media4_test.cc @@ -13,7 +13,10 @@ #include #include +#include +using boost::unit_test::test_suite; +using boost::unit_test::test_case; using namespace zypp; using namespace zypp::media; @@ -37,7 +40,7 @@ do { \ if( do_step) { pause(); if( do_quit) exit(0); } \ } while(0); -int main(int argc, char *argv[]) +BOOST_AUTO_TEST_CASE(strange_test) { { struct sigaction sa; @@ -48,8 +51,8 @@ int main(int argc, char *argv[]) sa.sa_handler = quit; sigaction(SIGTERM, &sa, NULL); - if( argc > 1 && std::string(argv[1]) == "-i") - do_step = true; +// if( argc > 1 && std::string(argv[1]) == "-i") +// do_step = true; } MediaManager mm; @@ -93,8 +96,6 @@ int main(int argc, char *argv[]) // hmm... ERR << "Catched *unknown* exception" << std::endl; } - - return 0; } // vim: set ts=2 sts=2 sw=2 ai et: diff --git a/tests/media/throw_if_not_exists.cc b/tests/media/throw_if_not_exists_test.cc similarity index 100% rename from tests/media/throw_if_not_exists.cc rename to tests/media/throw_if_not_exists_test.cc diff --git a/tests/parser/inifile/CMakeLists.txt b/tests/parser/inifile/CMakeLists.txt index 1690b20..25e1113 100644 --- a/tests/parser/inifile/CMakeLists.txt +++ b/tests/parser/inifile/CMakeLists.txt @@ -1,11 +1,2 @@ -ADD_DEFINITIONS( -DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN ) -ADD_EXECUTABLE( inifile iniparser_test.cc ) -TARGET_LINK_LIBRARIES( inifile zypp boost_unit_test_framework ) - -ADD_TEST(inifile ${CMAKE_CURRENT_BINARY_DIR}/inifile ${CMAKE_CURRENT_SOURCE_DIR}/data ) - -ADD_EXECUTABLE( inidict inidict_test.cc ) -TARGET_LINK_LIBRARIES( inidict zypp boost_unit_test_framework ) - -ADD_TEST(inidict ${CMAKE_CURRENT_BINARY_DIR}/inifile ${CMAKE_CURRENT_SOURCE_DIR}/data ) +ADD_TESTS(inidict iniparser) \ No newline at end of file diff --git a/tests/parser/inifile/inidict_test.cc b/tests/parser/inifile/inidict_test.cc index dcdd4ae..f5b6370 100644 --- a/tests/parser/inifile/inidict_test.cc +++ b/tests/parser/inifile/inidict_test.cc @@ -4,8 +4,6 @@ #include #include #include -#include -#include #include "zypp/base/Logger.h" #include "zypp/base/InputStream.h" @@ -21,10 +19,11 @@ using namespace zypp; using namespace zypp::parser; using namespace boost::unit_test; +#define DATADIR (Pathname(TESTS_SRC_DIR) + "/parser/inifile/data") -void ini_read_test(const string &dir) +BOOST_AUTO_TEST_CASE(ini_read) { - InputStream is((Pathname(dir)+"/1.ini")); + InputStream is((DATADIR+"/1.ini")); IniDict dict(is); //MIL << dict["homedmacvicar"]["type"] << endl; @@ -45,9 +44,9 @@ void ini_read_test(const string &dir) BOOST_CHECK( !dict.hasEntry("foo", "bar") ); } -void ini_read_test2(const string &dir) +BOOST_AUTO_TEST_CASE(ini_read2) { - InputStream is((Pathname(dir)+"/2.ini")); + InputStream is((DATADIR+"/2.ini")); IniDict dict(is); BOOST_CHECK( find( dict.sectionsBegin(), dict.sectionsEnd(), "base" ) != dict.sectionsEnd() ); @@ -55,31 +54,4 @@ void ini_read_test2(const string &dir) //BOOST_CHECK( i != dict.entriesEnd("base") ); } -test_suite* -init_unit_test_suite( int argc, char *argv[] ) -{ - string datadir; - if (argc < 2) - { - datadir = TESTS_SRC_DIR; - datadir = (Pathname(datadir) + "/parser/inifile/data").asString(); - cout << "inidict_test:" - " path to directory with test data required as parameter. Using " << datadir << endl; - //return (test_suite *)0; - } - else - { - datadir = argv[1]; - } - - test_suite* test= BOOST_TEST_SUITE("ini_file"); - - std::string const params[] = { datadir }; - test->add(BOOST_PARAM_TEST_CASE(&ini_read_test, - (std::string const*)params, params+1)); - test->add(BOOST_PARAM_TEST_CASE(&ini_read_test2, - (std::string const*)params, params+1)); - return test; -} - // vim: set ts=2 sts=2 sw=2 ai et: diff --git a/tests/parser/inifile/iniparser_test.cc b/tests/parser/inifile/iniparser_test.cc index b4acb1b..bb647fc 100644 --- a/tests/parser/inifile/iniparser_test.cc +++ b/tests/parser/inifile/iniparser_test.cc @@ -4,8 +4,6 @@ #include #include #include -#include -#include #include "zypp/base/Logger.h" #include "zypp/base/InputStream.h" @@ -20,6 +18,8 @@ using namespace zypp; using namespace zypp::parser; using namespace boost::unit_test; +#define DATADIR (Pathname(TESTS_SRC_DIR) + "/parser/inifile/data") + class IniTest : public IniParser { virtual void consume( const std::string §ion ) @@ -69,45 +69,16 @@ class WithSpacesTest : public IniParser } }; -void ini_read_test(const string &dir) +BOOST_AUTO_TEST_CASE(ini_read) { - InputStream is((Pathname(dir)+"/1.ini")); + InputStream is((DATADIR+"/1.ini")); IniTest parser; parser.parse(is); } -void ini_spaces_test(const string &dir) +BOOST_AUTO_TEST_CASE(ini_spaces_test) { - InputStream is((Pathname(dir)+"/2.ini")); + InputStream is((DATADIR+"/2.ini")); WithSpacesTest parser; parser.parse(is); } - -test_suite* -init_unit_test_suite( int argc, char *argv[] ) -{ - string datadir; - if (argc < 2) - { - datadir = TESTS_SRC_DIR; - datadir = (Pathname(datadir) + "/parser/inifile/data").asString(); - cout << "inifile_test:" - " path to directory with test data required as parameter. Using " << datadir << endl; - //return (test_suite *)0; - } - else - { - datadir = argv[1]; - } - - test_suite* test= BOOST_TEST_SUITE("ini_file"); - - std::string const params[] = { datadir }; - test->add(BOOST_PARAM_TEST_CASE(&ini_read_test, - (std::string const*)params, params+1)); - test->add(BOOST_PARAM_TEST_CASE(&ini_spaces_test, - (std::string const*)params, params+1)); - return test; -} - -// vim: set ts=2 sts=2 sw=2 ai et: diff --git a/tests/parser/yum/CMakeLists.txt b/tests/parser/yum/CMakeLists.txt index 8dd5271..7893bb6 100644 --- a/tests/parser/yum/CMakeLists.txt +++ b/tests/parser/yum/CMakeLists.txt @@ -1,14 +1,2 @@ -ADD_DEFINITIONS( -DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN ) -ADD_EXECUTABLE( RepomdFileReader RepomdFileReader_test.cc ) -TARGET_LINK_LIBRARIES( RepomdFileReader zypp boost_unit_test_framework ) - -ADD_EXECUTABLE( PatchesFileReader PatchesFileReader_test.cc ) -TARGET_LINK_LIBRARIES( PatchesFileReader zypp boost_unit_test_framework ) - -ADD_EXECUTABLE( PatchFileReader PatchFileReader_test.cc ) -TARGET_LINK_LIBRARIES( PatchFileReader zypp boost_unit_test_framework ) - -ADD_TEST(RepomdFileReader ${CMAKE_CURRENT_BINARY_DIR}/RepomdFileReader ${CMAKE_CURRENT_SOURCE_DIR}/data ) -ADD_TEST(PatchesFileReader ${CMAKE_CURRENT_BINARY_DIR}/PatchesFileReader ${CMAKE_CURRENT_SOURCE_DIR}/data ) -ADD_TEST(PatchFileReader ${CMAKE_CURRENT_BINARY_DIR}/PatchFileReader ${CMAKE_CURRENT_SOURCE_DIR}/data ) +ADD_TESTS(RepomdFileReader PatchesFileReader PatchFileReader) \ No newline at end of file diff --git a/tests/parser/yum/PatchFileReader_test.cc b/tests/parser/yum/PatchFileReader_test.cc index 9eb0bb5..272c07b 100644 --- a/tests/parser/yum/PatchFileReader_test.cc +++ b/tests/parser/yum/PatchFileReader_test.cc @@ -1,6 +1,4 @@ #include -#include -#include #include "zypp/base/Easy.h" #include "zypp/Url.h" @@ -14,6 +12,8 @@ using namespace boost::unit_test; using namespace zypp; using namespace zypp::parser::yum; +#define DATADIR (Pathname(TESTS_SRC_DIR) + "parser/yum/data") + struct Check_fetchmsttfonts { bool operator()( const data::Patch_Ptr & data_r ) @@ -62,24 +62,7 @@ void patch_read_test( const Pathname & file_r ) PatchFileReader( file_r, Check_fetchmsttfonts() ); } -test_suite * init_unit_test_suite( int argc, char * argv[] ) +BOOST_AUTO_TEST_CASE(patch_read) { - Pathname patchfile; - --argc; ++argv; - if ( argc ) - { - patchfile = argv[0]; - if ( PathInfo( patchfile ).isDir() ) - patchfile /= "patch-fetchmsttfonts.sh-4347.xml"; - } - else - { - patchfile = TESTS_SRC_DIR; - patchfile /= "parser/yum/data/patch-fetchmsttfonts.sh-4347.xml"; - } - - test_suite * test = BOOST_TEST_SUITE( "PatchFileReader" ); - test->add( BOOST_PARAM_TEST_CASE( &patch_read_test, &patchfile, &patchfile+1 ) ); - - return test; + patch_read_test(DATADIR + "patch-fetchmsttfonts.sh-4347.xml"); } diff --git a/tests/parser/yum/PatchesFileReader_test.cc b/tests/parser/yum/PatchesFileReader_test.cc index 033a3f1..71b7d01 100644 --- a/tests/parser/yum/PatchesFileReader_test.cc +++ b/tests/parser/yum/PatchesFileReader_test.cc @@ -4,8 +4,6 @@ #include #include #include -#include -#include #include "zypp/OnMediaLocation.h" #include "zypp/parser/yum/PatchesFileReader.h" @@ -18,6 +16,8 @@ using namespace boost::unit_test; using namespace zypp::parser::yum; +#define DATADIR (Pathname(TESTS_SRC_DIR) + "/parser/yum/data") + class Collector { public: @@ -36,10 +36,10 @@ public: //vector items; }; -void patches_read_test(const string &dir) +BOOST_AUTO_TEST_CASE(patches_read_test) { list entries; - if ( filesystem::readdir( entries, Pathname(dir), false ) != 0 ) + if ( filesystem::readdir( entries, DATADIR, false ) != 0 ) ZYPP_THROW(Exception("failed to read directory")); for ( list::const_iterator it = entries.begin(); it != entries.end(); ++it ) @@ -78,30 +78,4 @@ void patches_read_test(const string &dir) } } -test_suite* -init_unit_test_suite( int argc, char *argv[] ) -{ - string datadir; - if (argc < 2) - { - datadir = TESTS_SRC_DIR; - datadir = (Pathname(datadir) + "/parser/yum/data").asString(); - cout << "PatchesFileReader_test:" - " path to directory with test data required as parameter. Using " << datadir << endl; - //return (test_suite *)0; - - } - else - { - datadir = argv[1]; - } - - test_suite* test= BOOST_TEST_SUITE("PatchesFileReader"); - - std::string const params[] = { datadir }; - test->add(BOOST_PARAM_TEST_CASE(&patches_read_test, - (std::string const*)params, params+1)); - return test; -} - // vim: set ts=2 sts=2 sw=2 ai et: diff --git a/tests/parser/yum/RepomdFileReader_test.cc b/tests/parser/yum/RepomdFileReader_test.cc index 8398a3e..b6aa3c5 100644 --- a/tests/parser/yum/RepomdFileReader_test.cc +++ b/tests/parser/yum/RepomdFileReader_test.cc @@ -4,8 +4,6 @@ #include #include #include -#include -#include #include "zypp/parser/yum/RepomdFileReader.h" #include "zypp/Url.h" @@ -18,6 +16,8 @@ using namespace boost::unit_test; using namespace zypp::parser::yum; using repo::yum::ResourceType; +#define DATADIR (Pathname(TESTS_SRC_DIR) + "parser/yum/data") + class Collector { public: @@ -36,10 +36,10 @@ public: //vector items; }; -void repomd_read_test(const string &dir) +BOOST_AUTO_TEST_CASE(repomd_read) { list entries; - if ( filesystem::readdir( entries, Pathname(dir), false ) != 0 ) + if ( filesystem::readdir( entries, DATADIR, false ) != 0 ) ZYPP_THROW(Exception("failed to read directory")); for ( list::const_iterator it = entries.begin(); it != entries.end(); ++it ) @@ -77,22 +77,5 @@ void repomd_read_test(const string &dir) } } -test_suite* -init_unit_test_suite( int argc, char *argv[] ) -{ - if (argc < 2) - { - cout << "RepomdFileReader_test:" - " path to directory with test data required as parameter" << endl; - return (test_suite *)0; - } - - test_suite* test= BOOST_TEST_SUITE("RepomdFileReader"); - string datadir = argv[1]; - std::string const params[] = { datadir }; - test->add(BOOST_PARAM_TEST_CASE(&repomd_read_test, - (std::string const*)params, params+1)); - return test; -} // vim: set ts=2 sts=2 sw=2 ai et: diff --git a/tests/repo/CMakeLists.txt b/tests/repo/CMakeLists.txt index b0a26bf..571c9ca 100644 --- a/tests/repo/CMakeLists.txt +++ b/tests/repo/CMakeLists.txt @@ -1,9 +1,4 @@ -ADD_DEFINITIONS( -DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN ) - ADD_SUBDIRECTORY( yum ) ADD_SUBDIRECTORY( susetags ) -ADD_EXECUTABLE( RepoVariables RepoVariables_test.cc ) -TARGET_LINK_LIBRARIES( RepoVariables zypp boost_unit_test_framework ) - -ADD_TEST(RepoVariables ${CMAKE_CURRENT_BINARY_DIR}/RepoVariables ${CMAKE_CURRENT_SOURCE_DIR}/data ) +ADD_TESTS(RepoVariables) diff --git a/tests/repo/RepoVariables_test.cc b/tests/repo/RepoVariables_test.cc index c5b1e7e..69ee58b 100644 --- a/tests/repo/RepoVariables_test.cc +++ b/tests/repo/RepoVariables_test.cc @@ -4,8 +4,6 @@ #include #include #include -#include -#include #include "zypp/ZYppFactory.h" #include "zypp/Url.h" @@ -19,10 +17,11 @@ using std::endl; using std::string; using namespace zypp; using namespace boost::unit_test; - using namespace zypp::repo; -void replace_test(const string &dir) +#define DATADIR (Pathname(TESTS_SRC_DIR) + "/repo/yum/data") + +BOOST_AUTO_TEST_CASE(replace_text) { /* check RepoVariablesStringReplacer */ @@ -49,30 +48,4 @@ void replace_test(const string &dir) "http://site.org/update/?arch=i686"); } -test_suite* -init_unit_test_suite( int argc, char *argv[] ) -{ - string datadir; - if (argc < 2) - { - datadir = TESTS_SRC_DIR; - datadir = (Pathname(datadir) + "/repo/yum/data").asString(); - cout << "RepoVariables_test:" - " path to directory with test data required as parameter. Using " << datadir << endl; - //return (test_suite *)0; - - } - else - { - datadir = argv[1]; - } - - test_suite* test= BOOST_TEST_SUITE("RepoVariables"); - - std::string const params[] = { datadir }; - test->add(BOOST_PARAM_TEST_CASE(&replace_test, - (std::string const*)params, params+1)); - return test; -} - // vim: set ts=2 sts=2 sw=2 ai et: diff --git a/tests/repo/susetags/CMakeLists.txt b/tests/repo/susetags/CMakeLists.txt index f59dffc..4993c4e 100644 --- a/tests/repo/susetags/CMakeLists.txt +++ b/tests/repo/susetags/CMakeLists.txt @@ -1,9 +1,2 @@ -ADD_DEFINITIONS( -DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN ) -ADD_EXECUTABLE( - Downloader - Downloader_test.cc -) -TARGET_LINK_LIBRARIES( Downloader zypp boost_unit_test_framework ) - -ADD_TEST(Downloader ${CMAKE_CURRENT_BINARY_DIR}/Downloader ${CMAKE_CURRENT_SOURCE_DIR}/data ) +ADD_TESTS(Downloader) \ No newline at end of file diff --git a/tests/repo/susetags/Downloader_test.cc b/tests/repo/susetags/Downloader_test.cc index f05df92..a474651 100644 --- a/tests/repo/susetags/Downloader_test.cc +++ b/tests/repo/susetags/Downloader_test.cc @@ -4,8 +4,6 @@ #include #include #include -#include -#include #include "zypp/base/Logger.h" #include "zypp/Url.h" @@ -20,15 +18,16 @@ using std::endl; using std::string; using namespace zypp; using namespace boost::unit_test; - using namespace zypp::repo; -void susetags_download_test(const string &dir) +#define DATADIR (Pathname(TESTS_SRC_DIR) + "/repo/susetags/data") + +BOOST_AUTO_TEST_CASE(susetags_download) { KeyRingTestReceiver keyring_callbacks; keyring_callbacks.answerTrustKey(true); - Pathname p = dir + "/stable-x86-subset"; + Pathname p = DATADIR + "/stable-x86-subset"; Url url("dir:" + p.asString()); MediaSetAccess media(url); susetags::Downloader downloader("/"); @@ -79,12 +78,12 @@ void susetags_download_test(const string &dir) } -void susetags_gz_download_test(const string &dir) +BOOST_AUTO_TEST_CASE(susetags_gz_download) { KeyRingTestReceiver keyring_callbacks; keyring_callbacks.answerTrustKey(true); - Pathname p = dir + "/stable-x86-subset-gz"; + Pathname p = DATADIR + "/stable-x86-subset-gz"; Url url("dir:" + p.asString()); MediaSetAccess media(url); susetags::Downloader downloader("/"); @@ -135,32 +134,4 @@ void susetags_gz_download_test(const string &dir) } -test_suite* -init_unit_test_suite( int argc, char *argv[] ) -{ - string datadir; - if (argc < 2) - { - datadir = TESTS_SRC_DIR; - datadir = (Pathname(datadir) + "/repo/susetags/data").asString(); - cout << "SUSETags Downloader_test:" - " path to directory with test data required as parameter. Using " << datadir << endl; - //return (test_suite *)0; - - } - else - { - datadir = argv[1]; - } - - test_suite* test= BOOST_TEST_SUITE("SUSETags Downloader"); - - std::string const params[] = { datadir }; - test->add(BOOST_PARAM_TEST_CASE(&susetags_download_test, - (std::string const*)params, params+1)); - test->add(BOOST_PARAM_TEST_CASE(&susetags_gz_download_test, - (std::string const*)params, params+1)); - return test; -} - // vim: set ts=2 sts=2 sw=2 ai et: diff --git a/tests/repo/yum/CMakeLists.txt b/tests/repo/yum/CMakeLists.txt index 7e82258..de237c0 100644 --- a/tests/repo/yum/CMakeLists.txt +++ b/tests/repo/yum/CMakeLists.txt @@ -1,6 +1,2 @@ -ADD_DEFINITIONS( -DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN ) -ADD_EXECUTABLE( YUMDownloader YUMDownloader_test.cc ) -TARGET_LINK_LIBRARIES( YUMDownloader zypp boost_unit_test_framework ) - -ADD_TEST(YUMDownloader ${CMAKE_CURRENT_BINARY_DIR}/YUMDownloader ${CMAKE_CURRENT_SOURCE_DIR}/data ) +ADD_TESTS(YUMDownloader) \ No newline at end of file diff --git a/tests/repo/yum/YUMDownloader_test.cc b/tests/repo/yum/YUMDownloader_test.cc index 952af39..993d230 100644 --- a/tests/repo/yum/YUMDownloader_test.cc +++ b/tests/repo/yum/YUMDownloader_test.cc @@ -4,8 +4,6 @@ #include #include #include -#include -#include #include "zypp/base/Logger.h" #include "zypp/Url.h" @@ -18,17 +16,18 @@ using std::endl; using std::string; using namespace zypp; using namespace boost::unit_test; - using namespace zypp::repo; #include "tests/zypp/KeyRingTestReceiver.h" -void yum_download_test(const string &dir) +#define DATADIR (Pathname(TESTS_SRC_DIR) + "/repo/yum/data") + +BOOST_AUTO_TEST_CASE(yum_download) { KeyRingTestReceiver keyring_callbacks; keyring_callbacks.answerTrustKey(true); - Pathname p = dir + "/10.2-updates-subset"; + Pathname p = DATADIR + "/10.2-updates-subset"; Url url("dir:" + p.asString()); MediaSetAccess media(url); yum::Downloader yum("/"); @@ -65,30 +64,4 @@ void yum_download_test(const string &dir) } -test_suite* -init_unit_test_suite( int argc, char *argv[] ) -{ - string datadir; - if (argc < 2) - { - datadir = TESTS_SRC_DIR; - datadir = (Pathname(datadir) + "/repo/yum/data").asString(); - cout << "YUMDownloader_test:" - " path to directory with test data required as parameter. Using " << datadir << endl; - //return (test_suite *)0; - - } - else - { - datadir = argv[1]; - } - - test_suite* test= BOOST_TEST_SUITE("YUMDownloader"); - - std::string const params[] = { datadir }; - test->add(BOOST_PARAM_TEST_CASE(&yum_download_test, - (std::string const*)params, params+1)); - return test; -} - // vim: set ts=2 sts=2 sw=2 ai et: diff --git a/tests/zypp/Arch_test.cc b/tests/zypp/Arch_test.cc index 075872a..7a46dd2 100644 --- a/tests/zypp/Arch_test.cc +++ b/tests/zypp/Arch_test.cc @@ -29,7 +29,7 @@ using namespace zypp; ** ** DESCRIPTION : */ -void arch_test() +BOOST_AUTO_TEST_CASE(arch_test) { Arch _arch32( "i386" ); @@ -43,11 +43,3 @@ void arch_test() BOOST_REQUIRE( ! Arch_noarch.empty() ); BOOST_REQUIRE( ! ( _arch32.compare(Arch_x86_64) >= 0) ); } - -test_suite* -init_unit_test_suite( int, char* [] ) -{ - test_suite* test= BOOST_TEST_SUITE( "ArchTest" ); - test->add( BOOST_TEST_CASE( &arch_test ), 0 /* expected zero error */ ); - return test; -} diff --git a/tests/zypp/CMakeLists.txt b/tests/zypp/CMakeLists.txt index d25da0a..4372fa9 100644 --- a/tests/zypp/CMakeLists.txt +++ b/tests/zypp/CMakeLists.txt @@ -1,25 +1,4 @@ -# source: ${loop_var}_test.cc -# executable: ${loop_var}_test -# test: ${loop_var}_test ADD_SUBDIRECTORY(base) -ADD_DEFINITIONS( -DBOOST_TEST_DYN_LINK ) - -#FOREACH( loop_var Vendor1 Vendor2 TranslatedText PoolQuery KeyRing MediaSetAccess ResKind Arch Url Edition Capabilities CheckSum PublicKey PathInfo Digest Fetcher FileChecker RepoManager RepoInfo RepoStatus ProgressData ) -FOREACH( loop_var PoolQuery ) - ADD_EXECUTABLE( ${loop_var}_test ${loop_var}_test.cc ) - TARGET_LINK_LIBRARIES( ${loop_var}_test zypp boost_unit_test_framework) - ADD_TEST( ${loop_var}_test ${CMAKE_CURRENT_BINARY_DIR}/${loop_var}_test) -ENDFOREACH( loop_var ) - -ADD_EXECUTABLE(RWPtr RWPtr.cc) -TARGET_LINK_LIBRARIES(RWPtr zypp) - -ADD_EXECUTABLE(PtrTypes PtrTypes.cc) -TARGET_LINK_LIBRARIES(PtrTypes zypp ) - -#ADD_EXECUTABLE(Signature Signature.cc) -#TARGET_LINK_LIBRARIES(Signature zypp boost_unit_test_framework) - -ADD_TEST(PtrTypesTest ${CMAKE_CURRENT_BINARY_DIR}/PtrTypes) +ADD_TESTS(RWPtr Vendor TranslatedText PoolQuery KeyRing MediaSetAccess ResKind Arch Url Edition Capabilities CheckSum PublicKey PathInfo Digest Fetcher FileChecker RepoManager RepoInfo RepoStatus ProgressData ) diff --git a/tests/zypp/Capabilities_test.cc b/tests/zypp/Capabilities_test.cc index 7e84107..2dc570b 100644 --- a/tests/zypp/Capabilities_test.cc +++ b/tests/zypp/Capabilities_test.cc @@ -17,7 +17,7 @@ using boost::test_tools::close_at_tolerance; using namespace std; using namespace zypp; -void capabilities_test() +BOOST_AUTO_TEST_CASE(capabilities_test) { // Resolvable::Kind kind = ResTraits::kind; // CapFactory factory; @@ -80,10 +80,3 @@ void capabilities_test() BOOST_CHECK_EQUAL( Capability::matches( c0, c1 ), CapMatch::yes ); } -test_suite* -init_unit_test_suite( int, char* [] ) -{ - test_suite* test= BOOST_TEST_SUITE( "CapabilitiesTest" ); - test->add( BOOST_TEST_CASE( &capabilities_test ), 0 /* expected zero error */ ); - return test; -} diff --git a/tests/zypp/CheckSum_test.cc b/tests/zypp/CheckSum_test.cc index 69336b9..0de9221 100644 --- a/tests/zypp/CheckSum_test.cc +++ b/tests/zypp/CheckSum_test.cc @@ -4,27 +4,20 @@ #include // Boost.Test -#include #include -using boost::unit_test::test_suite; -using boost::unit_test::test_case; -using boost::test_tools::close_at_tolerance; - -// parameterized test -// http://www.boost.org/libs/test/example/unit_test_example4.cpp - #include "zypp/base/Logger.h" #include "zypp/base/Exception.h" #include "zypp/ZYppFactory.h" #include "zypp/ZYpp.h" +using boost::unit_test::test_case; using namespace std; using namespace zypp; // most frequently you implement test cases as a free functions -void checksum_test() +BOOST_AUTO_TEST_CASE(checksum_test) { BOOST_CHECK_THROW( CheckSum( "sha1", "dsdsads" ), Exception ); // wrong size BOOST_CHECK_THROW( CheckSum( "sha256", "dsdsads" ), Exception ); // wrong size @@ -33,12 +26,3 @@ void checksum_test() BOOST_CHECK_THROW( CheckSum( "md2", "dsdsads" ), Exception ); // wrong size } - -test_suite* -init_unit_test_suite( int, char* [] ) -{ - test_suite* test= BOOST_TEST_SUITE( "CheckSumTest" ); - test->add( BOOST_TEST_CASE( &checksum_test ), 5 /* expected zero error */ , 0); - return test; -} - diff --git a/tests/zypp/Digest_test.cc b/tests/zypp/Digest_test.cc index 8e7ef63..b385c7f 100644 --- a/tests/zypp/Digest_test.cc +++ b/tests/zypp/Digest_test.cc @@ -5,22 +5,15 @@ #include #include -// Boost.Test -#include #include -using boost::unit_test::test_suite; -using boost::unit_test::test_case; -using boost::test_tools::close_at_tolerance; - -// parameterized test -// http://www.boost.org/libs/test/example/unit_test_example4.cpp - #include "zypp/base/Logger.h" #include "zypp/base/Exception.h" #include "zypp/PathInfo.h" #include "zypp/Digest.h" +using boost::unit_test::test_case; + using namespace std; using namespace zypp; using namespace zypp::filesystem; @@ -29,7 +22,7 @@ using namespace zypp::filesystem; * Test case for * static std::string digest(const std::string& name, std::istream& is, size_t bufsize = 4096); */ -void digest_test() +BOOST_AUTO_TEST_CASE(digest) { string data("I will test the checksum of this"); stringstream str1(data); @@ -41,12 +34,3 @@ void digest_test() // FIXME i think it should throw BOOST_CHECK_EQUAL( Digest::digest( "lalala", str3) , "" ); } - -test_suite* -init_unit_test_suite( int, char* [] ) -{ - test_suite* test= BOOST_TEST_SUITE( "DigestTest" ); - test->add( BOOST_TEST_CASE( &digest_test ), 0 /* expected zero error */ ); - return test; -} - diff --git a/tests/zypp/Edition_test.cc b/tests/zypp/Edition_test.cc index e6b6fc4..72e1bd7 100644 --- a/tests/zypp/Edition_test.cc +++ b/tests/zypp/Edition_test.cc @@ -8,13 +8,12 @@ #include -using boost::unit_test::test_suite; using boost::unit_test::test_case; using namespace std; using namespace zypp; -void edition_test() +BOOST_AUTO_TEST_CASE(edition) { Edition _ed1 ("1"); Edition _ed2 ("1.1"); @@ -36,11 +35,3 @@ void edition_test() BOOST_CHECK_EQUAL( Edition::compare("2:1-1","2:1-1"), 0 ); BOOST_CHECK_EQUAL( Edition::compare("3:1-1","2:1-1"), 1 ); } - -test_suite* -init_unit_test_suite( int, char* [] ) -{ - test_suite* test= BOOST_TEST_SUITE( "EditionTest" ); - test->add( BOOST_TEST_CASE( &edition_test ), 0 /* expected zero error */ ); - return test; -} diff --git a/tests/zypp/Fetcher_test.cc b/tests/zypp/Fetcher_test.cc index 8b0600f..c016eae 100644 --- a/tests/zypp/Fetcher_test.cc +++ b/tests/zypp/Fetcher_test.cc @@ -15,30 +15,12 @@ using namespace zypp; using namespace zypp::media; using namespace boost::unit_test; -void fetcher_simple_test() -{ - string dir(TESTS_SRC_DIR); - dir += "/zypp/data/Fetcher/remote-site"; - MediaSetAccess media( "dir:" + dir, "/" ); - Fetcher fetcher; -} +#define DATADIR (Pathname(TESTS_SRC_DIR) + "/zypp/data/Fetcher/remote-site") -test_suite* -init_unit_test_suite( int argc, char *argv[] ) +BOOST_AUTO_TEST_CASE(fetcher) { -// if (argc < 2) -// { -// cout << "mediasetaccesstest:" -// " path to directory with test data required as parameter" << endl; -// return (test_suite *)0; -// } - - test_suite* test= BOOST_TEST_SUITE("Fetcher_test"); - - // simple test - test->add(BOOST_TEST_CASE(&fetcher_simple_test)); - - return test; + MediaSetAccess media( ("dir:" + DATADIR).asUrl(), "/" ); + Fetcher fetcher; } // vim: set ts=2 sts=2 sw=2 ai et: diff --git a/tests/zypp/FileChecker_test.cc b/tests/zypp/FileChecker_test.cc index 078583d..b56fc0f 100644 --- a/tests/zypp/FileChecker_test.cc +++ b/tests/zypp/FileChecker_test.cc @@ -13,25 +13,24 @@ #include "zypp/FileChecker.h" #include -#include -#include #include "KeyRingTestReceiver.h" using boost::unit_test::test_suite; using boost::unit_test::test_case; -using namespace boost::unit_test::log; using namespace std; using namespace zypp; using namespace zypp::filesystem; -void keyring_test( const string &dir ) +#define DATADIR (Pathname(TESTS_SRC_DIR) + "/zypp/data/FileChecker") + +BOOST_AUTO_TEST_CASE(keyring_test) { - Pathname file( Pathname(dir) + "hello.txt" ); - Pathname file2( Pathname(dir) + "hello2.txt" ); - Pathname pubkey( Pathname(dir) + "hello.txt.key" ); - Pathname signature( Pathname(dir) + "hello.txt.asc" ); + Pathname file( Pathname(DATADIR) + "hello.txt" ); + Pathname file2( Pathname(DATADIR) + "hello2.txt" ); + Pathname pubkey( Pathname(DATADIR) + "hello.txt.key" ); + Pathname signature( Pathname(DATADIR) + "hello.txt.asc" ); /** * 1st scenario, the signature does @@ -65,12 +64,12 @@ void keyring_test( const string &dir ) } -void checksum_test( const string &dir ) +BOOST_AUTO_TEST_CASE(checksum_test) { - Pathname file( Pathname(dir) + "hello.txt" ); - Pathname file2( Pathname(dir) + "hello2.txt" ); - Pathname pubkey( Pathname(dir) + "hello.txt.key" ); - Pathname signature( Pathname(dir) + "hello.txt.asc" ); + Pathname file( Pathname(DATADIR) + "hello.txt" ); + Pathname file2( Pathname(DATADIR) + "hello2.txt" ); + Pathname pubkey( Pathname(DATADIR) + "hello.txt.key" ); + Pathname signature( Pathname(DATADIR) + "hello.txt.asc" ); /** * 1st scenario, checksum matches @@ -89,30 +88,3 @@ void checksum_test( const string &dir ) } } -test_suite* -init_unit_test_suite( int argc, char* argv[] ) -{ - string datadir; - if (argc < 2) - { - datadir = TESTS_SRC_DIR; - datadir = (Pathname(datadir) + "/zypp/data/FileChecker").asString(); - cout << "filechecker_test:" - " path to directory with test data required as parameter. Using " << datadir << endl; - //return (test_suite *)0; - } - else - { - datadir = argv[1]; - } - - std::string const params[] = { datadir }; - //set_log_stream( std::cout ); - test_suite* test= BOOST_TEST_SUITE( "FileCheckerTest" ); - test->add(BOOST_PARAM_TEST_CASE( &keyring_test, - (std::string const*)params, params+1)); - test->add(BOOST_PARAM_TEST_CASE( &checksum_test, - (std::string const*)params, params+1)); - return test; -} - diff --git a/tests/zypp/KeyRing_test.cc b/tests/zypp/KeyRing_test.cc index 08e8a83..9500def 100644 --- a/tests/zypp/KeyRing_test.cc +++ b/tests/zypp/KeyRing_test.cc @@ -11,8 +11,6 @@ #include "zypp/TmpPath.h" #include -#include -#include #include "KeyRingTestReceiver.h" @@ -24,11 +22,11 @@ using namespace std; using namespace zypp; using namespace zypp::filesystem; -void keyring_test( const string &dir ) +#define DATADIR (Pathname(TESTS_SRC_DIR) + "/zypp/data/KeyRing") + +BOOST_AUTO_TEST_CASE(keyring_test) { - PublicKey key( Pathname(dir) + "public.asc" ); - - + PublicKey key( Pathname(DATADIR) + "public.asc" ); /** * scenario #1 @@ -55,7 +53,7 @@ void keyring_test( const string &dir ) BOOST_CHECK_MESSAGE( ! keyring.isKeyTrusted( key.id() ), "Imported untrusted key should be untrusted"); keyring_callbacks.answerTrustKey(true); - bool to_continue = keyring.verifyFileSignatureWorkflow( Pathname(dir) + "repomd.xml", "Blah Blah", Pathname(dir) + "repomd.xml.asc"); + bool to_continue = keyring.verifyFileSignatureWorkflow( DATADIR + "repomd.xml", "Blah Blah", DATADIR + "repomd.xml.asc"); BOOST_CHECK_MESSAGE( ! keyring_callbacks.askedAcceptUnknownKey(), "Should not ask for unknown key, it was known"); BOOST_CHECK_MESSAGE( keyring_callbacks.askedTrustKey(), "Verify Signature Workflow with only 1 untrusted key should ask user wether to trust"); @@ -88,7 +86,7 @@ void keyring_test( const string &dir ) keyring_callbacks.answerTrustKey(true); // now we will recheck with a corrupted file - bool to_continue = keyring.verifyFileSignatureWorkflow( Pathname(dir) + "repomd.xml.corrupted", "Blah Blah", Pathname(dir) + "repomd.xml.asc"); + bool to_continue = keyring.verifyFileSignatureWorkflow( DATADIR + "repomd.xml.corrupted", "Blah Blah", DATADIR + "repomd.xml.asc"); // check wether the user got the right questions BOOST_CHECK_MESSAGE( ! keyring_callbacks.askedAcceptUnknownKey(), "Should not ask for unknown key, it was known"); @@ -118,7 +116,7 @@ void keyring_test( const string &dir ) keyring_callbacks.answerTrustKey(true); // now we will recheck with a unsigned file - bool to_continue = keyring.verifyFileSignatureWorkflow( Pathname(dir) + "repomd.xml", "Blah Blah", Pathname() ); + bool to_continue = keyring.verifyFileSignatureWorkflow( DATADIR + "repomd.xml", "Blah Blah", Pathname() ); // check wether the user got the right questions BOOST_CHECK_MESSAGE( ! keyring_callbacks.askedAcceptUnknownKey(), "Should not ask for unknown key, it was known"); @@ -145,7 +143,7 @@ void keyring_test( const string &dir ) BOOST_CHECK_MESSAGE( ! keyring.isKeyKnown( key.id() ), "empty keyring has not known keys"); //keyring_callbacks.answerAcceptUnknownKey(true); - bool to_continue = keyring.verifyFileSignatureWorkflow( Pathname(dir) + "repomd.xml", "Blah Blah", Pathname(dir) + "repomd.xml.asc"); + bool to_continue = keyring.verifyFileSignatureWorkflow( DATADIR + "repomd.xml", "Blah Blah", DATADIR + "repomd.xml.asc"); BOOST_CHECK_MESSAGE(keyring_callbacks.askedAcceptUnknownKey(), "Should ask to accept unknown key, empty keyring"); BOOST_CHECK_MESSAGE( ! keyring_callbacks.askedTrustKey(), "Unknown key cant be trusted"); BOOST_CHECK_MESSAGE( ! keyring_callbacks.askedImportKey(), "Unknown key cant be imported"); @@ -178,7 +176,7 @@ void keyring_test( const string &dir ) BOOST_CHECK_MESSAGE( keyring.isKeyKnown( key.id() ), "Imported trusted key should be known"); BOOST_CHECK_MESSAGE( keyring.isKeyTrusted( key.id() ), "Imported trusted key should be trusted"); - bool to_continue = keyring.verifyFileSignatureWorkflow( Pathname(dir) + "repomd.xml", "Blah Blah", Pathname(dir) + "repomd.xml.asc"); + bool to_continue = keyring.verifyFileSignatureWorkflow( DATADIR + "repomd.xml", "Blah Blah", DATADIR + "repomd.xml.asc"); BOOST_CHECK_MESSAGE( ! keyring_callbacks.askedAcceptUnknownKey(), "Should not ask for unknown key, it was known"); BOOST_CHECK_MESSAGE( ! keyring_callbacks.askedTrustKey(), "Verify Signature Workflow with only 1 untrusted key should ask user wether to trust"); @@ -196,9 +194,9 @@ void keyring_test( const string &dir ) } -void keyring_signature_test( const string &dir ) +BOOST_AUTO_TEST_CASE(signature_test) { - PublicKey key( Pathname(dir) + "public.asc" ); + PublicKey key( DATADIR + "public.asc" ); { KeyRingTestReceiver keyring_callbacks; @@ -207,42 +205,16 @@ void keyring_signature_test( const string &dir ) TmpDir tmp_dir; KeyRing keyring( tmp_dir.path() ); - BOOST_CHECK_EQUAL( keyring.readSignatureKeyId( Pathname(dir) + "repomd.xml.asc" ), "BD61D89BD98821BE" ); + BOOST_CHECK_EQUAL( keyring.readSignatureKeyId( DATADIR + "repomd.xml.asc" ), "BD61D89BD98821BE" ); BOOST_CHECK_THROW( keyring.readSignatureKeyId(Pathname()), Exception ); TmpFile tmp; BOOST_CHECK_EQUAL( keyring.readSignatureKeyId(tmp.path()), "" ); keyring.importKey(key); - BOOST_CHECK(keyring.verifyFileSignature( Pathname(dir) + "repomd.xml", Pathname(dir) + "repomd.xml.asc")); - BOOST_CHECK( ! keyring.verifyFileSignature( Pathname(dir) + "repomd.xml.corrupted", Pathname(dir) + "repomd.xml.asc")); + BOOST_CHECK(keyring.verifyFileSignature( DATADIR + "repomd.xml", DATADIR + "repomd.xml.asc")); + BOOST_CHECK( ! keyring.verifyFileSignature( DATADIR + "repomd.xml.corrupted", DATADIR + "repomd.xml.asc")); } } -test_suite* -init_unit_test_suite( int argc, char* argv[] ) -{ - string datadir; - if (argc < 2) - { - datadir = TESTS_SRC_DIR; - datadir = (Pathname(datadir) + "/zypp/data/KeyRing").asString(); - cout << "keyring_test:" - " path to directory with test data required as parameter. Using " << datadir << endl; - //return (test_suite *)0; - } - else - { - datadir = argv[1]; - } - - std::string const params[] = { datadir }; - //set_log_stream( std::cout ); - test_suite* test= BOOST_TEST_SUITE( "PublicKeyTest" ); - test->add(BOOST_PARAM_TEST_CASE( &keyring_test, - (std::string const*)params, params+1)); - test->add(BOOST_PARAM_TEST_CASE( &keyring_signature_test, - (std::string const*)params, params+1)); - return test; -} diff --git a/tests/zypp/PathInfo_test.cc b/tests/zypp/PathInfo_test.cc index 13e627e..79eaa0d 100644 --- a/tests/zypp/PathInfo_test.cc +++ b/tests/zypp/PathInfo_test.cc @@ -4,22 +4,16 @@ #include #include -// Boost.Test -#include #include -using boost::unit_test::test_suite; -using boost::unit_test::test_case; -using boost::test_tools::close_at_tolerance; - -// parameterized test -// http://www.boost.org/libs/test/example/unit_test_example4.cpp - #include "zypp/base/Logger.h" #include "zypp/base/Exception.h" #include "zypp/PathInfo.h" #include "zypp/TmpPath.h" +using boost::unit_test::test_suite; +using boost::unit_test::test_case; + using namespace std; using namespace zypp; using namespace zypp::filesystem; @@ -29,7 +23,7 @@ using namespace zypp::filesystem; * bool is_checksum( const Pathname & file, const CheckSum &checksum ); * std::string checksum( const Pathname & file, const std::string &algorithm ); */ -void pathinfo_checksum_test() +BOOST_AUTO_TEST_CASE(pathinfo_checksum_test) { const char *buffer = "I will test the checksum of this"; TmpFile file; @@ -52,7 +46,7 @@ void pathinfo_checksum_test() BOOST_REQUIRE( is_checksum( file.path(), file_md5 ) ); } -void pathinfo_is_exist_test() +BOOST_AUTO_TEST_CASE(pathinfo_is_exist_test) { TmpDir dir; Pathname subdir("text with spaces"); @@ -68,7 +62,7 @@ void pathinfo_is_exist_test() BOOST_CHECK( PathInfo(filepath).isExist() ); } -void pathinfo_misc_test() +BOOST_AUTO_TEST_CASE(pathipathinfo_misc_test) { TmpDir dir; @@ -76,7 +70,7 @@ void pathinfo_misc_test() BOOST_CHECK(info.isDir()); } -void pathinfo_expandlink_test() +BOOST_AUTO_TEST_CASE(pathinfo_expandlink_test) { TmpDir dir; @@ -124,14 +118,4 @@ void pathinfo_expandlink_test() cout << brokenlink << " -> " << filesystem::expandlink(brokenlink) << endl; } -test_suite* -init_unit_test_suite( int, char* [] ) -{ - test_suite* test= BOOST_TEST_SUITE( "PathInfoTest" ); - test->add( BOOST_TEST_CASE( &pathinfo_checksum_test ), 0 /* expected zero error */ ); - test->add( BOOST_TEST_CASE( &pathinfo_misc_test ), 0 /* expected zero error */ ); - test->add( BOOST_TEST_CASE( &pathinfo_is_exist_test ), 0 /* expected zero error */ ); - test->add( BOOST_TEST_CASE( &pathinfo_expandlink_test ), 0 /* expected zero error */ ); - return test; -} diff --git a/tests/zypp/PoolQuery_test.cc b/tests/zypp/PoolQuery_test.cc index bbff216..a999d25 100644 --- a/tests/zypp/PoolQuery_test.cc +++ b/tests/zypp/PoolQuery_test.cc @@ -1,12 +1,12 @@ #include #include #include -#include -#include #include "zypp/ZYppFactory.h" #include "zypp/PoolQuery.h" +#define BOOST_TEST_MODULE PoolQuery + using std::cout; using std::endl; using std::string; @@ -19,7 +19,7 @@ bool result_cb( const ResObject::Ptr &r ) return true; } -void poolquery_simple_test() +BOOST_AUTO_TEST_CASE(pool_query ) { Pathname dir(TESTS_SRC_DIR); dir += "/zypp/data/PoolQuery"; @@ -40,15 +40,15 @@ void poolquery_simple_test() cout << "search done." << endl; } -bool init_function() { - framework::master_test_suite().add( BOOST_TEST_CASE( boost::bind( &poolquery_simple_test) ) ); - return true; -} - -int -main( int argc, char* argv[] ) -{ -return ::boost::unit_test::unit_test_main( &init_function, argc, argv ); -} +// bool init_function() { +// framework::master_test_suite().add( BOOST_TEST_CASE( boost::bind( &poolquery_simple_test) ) ); +// return true; +// } +// +// int +// main( int argc, char* argv[] ) +// { +// return ::boost::unit_test::unit_test_main( &init_function, argc, argv ); +// } // vim: set ts=2 sts=2 sw=2 ai et: diff --git a/tests/zypp/ProgressData_test.cc b/tests/zypp/ProgressData_test.cc index 70713a4..2d3900f 100644 --- a/tests/zypp/ProgressData_test.cc +++ b/tests/zypp/ProgressData_test.cc @@ -8,19 +8,15 @@ #include "zypp/base/Exception.h" #include -#include -#include #include "zypp/ProgressData.h" -using boost::unit_test::test_suite; using boost::unit_test::test_case; -using namespace boost::unit_test::log; using namespace std; using namespace zypp; -void progressdata_test() +BOOST_AUTO_TEST_CASE(progressdata_test) { { ProgressData progress(100); @@ -60,12 +56,5 @@ void progressdata_test() } } - -test_suite* -init_unit_test_suite( int argc, char* argv[] ) -{ - test_suite* test= BOOST_TEST_SUITE( "ProgressData_test" ); - test->add( BOOST_TEST_CASE( &progressdata_test ), 0 /* expected zero error */ ); - return test; -} + diff --git a/tests/zypp/PtrTypes.cc b/tests/zypp/PtrTypes_test.cc similarity index 97% rename from tests/zypp/PtrTypes.cc rename to tests/zypp/PtrTypes_test.cc index a986b88..556ad58 100644 --- a/tests/zypp/PtrTypes.cc +++ b/tests/zypp/PtrTypes_test.cc @@ -1,14 +1,19 @@ #include +#include + #include "zypp/base/Logger.h" #include #include #include +#define BOOST_TEST_MODULE PtrTypes + using std::endl; using namespace zypp; using namespace zypp::base; + #define TRACE_TAG DBG << this->numericId() << " " << __PRETTY_FUNCTION__ << endl /** Logs Ctor, CopyCtor, Assign and Dtor. */ @@ -116,7 +121,7 @@ template ** FUNCTION NAME : main ** FUNCTION TYPE : int */ -int main( int argc, char * argv[] ) +BOOST_AUTO_TEST_CASE(basic_test) { MIL << "===[START]=====" << endl; test > >(); @@ -130,5 +135,4 @@ int main( int argc, char * argv[] ) cowt > >(); MIL << "===[DONE]=====" << endl; - return 0; } diff --git a/tests/zypp/PublicKey_test.cc b/tests/zypp/PublicKey_test.cc index ac0b6b2..181b382 100644 --- a/tests/zypp/PublicKey_test.cc +++ b/tests/zypp/PublicKey_test.cc @@ -235,7 +235,7 @@ char susekey[]= size_t _susekey_size=2173; size_t *susekey_size=&_susekey_size; -void publickey_test() +BOOST_AUTO_TEST_CASE(publickey_test) { BOOST_CHECK_THROW( zypp::PublicKey("nonexistant"), Exception ); @@ -261,11 +261,3 @@ void publickey_test() BOOST_REQUIRE( ! empty_key.isValid() ); } -test_suite* -init_unit_test_suite( int argc, char* argv[] ) -{ - test_suite* test= BOOST_TEST_SUITE( "PublicKeyTest" ); - test->add( BOOST_TEST_CASE( &publickey_test ), 0 /* expected zero error */ ); - return test; -} - diff --git a/tests/zypp/RWPtr.cc b/tests/zypp/RWPtr_test.cc similarity index 92% rename from tests/zypp/RWPtr.cc rename to tests/zypp/RWPtr_test.cc index 6e1ddc6..ec11010 100644 --- a/tests/zypp/RWPtr.cc +++ b/tests/zypp/RWPtr_test.cc @@ -1,7 +1,11 @@ +#include + #include #include #include +#define BOOST_TEST_MODULE RWPtr_test + struct Foo { int _foo; @@ -46,11 +50,9 @@ do { \ std::cerr << std::endl; \ } while(0); -int main(int argc, char *argv[]) +BOOST_AUTO_TEST_CASE(basic_test) { - (void)argv; - - bool skip_reset = argc > 1; + bool skip_reset = false; int result = 0; typedef zypp::RW_pointer FooRef; @@ -77,6 +79,5 @@ int main(int argc, char *argv[]) std::cerr << "RESULT: " << (result == 0 ? "PASSED" : "FAILED") << std::endl; - return result; } diff --git a/tests/zypp/RepoInfo_test.cc b/tests/zypp/RepoInfo_test.cc index d95ccaf..97ee150 100644 --- a/tests/zypp/RepoInfo_test.cc +++ b/tests/zypp/RepoInfo_test.cc @@ -24,33 +24,9 @@ using namespace zypp; using namespace zypp::filesystem; using namespace zypp::repo; -void repoinfo_test( const string &dir ) +BOOST_AUTO_TEST_CASE(repoinfo_test) { } -test_suite* -init_unit_test_suite( int argc, char* argv[] ) -{ - string datadir; - if (argc < 2) - { - datadir = TESTS_SRC_DIR; - datadir = (Pathname(datadir) + "/zypp/data/RepoInfo").asString(); - cout << "repoinfo_test:" - " path to directory with test data required as parameter. Using " << datadir << endl; - //return (test_suite *)0; - } - else - { - datadir = argv[1]; - } - - std::string const params[] = { datadir }; - //set_log_stream( std::cout ); - test_suite* test= BOOST_TEST_SUITE( "RepoInfoTest" ); - test->add(BOOST_PARAM_TEST_CASE( &repoinfo_test, - (std::string const*)params, params+1)); - return test; -} diff --git a/tests/zypp/RepoManager_test.cc b/tests/zypp/RepoManager_test.cc index 50f42d3..50e96a8 100644 --- a/tests/zypp/RepoManager_test.cc +++ b/tests/zypp/RepoManager_test.cc @@ -14,21 +14,21 @@ #include "zypp/RepoManager.h" #include -#include -#include + #include "KeyRingTestReceiver.h" using boost::unit_test::test_suite; using boost::unit_test::test_case; -using namespace boost::unit_test::log; using namespace std; using namespace zypp; using namespace zypp::filesystem; using namespace zypp::repo; -void repomanager_test( const string &dir ) +#define DATADIR (Pathname(TESTS_SRC_DIR) + "/zypp/data/RepoManager") + +BOOST_AUTO_TEST_CASE(repomanager_test) { RepoManagerOptions opts; @@ -36,7 +36,7 @@ void repomanager_test( const string &dir ) TmpDir tmpRawCachePath; TmpDir tmpKnownReposPath; - BOOST_CHECK_EQUAL( filesystem::copy_dir_content( Pathname(dir) + "/repos.d", tmpKnownReposPath.path() ), 0 ); + BOOST_CHECK_EQUAL( filesystem::copy_dir_content( DATADIR + "/repos.d", tmpKnownReposPath.path() ), 0 ); opts.repoCachePath = tmpCachePath.path(); opts.repoRawCachePath = tmpRawCachePath.path(); @@ -49,7 +49,7 @@ void repomanager_test( const string &dir ) // now add a .repo file with 2 repositories in it Url url; - url.setPathName((Pathname(dir) + "/proprietary.repo").asString()); + url.setPathName((DATADIR + "/proprietary.repo").asString()); url.setScheme("file"); manager.addRepositories(url); @@ -149,28 +149,3 @@ void repomanager_test( const string &dir ) manager.buildCache(repo); } -test_suite* -init_unit_test_suite( int argc, char* argv[] ) -{ - string datadir; - if (argc < 2) - { - datadir = TESTS_SRC_DIR; - datadir = (Pathname(datadir) + "/zypp/data/RepoManager").asString(); - cout << "repomanager_test:" - " path to directory with test data required as parameter. Using " << datadir << endl; - //return (test_suite *)0; - } - else - { - datadir = argv[1]; - } - - std::string const params[] = { datadir }; - //set_log_stream( std::cout ); - test_suite* test= BOOST_TEST_SUITE( "RepoManagerTest" ); - test->add(BOOST_PARAM_TEST_CASE( &repomanager_test, - (std::string const*)params, params+1)); - return test; -} - diff --git a/tests/zypp/RepoStatus_test.cc b/tests/zypp/RepoStatus_test.cc index e7138a7..62302f6 100644 --- a/tests/zypp/RepoStatus_test.cc +++ b/tests/zypp/RepoStatus_test.cc @@ -6,28 +6,16 @@ #include "zypp/PathInfo.h" #include -#include -#include using boost::unit_test::test_suite; using boost::unit_test::test_case; -using namespace boost::unit_test::log; using namespace std; using namespace zypp; using namespace zypp::filesystem; -void repostatus_test() +BOOST_AUTO_TEST_CASE(repostatus_test) { TmpDir tmpPath; RepoStatus status; } - -test_suite* -init_unit_test_suite( int argc, char* argv[] ) -{ - test_suite* test= BOOST_TEST_SUITE( "RepoStatus" ); - test->add( BOOST_TEST_CASE( &repostatus_test ), 0 /* expected zero error */ ); - return test; -} - diff --git a/tests/zypp/ResKind_test.cc b/tests/zypp/ResKind_test.cc index 446cb34..9e8cbbf 100644 --- a/tests/zypp/ResKind_test.cc +++ b/tests/zypp/ResKind_test.cc @@ -2,12 +2,11 @@ #include "zypp/base/Logger.h" #include "zypp/ResKind.h" -using boost::unit_test::test_suite; using boost::unit_test::test_case; using namespace std; using namespace zypp; -void dotest() +BOOST_AUTO_TEST_CASE(reskind_test) { // Default construced is empty "" BOOST_CHECK_EQUAL( ResKind(), "" ); @@ -32,9 +31,3 @@ void dotest() BOOST_CHECK_EQUAL( ResKind::compare( "FOO", "foo" ), 0 ); } -test_suite * init_unit_test_suite( int, char * [] ) -{ - test_suite * test= BOOST_TEST_SUITE( "ResKind_test" ); - test->add( BOOST_TEST_CASE( &dotest ), 0 /* expected zero error */ ); - return test; -} diff --git a/tests/zypp/TranslatedText_test.cc b/tests/zypp/TranslatedText_test.cc index 0c8c846..981983b 100644 --- a/tests/zypp/TranslatedText_test.cc +++ b/tests/zypp/TranslatedText_test.cc @@ -1,8 +1,3 @@ -// Arch.cc -// -// tests for Arch -// - #include #include #include @@ -12,18 +7,15 @@ #include "zypp/ZYppFactory.h" #include "zypp/ZYpp.h" -// Boost.Test -#include #include using boost::unit_test::test_suite; using boost::unit_test::test_case; -using boost::test_tools::close_at_tolerance; using namespace std; using namespace zypp; -void test_tt() +BOOST_AUTO_TEST_CASE(translatedtext_test) { ZYpp::Ptr god; @@ -57,10 +49,3 @@ void test_tt() BOOST_CHECK_EQUAL( testTT.text(), "default" ); } -test_suite* -init_unit_test_suite( int, char* [] ) -{ - test_suite* test= BOOST_TEST_SUITE( "TranslatedText" ); - test->add( BOOST_TEST_CASE( &test_tt ), 0 /* expected zero error */ ); - return test; -} diff --git a/tests/zypp/Url_test.cc b/tests/zypp/Url_test.cc index 0e5535d..d0f0e24 100644 --- a/tests/zypp/Url_test.cc +++ b/tests/zypp/Url_test.cc @@ -12,16 +12,12 @@ #include // Boost.Test -#include #include -using boost::unit_test::test_suite; using boost::unit_test::test_case; -using boost::test_tools::close_at_tolerance; - using namespace zypp; -void test_url1(void) +BOOST_AUTO_TEST_CASE(test_url1) { std::string str, one, two; zypp::Url url; @@ -127,7 +123,7 @@ void test_url1(void) BOOST_CHECK( zypp::Url(str).isValid()); } -void test_url2(void) +BOOST_AUTO_TEST_CASE(test_url2) { zypp::Url url("http://user:pass@localhost:/path/to;version=1.1?arg=val#frag"); @@ -146,7 +142,7 @@ void test_url2(void) "http://user:pass@localhost/path/to;version=1.1?arg=val#frag"); } -void test_url3() +BOOST_AUTO_TEST_CASE(test_url3) { zypp::Url url("http://localhost/path/to#frag"); std::string key; @@ -187,7 +183,7 @@ void test_url3() } } -void test_url4() +BOOST_AUTO_TEST_CASE( test_url4) { try { @@ -239,16 +235,5 @@ void test_url4() } } -test_suite* -init_unit_test_suite( int, char* [] ) -{ - test_suite* test= BOOST_TEST_SUITE( "Url" ); - test->add( BOOST_TEST_CASE( &test_url1 ), 0 /* expected zero error */ ); - test->add( BOOST_TEST_CASE( &test_url2 ), 0 ); - test->add( BOOST_TEST_CASE( &test_url3 ), 0 ); - test->add( BOOST_TEST_CASE( &test_url4 ), 0 ); - return test; -} - // vim: set ts=2 sts=2 sw=2 ai et: diff --git a/tests/zypp/Vendor1_test.cc b/tests/zypp/Vendor1_test.cc deleted file mode 100644 index 888c74e..0000000 --- a/tests/zypp/Vendor1_test.cc +++ /dev/null @@ -1,49 +0,0 @@ - -#include -#include -#include - -// Boost.Test -#include -#include - -using boost::unit_test::test_suite; -using boost::unit_test::test_case; -using boost::test_tools::close_at_tolerance; - -// parameterized test -// http://www.boost.org/libs/test/example/unit_test_example4.cpp - -#include "zypp/base/LogControl.h" -#include "zypp/base/Logger.h" -#include "zypp/base/Exception.h" -#include "zypp/ZYpp.h" -#include "zypp/VendorAttr.h" - -using namespace std; -using namespace zypp; - - -// most frequently you implement test cases as a free functions -void vendor_test() -{ - // No vendor definition files has been readed. So only suse,opensuse vendors are - // equivalent - BOOST_REQUIRE( VendorAttr::instance().equivalent("suse", "suse") ); - BOOST_REQUIRE( VendorAttr::instance().equivalent("equal", "equal") ); - BOOST_REQUIRE( VendorAttr::instance().equivalent("suse", "SuSE") ); - BOOST_REQUIRE( VendorAttr::instance().equivalent("opensuse", "SuSE") ); - BOOST_REQUIRE( !VendorAttr::instance().equivalent("open", "SuSE") ); - BOOST_REQUIRE( !VendorAttr::instance().equivalent("nothing", "SuSE") ); -} - -test_suite* -init_unit_test_suite( int, char* [] ) -{ - setenv("ZYPP_CONF", "./../../tests/zypp/data/Vendor/zypp1.conf", 1 ); - zypp::base::LogControl::instance().logfile( "-" ); - test_suite* test= BOOST_TEST_SUITE( "VendorTest" ); - test->add( BOOST_TEST_CASE( &vendor_test ), 5 /* expected zero error */ , 0); - return test; -} - diff --git a/tests/zypp/Vendor2_test.cc b/tests/zypp/Vendor_test.cc similarity index 62% rename from tests/zypp/Vendor2_test.cc rename to tests/zypp/Vendor_test.cc index 17a0680..0d64fd3 100644 --- a/tests/zypp/Vendor2_test.cc +++ b/tests/zypp/Vendor_test.cc @@ -4,29 +4,36 @@ #include // Boost.Test -#include #include -using boost::unit_test::test_suite; -using boost::unit_test::test_case; -using boost::test_tools::close_at_tolerance; - -// parameterized test -// http://www.boost.org/libs/test/example/unit_test_example4.cpp - #include "zypp/base/LogControl.h" #include "zypp/base/Logger.h" #include "zypp/base/Exception.h" #include "zypp/ZYpp.h" #include "zypp/VendorAttr.h" +using boost::unit_test::test_case; using namespace std; using namespace zypp; +#define DATADIR (Pathname(TESTS_SRC_DIR) + "/zypp/data/Vendor") + +BOOST_AUTO_TEST_CASE(vendor_test1) +{ + setenv("ZYPP_CONF", (DATADIR + "zypp1.conf").c_str(), 1 ); + // No vendor definition files has been readed. So only suse,opensuse vendors are + // equivalent + BOOST_REQUIRE( VendorAttr::instance().equivalent("suse", "suse") ); + BOOST_REQUIRE( VendorAttr::instance().equivalent("equal", "equal") ); + BOOST_REQUIRE( VendorAttr::instance().equivalent("suse", "SuSE") ); + BOOST_REQUIRE( VendorAttr::instance().equivalent("opensuse", "SuSE") ); + BOOST_REQUIRE( !VendorAttr::instance().equivalent("open", "SuSE") ); + BOOST_REQUIRE( !VendorAttr::instance().equivalent("nothing", "SuSE") ); +} -// most frequently you implement test cases as a free functions -void vendor_test() +BOOST_AUTO_TEST_CASE(vendor_test2) { + setenv("ZYPP_CONF", (DATADIR + "zypp2.conf").c_str(), 1 ); // No vendor definition files has been readed. So only suse,opensuse vendors are // equivalent BOOST_REQUIRE( VendorAttr::instance().equivalent("suse", "suse") ); @@ -43,13 +50,3 @@ void vendor_test() BOOST_REQUIRE( VendorAttr::instance().equivalent("ati_new", "ati") ); } -test_suite* -init_unit_test_suite( int, char* [] ) -{ - setenv("ZYPP_CONF", "./../../tests/zypp/data/Vendor/zypp2.conf", 1 ); - zypp::base::LogControl::instance().logfile( "-" ); - test_suite* test= BOOST_TEST_SUITE( "VendorTest" ); - test->add( BOOST_TEST_CASE( &vendor_test ), 5 /* expected zero error */ , 0); - return test; -} - diff --git a/tests/zypp/base/CMakeLists.txt b/tests/zypp/base/CMakeLists.txt index 4bc6fb1..22863f6 100644 --- a/tests/zypp/base/CMakeLists.txt +++ b/tests/zypp/base/CMakeLists.txt @@ -1,7 +1,2 @@ -ADD_DEFINITIONS( -DBOOST_TEST_DYN_LINK ) -FOREACH( loop_var Sysconfig ) - ADD_EXECUTABLE( ${loop_var}_test ${loop_var}_test.cc ) - TARGET_LINK_LIBRARIES( ${loop_var}_test zypp boost_unit_test_framework ) - ADD_TEST( ${loop_var}_test ${CMAKE_CURRENT_BINARY_DIR}/${loop_var}_test) -ENDFOREACH( loop_var ) +ADD_TESTS(Sysconfig) \ No newline at end of file diff --git a/tests/zypp/base/Sysconfig_test.cc b/tests/zypp/base/Sysconfig_test.cc index 741c2a4..9468523 100644 --- a/tests/zypp/base/Sysconfig_test.cc +++ b/tests/zypp/base/Sysconfig_test.cc @@ -4,29 +4,28 @@ #include #include +#include + #include "zypp/base/Logger.h" #include "zypp/base/Exception.h" #include "zypp/TmpPath.h" #include "zypp/PathInfo.h" - -#include -#include -#include - #include "zypp/base/Sysconfig.h" using boost::unit_test::test_suite; using boost::unit_test::test_case; +using namespace boost::unit_test; using namespace boost::unit_test::log; using namespace std; using namespace zypp; +#define DATADIR (Pathname(TESTS_SRC_DIR) + "/zypp/base/data/Sysconfig") -void sysconfig_test( const string &dir ) +BOOST_AUTO_TEST_CASE(Sysconfig) { - Pathname file = Pathname(dir) + "proxy"; + Pathname file = DATADIR + "proxy"; map values = zypp::base::sysconfig::read(file); BOOST_CHECK_EQUAL( values.size(), 6 ); BOOST_CHECK_EQUAL( values["PROXY_ENABLED"], "no"); @@ -34,39 +33,3 @@ void sysconfig_test( const string &dir ) BOOST_CHECK_EQUAL( values["NO_PROXY"], "localhost, 127.0.0.1"); } -bool -init_unit_test_suite( int argc, char* argv[] ) -{ - string datadir; - if (argc < 2) - { - datadir = TESTS_SRC_DIR; - datadir = (Pathname(datadir) + "/zypp/base/data/Sysconfig").asString(); - cout << "sysconfig_test:" - " path to directory with test data required as parameter. Using " << datadir << endl; - //return (test_suite *)0; - } - else - { - datadir = argv[1]; - } - - std::string const params[] = { datadir }; - //set_log_stream( std::cout ); - test_suite* test= BOOST_TEST_SUITE( "SysconfigTest" ); - test->add(BOOST_PARAM_TEST_CASE( &sysconfig_test, - (std::string const*)params, params+1)); - return test; -} - -//bool init_function() { -// framework::master_test_suite().add( BOOST_TEST_CASE( boost::bind( &poolquery_simple_test) ) ); -// return true; -//} - -int -main( int argc, char* argv[] ) -{ - return ::boost::unit_test::unit_test_main( &init_unit_test_suite, argc, argv ); -} - -- 2.7.4