Base64.cpp 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "pch.h"
  2. #include <Base64.h>
  3. #include <Text.h>
  4. #include "CppUnitTest.h"
  5. using namespace Microsoft::VisualStudio::CppUnitTestFramework;
  6. // test class for base64 encoding and decoding
  7. namespace FrameworkTests
  8. {
  9. TEST_CLASS (Base64Tests)
  10. {
  11. public:
  12. TEST_METHOD (TestEncoding)
  13. {
  14. const char* data = "Hello World!";
  15. const char* encoded = "SGVsbG8gV29ybGQh";
  16. Framework::Text encodedData
  17. = Framework::base64Encode(data, Framework::textLength(data));
  18. Assert::AreEqual(encoded, encodedData.getText());
  19. }
  20. TEST_METHOD (TestDecoding)
  21. {
  22. const char* data = "SGVsbG8gV29ybGQh";
  23. const char* decoded = "Hello World!";
  24. char* decodedData = 0;
  25. int decodecLength;
  26. Framework::base64Decode(data, &decodedData, &decodecLength);
  27. Assert::AreEqual(decoded, decodedData);
  28. delete[] decodedData;
  29. }
  30. TEST_METHOD (TestDecodingInvalid)
  31. {
  32. const char* data = "SGVsbG8.gVd29ybGQh";
  33. char* decodedData = 0;
  34. int decodecLength;
  35. Framework::base64Decode(data, &decodedData, &decodecLength);
  36. Assert::AreEqual(0, decodecLength);
  37. delete[] decodedData;
  38. }
  39. TEST_METHOD (TestDecodeAndEncode)
  40. {
  41. const char* data
  42. = "g0OLN0EJepEiT8eiNdvb9PfJkIqSpiLqb3uvRwyg2Y7iZsQkbkC1kI99M8Na"
  43. "ELhT2Erca/"
  44. "D+VmB6B6aFpoAViuXZrlQaZeSo4RhtPScmjwFwbGtha8DA5Mdna2/"
  45. "ngPjOWqgkdA4JHe8hiS1Ir7tIICmygZR0Qnk8qeSrkWWlYL5OhDRcjFBMrNl"
  46. "584o1Pape7izxZG1soBdRTKi28Ap2QI2pmxr55sbTYbtelfcK8+"
  47. "c15UyiUuy4ozliWitr0Gr3egYAE3Ts2UlOlafjjbDXdeS+"
  48. "wYcRrkGz56IPEw/"
  49. "efQgAAAAAWYMbzXDzF76JvaIYb3uNVDpQ20v9Hf3mvw75zet31Ub57xRr4ys"
  50. "qbujMhVhIFKuCY4jMYqTLSWXYRDTFuwoMtfggIt1KS0w0GdGLYOQ44ki/"
  51. "r6lle/LJVDf9GvEIAAAAACaoAgBFyt6PFyzCL/"
  52. "xPj+GGcipGItOqncd18f1zDfB7Mpp9d2VcCAAAAAB7h8qphRo5Z5+"
  53. "rkeXNZZFrLQdeLHpqHvWct3MUHc8cmFjlQ9z+"
  54. "fESeKNSF9TsXYWgev5OYKrCOxmgDAAAAANmF0fUfK9thCADVAQDa3Ex6BgAi"
  55. "/vpcF13DNB1Yy0cJWw5xXef2MN0XWrl3YpVVrRFbzhFWLCez71rQSCcZUYIm"
  56. "wd4PuRDrz2mmSMo8nHlM90lcT3SDAwAAADG1AWXd06wFAAAAAOv8hxK/"
  57. "ZiB6dg1K3rKSqu4wJTwobZh24Rx5R/"
  58. "hN8v058IVLsetqLGJ3dkIqCuwaORJVYH7s1WAJT6cDAAAAAJuaAdSMhiA/"
  59. "c4pq1QIA4Bgs6gYARSQXmYOVhlr1j6mdkkU5kxvEGjoEAAAAAI3DbmPEUHvv"
  60. "O4A1XpbO4S1WPCPk5MB3K/gMRb4lf8KxQzEWCAAAAADFAgCBkPe8ES4cp/"
  61. "v81FI69jgguK9LsbqPcN8PM5JSZKda5TlSokl/"
  62. "vvB8u8XO9b0IAAAAABd2t2Eoc/"
  63. "CYVAHL5VIxjqsXxv25EX54AgD6NcfJLIXRQvuJoiT7k7xQlIg35bnEktCMkI"
  64. "qdDwQAAAAANQMAnwAACjln02TspaXoMEkOLdzJfHFTs1cNeencBgBVAwB6AA"
  65. "Boo4lsQ5OkqWgKlg6vfz73jGrVV+ZHqZqethSIlBoEAAAAAPy8jWn+"
  66. "IQ6piBdBlsW/"
  67. "075NP5SkJtpOv3oGANMEAAAAAJntB5erkwGrtA5VPiWV0+"
  68. "pWqKmj5j5IDRqWzJScoZc3kJ3NPDLN5uXbPSQB0vfrKqCVzYjTF5XtrWOCSg"
  69. "UAAAAAGoGUt0/Q6B64z/"
  70. "j18vnI6uXyjHzAFVHXqj+"
  71. "FDsHPEttRppOgeH29MU23J0Gy7yyZ47gWpc1mfXilAwAAAACFZ9KXQyQ/"
  72. "1sO2VYLnojoQ4uv+EIXjx5uJlQMAAAAAMAQAAAAABw+oCpMR2yxU/"
  73. "morwyKARgojgBkGAGwZFvH73Y6FdJGMgjqVF0pyQp1yrMg2zUp812z78HJpC"
  74. "4dcB2bpjNl8Gly1r3IBIrSek2FnyDCwRgkeQviPqwQAAAAAkAQAAAAAGAgAA"
  75. "AAAC33xl1dusLMkYA==";
  76. char* decodedData = 0;
  77. int decodecLength;
  78. Framework::base64Decode(data, &decodedData, &decodecLength);
  79. Framework::Text encoded
  80. = Framework::base64Encode(decodedData, decodecLength);
  81. Assert::IsTrue(encoded.istGleich(data));
  82. delete[] decodedData;
  83. }
  84. };
  85. } // namespace FrameworkTests