You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

78 lines
2.7 KiB

  1. #define BOOST_TEST_DYN_LINK
  2. #define BOOST_TEST_NO_MAIN
  3. #ifdef HAVE_CONFIG_H
  4. #include "config.h"
  5. #endif
  6. #include <boost/test/unit_test.hpp>
  7. #include <boost/assign/std/map.hpp>
  8. #include "base64.hh"
  9. using namespace boost;
  10. BOOST_AUTO_TEST_SUITE(test_base64_cc)
  11. BOOST_AUTO_TEST_CASE(test_Base64_Roundtrip) {
  12. std::string before("Some Random String"), after;
  13. std::string encoded = Base64Encode(before);
  14. B64Decode(encoded, after);
  15. BOOST_CHECK_EQUAL(before, after);
  16. }
  17. /* for a in $(seq 1 32);
  18. do
  19. plain=$(pwgen -1 -s $a)
  20. echo \(\"$plain\",\"$(echo -n $plain | openssl enc -base64)\"\) ;
  21. done
  22. */
  23. BOOST_AUTO_TEST_CASE(test_Base64_Encode) {
  24. typedef std::map<std::string, std::string> cases_t;
  25. cases_t cases;
  26. assign::insert(cases)
  27. ("", "")
  28. ("z","eg==")
  29. ("x4","eDQ=")
  30. ("J07","SjA3")
  31. ("kl8F","a2w4Rg==")
  32. ("2NUx9","Mk5VeDk=")
  33. ("hwXQ8C","aHdYUThD")
  34. ("V7ZHmlG","VjdaSG1sRw==")
  35. ("FuNFLSd5","RnVORkxTZDU=")
  36. ("YVGwy3Vbi","WVZHd3kzVmJp")
  37. ("6ueW4V3oLG","NnVlVzRWM29MRw==")
  38. ("d5zR7AWIBIQ","ZDV6UjdBV0lCSVE=")
  39. ("WJjZ6xgpRMCD","V0pqWjZ4Z3BSTUNE")
  40. ("e8I52L0vC9Kfq","ZThJNTJMMHZDOUtmcQ==")
  41. ("ufxMi8EZgTDja8","dWZ4TWk4RVpnVERqYTg=")
  42. ("MiNPxzxUkNXCFg1","TWlOUHh6eFVrTlhDRmcx")
  43. ("abqIPosEky85gFVM","YWJxSVBvc0VreTg1Z0ZWTQ==")
  44. ("Qccuox8igoyRKEeTo","UWNjdW94OGlnb3lSS0VlVG8=")
  45. ("wbaw6g6WWo4iiYXosV","d2JhdzZnNldXbzRpaVlYb3NW")
  46. ("ZIfJZIA3Kd0a6iIr0vc","WklmSlpJQTNLZDBhNmlJcjB2Yw==")
  47. ("SUhE1RK7xrRfvYOiaPMQ","U1VoRTFSSzd4clJmdllPaWFQTVE=")
  48. ("ZAWsEeB4bcTUzTr828VTd","WkFXc0VlQjRiY1RVelRyODI4VlRk")
  49. ("xc9rpu0F5ztR7r3jElr2BS","eGM5cnB1MEY1enRSN3IzakVscjJCUw==")
  50. ("xvEWPkZjqVjIZwsL5WhijES","eHZFV1BrWmpxVmpJWndzTDVXaGlqRVM=")
  51. ("yy4yAmcBKCNF3hWriWbDnKmF","eXk0eUFtY0JLQ05GM2hXcmlXYkRuS21G")
  52. ("9wKEMpl8OlFvnD10wwhoK7BjY","OXdLRU1wbDhPbEZ2bkQxMHd3aG9LN0JqWQ==")
  53. ("SB6yLm39pDVIUiQ5g73BvyRzBs","U0I2eUxtMzlwRFZJVWlRNWc3M0J2eVJ6QnM=")
  54. ("Acu4kk1puF98lIzd1b9bt8ha7Er","QWN1NGtrMXB1Rjk4bEl6ZDFiOWJ0OGhhN0Vy")
  55. ("P4X6efItE6cn03ksLTvniqMQlel3","UDRYNmVmSXRFNmNuMDNrc0xUdm5pcU1RbGVsMw==")
  56. ("RnQSvhIOz3ywuHCoSotJGKjBdCVbx","Um5RU3ZoSU96M3l3dUhDb1NvdEpHS2pCZENWYng=")
  57. ("ykybXtN0lelsLSzyzd4DTP3sYp8YGu","eWt5Ylh0TjBsZWxzTFN6eXpkNERUUDNzWXA4WUd1")
  58. ("eSHBt7Xx5F7A4HFtabXEzDLD01bnSiG","ZVNIQnQ3WHg1RjdBNEhGdGFiWEV6RExEMDFiblNpRw==")
  59. ("dq4KydZjmcoQQ45VYBP2EDR8FqKaMul0","ZHE0S3lkWmptY29RUTQ1VllCUDJFRFI4RnFLYU11bDA=");
  60. for(const cases_t::value_type& val : cases) {
  61. std::string encoded = Base64Encode(val.first), decoded;
  62. BOOST_CHECK_EQUAL(encoded, val.second);
  63. decoded.clear();
  64. B64Decode(val.second, decoded);
  65. BOOST_CHECK_EQUAL(decoded, val.first);
  66. }
  67. }
  68. BOOST_AUTO_TEST_SUITE_END()