diff options
Diffstat (limited to 'sal/qa/rtl/digest/rtl_digest.cxx')
-rw-r--r-- | sal/qa/rtl/digest/rtl_digest.cxx | 120 |
1 files changed, 61 insertions, 59 deletions
diff --git a/sal/qa/rtl/digest/rtl_digest.cxx b/sal/qa/rtl/digest/rtl_digest.cxx index 1a99ff285762..ffd0af4126d2 100644 --- a/sal/qa/rtl/digest/rtl_digest.cxx +++ b/sal/qa/rtl/digest/rtl_digest.cxx @@ -1,3 +1,4 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /************************************************************************* * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -28,13 +29,19 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sal.hxx" -#include <testshl/simpleheader.hxx> + +#include <cppunit/TestAssert.h> +#include <cppunit/TestFixture.h> +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/plugin/TestPlugIn.h> #include <rtl/digest.h> #include <rtl/ustring.hxx> #include <rtl/ustrbuf.hxx> #include <rtl/strbuf.hxx> +#include <string.h> + // sample, how to use digest rtl::OUString CreateMD5FromString( const rtl::OUString& aMsg ) @@ -57,7 +64,7 @@ rtl::OUString CreateMD5FromString( const rtl::OUString& aMsg ) // Create hex-value string from the MD5 value to keep the string size minimal rtl::OUStringBuffer aBuffer( nMD5KeyLen * 2 + 1 ); - for ( sal_uInt32 i = 0; i < nMD5KeyLen; i++ ) + for ( sal_uInt32 i = 0; i < nMD5KeyLen; ++i ) aBuffer.append( (sal_Int32)pMD5KeyBuffer[i], 16 ); delete [] pMD5KeyBuffer; @@ -133,7 +140,7 @@ public: void create_007() { rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmInvalid ); - t_print("Handle is %x\n", handle); + printf("Handle is %p\n", handle); CPPUNIT_ASSERT_MESSAGE("create with NULL", handle == 0); rtl_digest_destroy( handle ); } @@ -436,7 +443,7 @@ public: rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD5 ); sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); - // t_print("nAlgoLength:=%d\n", nAlgoLength); + // printf("nAlgoLength:=%d\n", nAlgoLength); CPPUNIT_ASSERT_MESSAGE("query Length", RTL_DIGEST_LENGTH_MD5 == nAlgoLength); rtl_digest_destroy( handle ); @@ -446,7 +453,7 @@ public: rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmMD2 ); sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); - // t_print("nAlgoLength:=%d\n", nAlgoLength); + // printf("nAlgoLength:=%d\n", nAlgoLength); CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_MD2 == nAlgoLength); rtl_digest_destroy( handle ); @@ -456,7 +463,7 @@ public: rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA ); sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); - // t_print("nAlgoLength:=%d\n", nAlgoLength); + // printf("nAlgoLength:=%d\n", nAlgoLength); CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_SHA == nAlgoLength); rtl_digest_destroy( handle ); @@ -466,7 +473,7 @@ public: rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmSHA1 ); sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); - // t_print("nAlgoLength:=%d\n", nAlgoLength); + // printf("nAlgoLength:=%d\n", nAlgoLength); CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_SHA1 == nAlgoLength); rtl_digest_destroy( handle ); @@ -476,7 +483,7 @@ public: rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_MD5 ); sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); - // t_print("nAlgoLength:=%d\n", nAlgoLength); + // printf("nAlgoLength:=%d\n", nAlgoLength); CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_HMAC_MD5 == nAlgoLength); rtl_digest_destroy( handle ); @@ -486,7 +493,7 @@ public: rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmHMAC_SHA1 ); sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); - // t_print("nAlgoLength:=%d\n", nAlgoLength); + // printf("nAlgoLength:=%d\n", nAlgoLength); CPPUNIT_ASSERT_MESSAGE("query length", RTL_DIGEST_LENGTH_HMAC_SHA1 == nAlgoLength); rtl_digest_destroy( handle ); @@ -497,7 +504,7 @@ public: rtlDigest handle = rtl_digest_create( rtl_Digest_AlgorithmInvalid ); sal_uInt32 nAlgoLength = rtl_digest_queryLength(handle); - // t_print("nAlgoLength:=%d\n", nAlgoLength); + // printf("nAlgoLength:=%d\n", nAlgoLength); CPPUNIT_ASSERT_MESSAGE("query length", 0 == nAlgoLength); rtl_digest_destroy( handle ); @@ -524,13 +531,11 @@ rtl::OString createHex(sal_uInt8 *_pMD5KeyBuffer, sal_uInt32 _nMD5KeyLen) { // Create hex-value string from the MD5 value to keep the string size minimal rtl::OStringBuffer aBuffer( _nMD5KeyLen * 2 + 1 ); - for ( sal_uInt32 i = 0; i < _nMD5KeyLen; i++ ) + for ( sal_uInt32 i = 0; i < _nMD5KeyLen; ++i ) { sal_Int32 nValue = (sal_Int32)_pMD5KeyBuffer[i]; if (nValue < 16) // maximul hex value for 1 byte - { - aBuffer.append( sal_Int32(0), 16 /* radix */ ); - } + aBuffer.append( static_cast<sal_Int32>(0), static_cast<sal_Int16>(16) /* radix */ ); aBuffer.append( nValue, 16 /* radix */ ); } @@ -593,7 +598,7 @@ public: rtl::OString aSum = createHex(pKeyBuffer, nKeyLen); delete [] pKeyBuffer; - t_print("MD2 Sum: %s\n", aSum.getStr()); + printf("MD2 Sum: %s\n", aSum.getStr()); // LLA: how to check right values // samples? @@ -621,7 +626,7 @@ public: rtl::OString aSum = createHex(pKeyBuffer, nKeyLen); delete [] pKeyBuffer; - t_print("MD5 Sum: %s\n", aSum.getStr()); + printf("MD5 Sum: %s\n", aSum.getStr()); // LLA: how to check right values // samples? @@ -649,7 +654,7 @@ public: rtl::OString aSum = createHex(pKeyBuffer, nKeyLen); delete [] pKeyBuffer; - t_print("SHA Sum: %s\n", aSum.getStr()); + printf("SHA Sum: %s\n", aSum.getStr()); // LLA: how to check right values // samples? @@ -676,7 +681,7 @@ public: rtl::OString aSum = createHex(pKeyBuffer, nKeyLen); delete [] pKeyBuffer; - t_print("SHA1 Sum: %s\n", aSum.getStr()); + printf("SHA1 Sum: %s\n", aSum.getStr()); // LLA: how to check right values // samples? @@ -707,7 +712,7 @@ public: rtl::OString aSum = createHex(pKeyBuffer, nKeyLen); delete [] pKeyBuffer; - t_print("HMAC_MD5 Sum: %s\n", aSum.getStr()); + printf("HMAC_MD5 Sum: %s\n", aSum.getStr()); // LLA: how to check right values // samples? @@ -738,7 +743,7 @@ public: rtl::OString aSum = createHex(pKeyBuffer, nKeyLen); delete [] pKeyBuffer; - t_print("HMAC_SHA1 Sum: %s\n", aSum.getStr()); + printf("HMAC_SHA1 Sum: %s\n", aSum.getStr()); // LLA: how to check right values // samples? @@ -865,7 +870,7 @@ public: CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_MD2); - t_print("Decrypt MD2: %s\n", aStr.getStr()); + printf("Decrypt MD2: %s\n", aStr.getStr()); CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_MD2) ); delete [] pBuffer; @@ -908,7 +913,7 @@ public: CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_MD5); - t_print("Decrypt MD5: %s\n", aStr.getStr()); + printf("Decrypt MD5: %s\n", aStr.getStr()); CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_MD5) ); delete [] pBuffer; @@ -953,7 +958,7 @@ public: CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_SHA); - t_print("Decrypt SHA: %s\n", aStr.getStr()); + printf("Decrypt SHA: %s\n", aStr.getStr()); CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_SHA) ); delete [] pBuffer; @@ -998,7 +1003,7 @@ public: CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_SHA1); - t_print("Decrypt SHA1: %s\n", aStr.getStr()); + printf("Decrypt SHA1: %s\n", aStr.getStr()); CPPUNIT_ASSERT_MESSAGE("checksum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_SHA1) ); delete [] pBuffer; @@ -1045,7 +1050,7 @@ public: CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_HMAC_MD5); - t_print("Decrypt HMAC_MD5: %s\n", aStr.getStr()); + printf("Decrypt HMAC_MD5: %s\n", aStr.getStr()); CPPUNIT_ASSERT_MESSAGE("md5sum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_HMAC_MD5) ); delete [] pBuffer; @@ -1092,7 +1097,7 @@ public: CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); rtl::OString aStr = createHex(pBuffer, RTL_DIGEST_LENGTH_HMAC_SHA1); - t_print("Decrypt HMAC_SHA1: %s\n", aStr.getStr()); + printf("Decrypt HMAC_SHA1: %s\n", aStr.getStr()); CPPUNIT_ASSERT_MESSAGE("md5sum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_HMAC_SHA1) ); delete [] pBuffer; @@ -1146,10 +1151,10 @@ public: CPPUNIT_ASSERT(aError == rtl_Digest_E_None ); rtl::OString aKey = createHex(pKeyBuffer, nKeyLen); - t_print("Key: %s\n", aKey.getStr()); + printf("Key: %s\n", aKey.getStr()); // rtl::OString sSalt = createHex(pSaltData, nSaltDataLen); - // t_print("Salt: %s\n", sSalt.getStr()); + // printf("Salt: %s\n", sSalt.getStr()); // CPPUNIT_ASSERT_MESSAGE("md5sum of sample string is wrong. Code changes or sample problems, please check.", aStr.equals(sSampleString_PBKDF2) ); @@ -1415,37 +1420,34 @@ public: }; // class create // ----------------------------------------------------------------------------- -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::create, "rtl_digest"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createMD2, "rtl_digest"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createMD5, "rtl_digest"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createSHA, "rtl_digest"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createSHA1, "rtl_digest"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createHMAC_MD5, "rtl_digest"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::createHMAC_SHA1, "rtl_digest"); - -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::destroy, "rtl_digest"); - -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::queryAlgorithm, "rtl_digest"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::queryLength, "rtl_digest"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::init, "rtl_digest"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::equalTests, "rtl_digest"); - -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_MD2, "rtl_digest"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_MD5, "rtl_digest"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_SHA, "rtl_digest"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_SHA1, "rtl_digest"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_HMAC_MD5, "rtl_digest"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_HMAC_SHA1, "rtl_digest"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::digest_PBKDF2, "rtl_digest"); - -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::update, "rtl_digest"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::get, "rtl_digest"); -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_digest::destroy, "rtl_digest"); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::create); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::createMD2); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::createMD5); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::createSHA); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::createSHA1); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::createHMAC_MD5); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::createHMAC_SHA1); + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::destroy); + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::queryAlgorithm); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::queryLength); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::init); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::equalTests); + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::digest_MD2); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::digest_MD5); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::digest_SHA); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::digest_SHA1); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::digest_HMAC_MD5); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::digest_HMAC_SHA1); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::digest_PBKDF2); + +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::update); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::get); +CPPUNIT_TEST_SUITE_REGISTRATION(rtl_digest::destroy); } // namespace rtl_digest +CPPUNIT_PLUGIN_IMPLEMENT(); -// ----------------------------------------------------------------------------- - -// this macro creates an empty function, which will called by the RegisterAllFunctions() -// to let the user the possibility to also register some functions by hand. -NOADDITIONAL; +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |