12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- #include "pch.h"
- #include "CppUnitTest.h"
- #include <Base64.h>
- #include <Text.h>
- using namespace Microsoft::VisualStudio::CppUnitTestFramework;
- // test class for base64 encoding and decoding
- namespace FrameworkTests
- {
- TEST_CLASS(Base64Tests)
- {
- public:
- TEST_METHOD(TestEncoding)
- {
- const char* data = "Hello World!";
- const char* encoded = "SGVsbG8gV29ybGQh";
- Framework::Text encodedData = Framework::base64Encode(data, Framework::textLength(data));
- Assert::AreEqual(encoded, encodedData.getText());
- }
-
- TEST_METHOD(TestDecoding)
- {
- const char* data = "SGVsbG8gV29ybGQh";
- const char* decoded = "Hello World!";
- char* decodedData = 0;
- int decodecLength;
- Framework::base64Decode(data, &decodedData, &decodecLength);
- Assert::AreEqual(decoded, decodedData);
- delete[] decodedData;
- }
- TEST_METHOD(TestDecodingInvalid)
- {
- const char* data = "SGVsbG8.gVd29ybGQh";
- char* decodedData = 0;
- int decodecLength;
- Framework::base64Decode(data, &decodedData, &decodecLength);
- Assert::AreEqual(0, decodecLength);
- delete[] decodedData;
- }
- TEST_METHOD(TestDecodeAndEncode)
- {
- const char* data = "g0OLN0EJepEiT8eiNdvb9PfJkIqSpiLqb3uvRwyg2Y7iZsQkbkC1kI99M8NaELhT2Erca/D+VmB6B6aFpoAViuXZrlQaZeSo4RhtPScmjwFwbGtha8DA5Mdna2/ngPjOWqgkdA4JHe8hiS1Ir7tIICmygZR0Qnk8qeSrkWWlYL5OhDRcjFBMrNl584o1Pape7izxZG1soBdRTKi28Ap2QI2pmxr55sbTYbtelfcK8+c15UyiUuy4ozliWitr0Gr3egYAE3Ts2UlOlafjjbDXdeS+wYcRrkGz56IPEw/efQgAAAAAWYMbzXDzF76JvaIYb3uNVDpQ20v9Hf3mvw75zet31Ub57xRr4ysqbujMhVhIFKuCY4jMYqTLSWXYRDTFuwoMtfggIt1KS0w0GdGLYOQ44ki/r6lle/LJVDf9GvEIAAAAACaoAgBFyt6PF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eQviPqwQAAAAAkAQAAAAAGAgAAAAAC33xl1dusLMkYA==";
- char* decodedData = 0;
- int decodecLength;
- Framework::base64Decode(data, &decodedData, &decodecLength);
- Framework::Text encoded = Framework::base64Encode(decodedData, decodecLength);
- Assert::IsTrue(encoded.istGleich(data));
- delete[] decodedData;
- }
- };
- }
|