#include <iostream>
+#include "zypp/base/Exception.h"
#include "zypp/Dependencies.h"
#include "zypp/Capability.h"
#include "zypp/ResObject.h"
{
namespace utils
{
+ void assert_equal( const std::string &got, const std::string &expected)
+ {
+ if (got != expected)
+ {
+ ZYPP_THROW(Exception("Expected '" + expected + "', got '" + got + "'"));
+ }
+ }
+
static void dumpCapSet( const CapSet &caps, const std::string &deptype)
{
cout << " " << "<" << deptype << ">" << std::endl;
{
namespace utils
{
+ void assert_equal( const std::string &got, const std::string &expected);
void dump( const ResStore &store, bool descr = false, bool deps = false );
void dump( const std::list<ResObject::Ptr> &list, bool descr = false, bool deps = false );
}
+++ /dev/null
-## Process this file with automake to produce Makefile.in
-## ##################################################
-
-SUBDIRS =
-
-INCLUDES = -DZYPP_BASE_LOGGER_LOGGROUP=\"testsuite_utils\"
-
-## ##################################################
-
-##targetincludedir = $(pkgincludedir)/target
-
-noinst_HEADERS = \
- TestUtils.h
-
-## ##################################################
-
-noinst_LTLIBRARIES = lib@PACKAGE@_testsuite_utils.la
-
-## ##################################################
-
-lib@PACKAGE@_testsuite_utils_la_SOURCES = \
- TestUtils.cc
-
-lib@PACKAGE@_testsuite_utils_la_LDFLAGS = @LIBZYPP_VERSION_INFO@
-
-##lib@PACKAGE@_target_la_LIBADD = \
-## rpm/lib@PACKAGE@_target_rpm.la \
-## hal/lib@PACKAGE@_target_hal.la \
-## modalias/lib@PACKAGE@_target_modalias.la \
-## store/lib@PACKAGE@_target_store.la
-
-## ##################################################
+++ /dev/null
-
-#include <iostream>
-#include "zypp/Dependencies.h"
-#include "zypp/Capability.h"
-#include "zypp/ResObject.h"
-#include "zypp/Patch.h"
-#include "zypp/ResStore.h"
-#include "testsuite/utils/TestUtils.h"
-
-using namespace std;
-
-namespace zypp
-{
- namespace testsuite
- {
- namespace utils
- {
- static void dumpCapSet( const CapSet &caps, const std::string &deptype)
- {
- cout << " " << "<" << deptype << ">" << std::endl;
- CapSet::iterator it = caps.begin();
- for ( ; it != caps.end(); ++it)
- {
- cout << " <capability kind=\"" << (*it).kind() << "\" refers=\"" << (*it).refers() << "\">" << (*it).asString() << "</capability>" << std::endl;
- }
- cout << " " << "</" << deptype << ">" << std::endl;
- }
-
- static void dumpDeps( const Dependencies &deps )
- {
- dumpCapSet( deps[Dep::PROVIDES], "provides" );
- dumpCapSet( deps[Dep::PREREQUIRES], "prerequires" );
- dumpCapSet( deps[Dep::CONFLICTS], "conflicts" );
- dumpCapSet( deps[Dep::OBSOLETES], "obsoletes" );
- dumpCapSet( deps[Dep::FRESHENS], "freshens" );
- dumpCapSet( deps[Dep::REQUIRES], "requires" );
- dumpCapSet( deps[Dep::RECOMMENDS], "recommends" );
- dumpCapSet( deps[Dep::ENHANCES], "enhances" );
- dumpCapSet( deps[Dep::SUPPLEMENTS], "supplements" );
- dumpCapSet( deps[Dep::SUGGESTS], "suggests" );
- }
-
- static std::string xml_escape( const std::string &s )
- {
- return s;
- }
-
- static void dumpResObject( const ResObject::Ptr r, bool descr, bool deps )
- {
- std::string resolvable_line = "[" + r->kind().asString() + "]" + r->name() + " " + r->edition().asString() + " " + r->arch().asString();
- cout << " <resolvable kind=\"" << r->kind() << "\">" << std::endl;
- cout << " <name>" << r->name() << "</name>" << std::endl;
- cout << " <edition>" << r->edition() << "</edition>" << std::endl;
- cout << " <arch>" << r->arch() << "</arch>" << std::endl;
- if ( descr )
- {
- cout << " <summary>" << r->summary() << "</summary>" << std::endl;
- cout << " <description>" << r->description() << "</description>" << std::endl;
- }
-
- if ( deps )
- {
- cout << " <dependencies>" << std::endl;
- dumpDeps(r->deps());
- cout << " </dependencies>" << std::endl;
- }
- cout << " </resolvable>" << std::endl;
- //std::cout << (**it).deps() << endl;
- }
-
- void dump( const std::list<ResObject::Ptr> &list, bool descr, bool deps )
- {
- std::list<std::string> resolvables;
- cout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
- cout << "<resolvable-list xmlns=\"http://www.novell.com/zypp/testcases/resolvable-list\">" << std::endl;
- for (std::list<ResObject::Ptr>::const_iterator it = list.begin(); it != list.end(); it++)
- {
- dumpResObject(*it, descr, deps);
- }
- cout << "</resolvable-list>" << std::endl;
- }
-
- void dump( const ResStore &store, bool descr, bool deps )
- {
- std::list<std::string> resolvables;
- cout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
- cout << "<resolvable-list xmlns=\"http://www.novell.com/zypp/testcases/resolvable-list\">" << std::endl;
- for (ResStore::const_iterator it = store.begin(); it != store.end(); it++)
- {
- dumpResObject(*it, descr, deps);
- }
- cout << "</resolvable-list>" << std::endl;
- //std::sort( resolvables.begin(), resolvables.end(), CustomSort );
- //for (std::list<std::string>::const_iterator it = resolvables.begin(); it != resolvables.end(); ++it)
- //{
- // cout << *it << std::endl;
- //}
- }
-
-
-
- }
- }
-}
-
+++ /dev/null
-
-#ifndef ZYPP_TESTSUITE_TESTUTILS
-#define ZYPP_TESTSUITE_TESTUTILS
-
-#include "zypp/Dependencies.h"
-#include "zypp/Capability.h"
-#include "zypp/ResStore.h"
-
-namespace zypp
-{
- namespace testsuite
- {
- namespace utils
- {
- void dump( const ResStore &store, bool descr = false, bool deps = false );
- void dump( const std::list<ResObject::Ptr> &list, bool descr = false, bool deps = false );
- }
- }
-}
-
-#endif
-
--- /dev/null
+
+#include <iostream>
+#include <list>
+#include <string>
+
+// Boost.Test
+#include <boost/test/floating_point_comparison.hpp>
+#include <boost/test/unit_test.hpp>
+
+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 namespace std;
+using namespace zypp;
+
+
+// most frequently you implement test cases as a free functions
+void checksum_test()
+{
+ BOOST_CHECK_THROW( CheckSum( "sha1", "dsdsads" ), Exception ); // wrong size
+ BOOST_CHECK_THROW( CheckSum( "sha256", "dsdsads" ), Exception ); // wrong size
+ BOOST_CHECK_THROW( CheckSum( "md5", "dsdsads" ), Exception ); // wrong size
+ BOOST_CHECK_THROW( CheckSum( "md4", "dsdsads" ), Exception ); // wrong size
+ 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 ), 0 /* expected zero error */ );
+ return test;
+}
+
Edition \
Capabilities \
PtrTypes \
- TranslatedText
+ TranslatedText \
+ CheckSum
## ##################################################
-LDADD = $(top_srcdir)/zypp/lib@PACKAGE@.la
+LDADD = $(top_srcdir)/zypp/lib@PACKAGE@.la -lboost_unit_test_framework
## ##################################################
Url5_SOURCES = Url5.cc
Url_SOURCES = Url.cc
TranslatedText_SOURCES = TranslatedText.cc
+PublicKey_SOURCES = PublicKey.cc
+CheckSum_SOURCES = CheckSum.cc
RWPtr_SOURCES = RWPtr.cc
Edition_SOURCES = Edition.cc
Capabilities_SOURCES = Capabilities.cc
#include "zypp/PublicKey.h"
#include "zypp/ZYppFactory.h"
#include "zypp/ZYpp.h"
+#include "testsuite/src/utils/TestUtils.h"
using namespace std;
using namespace zypp;
-
-static void assert_equal( const std::string &got, const std::string &expected)
-{
- if (got != expected)
- {
- ZYPP_THROW(Exception("Expected '" + expected + "', got '" + got + "'"));
- }
-}
+using namespace zypp::testsuite::utils;
int main( int argc, char * argv[] )
{
}
if (
- ( (str::toLower(type) == "md5" ) && (checksum.size() != 32) ) ||
- ( (str::toLower(type) == "sha1" ) && (checksum.size() != 40) ) ||
- ( (str::toLower(type) == "sha256") && (checksum.size() != 64) ) )
+ ( (str::toLower(type) == "md2" ) && (checksum.size() != 32) ) ||
+ ( (str::toLower(type) == "md4" ) && (checksum.size() != 32) ) ||
+ ( (str::toLower(type) == "md5" ) && (checksum.size() != 32) ) ||
+ ( (str::toLower(type) == "sha1" ) && (checksum.size() != 40) ) ||
+ ( (str::toLower(type) == "rmd160" ) && (checksum.size() != 40) ) ||
+ ( (str::toLower(type) == "sha256" ) && (checksum.size() != 64) ) )
{
ZYPP_THROW(Exception("Bad checksum, " + type + " algorithm of size " + str::numstring(checksum.size())));
}
{ return (checksum().empty() || type().empty()); }
/** \relates CheckSum Stream output. */
- inline std::ostream & operator<<( std::ostream & str, const CheckSum & obj )
+ std::ostream & operator<<( std::ostream & str, const CheckSum & obj )
{ return str << (obj.empty() ? std::string("NoCheckSum")
: obj.type()+"-"+obj.checksum() ); }
/** \relates CheckSum */
- inline bool operator==( const CheckSum & lhs, const CheckSum & rhs )
+ bool operator==( const CheckSum & lhs, const CheckSum & rhs )
{ return lhs.checksum() == rhs.checksum() && lhs.type() == rhs.type(); }
/** \relates CheckSum */
- inline bool operator!=( const CheckSum & lhs, const CheckSum & rhs )
+ bool operator!=( const CheckSum & lhs, const CheckSum & rhs )
{ return ! ( lhs == rhs ); }
} // namespace zypp
};
/** \relates CheckSum Stream output. */
- inline std::ostream & operator<<( std::ostream & str, const CheckSum & obj );
+ std::ostream & operator<<( std::ostream & str, const CheckSum & obj );
/** \relates CheckSum */
- inline bool operator==( const CheckSum & lhs, const CheckSum & rhs );
+ bool operator==( const CheckSum & lhs, const CheckSum & rhs );
/** \relates CheckSum */
- inline bool operator!=( const CheckSum & lhs, const CheckSum & rhs );
+ bool operator!=( const CheckSum & lhs, const CheckSum & rhs );
} // namespace zypp
///////////////////////////////////////////////////////////////////