Base64.cpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include "pch.h"
  2. #include "CppUnitTest.h"
  3. #include <Base64.h>
  4. #include <Text.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 = Framework::base64Encode(data, Framework::textLength(data));
  17. Assert::AreEqual(encoded, encodedData.getText());
  18. }
  19. TEST_METHOD(TestDecoding)
  20. {
  21. const char* data = "SGVsbG8gV29ybGQh";
  22. const char* decoded = "Hello World!";
  23. char* decodedData = 0;
  24. int decodecLength;
  25. Framework::base64Decode(data, &decodedData, &decodecLength);
  26. Assert::AreEqual(decoded, decodedData);
  27. delete[] decodedData;
  28. }
  29. TEST_METHOD(TestDecodingInvalid)
  30. {
  31. const char* data = "SGVsbG8.gVd29ybGQh";
  32. char* decodedData = 0;
  33. int decodecLength;
  34. Framework::base64Decode(data, &decodedData, &decodecLength);
  35. Assert::AreEqual(0, decodecLength);
  36. delete[] decodedData;
  37. }
  38. TEST_METHOD(TestDecodeAndEncode)
  39. {
  40. const char* data = "g0OLN0EJepEiT8eiNdvb9PfJkIqSpiLqb3uvRwyg2Y7iZsQkbkC1kI99M8NaELhT2Erca/D+VmB6B6aFpoAViuXZrlQaZeSo4RhtPScmjwFwbGtha8DA5Mdna2/ngPjOWqgkdA4JHe8hiS1Ir7tIICmygZR0Qnk8qeSrkWWlYL5OhDRcjFBMrNl584o1Pape7izxZG1soBdRTKi28Ap2QI2pmxr55sbTYbtelfcK8+c15UyiUuy4ozliWitr0Gr3egYAE3Ts2UlOlafjjbDXdeS+wYcRrkGz56IPEw/efQgAAAAAWYMbzXDzF76JvaIYb3uNVDpQ20v9Hf3mvw75zet31Ub57x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2yxU/morwyKARgojgBkGAGwZFvH73Y6FdJGMgjqVF0pyQp1yrMg2zUp812z78HJpC4dcB2bpjNl8Gly1r3IBIrSek2FnyDCwRgkeQviPqwQAAAAAkAQAAAAAGAgAAAAAC33xl1dusLMkYA==";
  41. char* decodedData = 0;
  42. int decodecLength;
  43. Framework::base64Decode(data, &decodedData, &decodecLength);
  44. Framework::Text encoded = Framework::base64Encode(decodedData, decodecLength);
  45. Assert::IsTrue(encoded.istGleich(data));
  46. delete[] decodedData;
  47. }
  48. };
  49. }