Round tripping utf conversions fails for some surrogate pairs (below test). Starting with 0xD840, 0xDC00 which returns 0xD800, 0xDC00 after the converstions back and forth.
```
#include "stdafx.h"
#include "CppUnitTest.h"
#include <cpprest/json.h>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace UnitTest
{
TEST_CLASS(UtfConversionTest)
{
void IsConvertedCharacterEqualToOriginal(const std::wstring& original)
{
using namespace utility::conversions;
const auto converted = to_utf16string(to_utf8string(original));
Assert::IsTrue(original == converted);
}
public:
TEST_METHOD(UtfConversionExhaustiveTest)
{
// This test is crude -- it covers all potential Unicode code points,
// without regard to semantics, if they are even defined, or anything.
for (wchar_t c = 1; c < 0xd800u; ++c)
{
IsConvertedCharacterEqualToOriginal(std::wstring(1, c));
}
for (wchar_t c = 0xe000u; c < 0xfffeu; ++c)
{
IsConvertedCharacterEqualToOriginal(std::wstring(1, c));
}
// surrogate pairs
for (wchar_t highSurrogate = 0xd800; highSurrogate <= 0xdbff; ++highSurrogate)
{
for (wchar_t lowSurrogate = 0xdc00; lowSurrogate <= 0xdfff; ++lowSurrogate)
{
std::wstring c;
c.push_back(highSurrogate);
c.push_back(lowSurrogate);
IsConvertedCharacterEqualToOriginal(c);
}
}
}
};
}
```
```
#include "stdafx.h"
#include "CppUnitTest.h"
#include <cpprest/json.h>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace UnitTest
{
TEST_CLASS(UtfConversionTest)
{
void IsConvertedCharacterEqualToOriginal(const std::wstring& original)
{
using namespace utility::conversions;
const auto converted = to_utf16string(to_utf8string(original));
Assert::IsTrue(original == converted);
}
public:
TEST_METHOD(UtfConversionExhaustiveTest)
{
// This test is crude -- it covers all potential Unicode code points,
// without regard to semantics, if they are even defined, or anything.
for (wchar_t c = 1; c < 0xd800u; ++c)
{
IsConvertedCharacterEqualToOriginal(std::wstring(1, c));
}
for (wchar_t c = 0xe000u; c < 0xfffeu; ++c)
{
IsConvertedCharacterEqualToOriginal(std::wstring(1, c));
}
// surrogate pairs
for (wchar_t highSurrogate = 0xd800; highSurrogate <= 0xdbff; ++highSurrogate)
{
for (wchar_t lowSurrogate = 0xdc00; lowSurrogate <= 0xdfff; ++lowSurrogate)
{
std::wstring c;
c.push_back(highSurrogate);
c.push_back(lowSurrogate);
IsConvertedCharacterEqualToOriginal(c);
}
}
}
};
}
```