Base64.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. };
  39. }