Skip to content

Commit 0f83efa

Browse files
committed
More tests
1 parent 9a67da6 commit 0f83efa

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
==============================================================================
3+
4+
This file is part of the YUP library.
5+
Copyright (c) 2024 - [email protected]
6+
7+
YUP is an open source library subject to open-source licensing.
8+
9+
The code included in this file is provided under the terms of the ISC license
10+
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
11+
to use, copy, modify, and/or distribute this software for any purpose with or
12+
without fee is hereby granted provided that the above copyright notice and
13+
this permission notice appear in all copies.
14+
15+
YUP IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
16+
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
17+
DISCLAIMED.
18+
19+
==============================================================================
20+
*/
21+
22+
#include <gtest/gtest.h>
23+
24+
#include <yup_core/yup_core.h>
25+
26+
using namespace yup;
27+
28+
TEST (MemoryOutputStreamTests, WriteTextUtf16SupportsFullUnicodeCodepoints)
29+
{
30+
static constexpr yup_wchar stringA[] { 0x1F600, 0x00 }; // Grinning face emoji
31+
static constexpr yup_wchar stringB[] { 0xA, 0xB, 0xC, 0x0 }; // ASCII
32+
static constexpr yup_wchar stringC[] { 0xAAAA, 0xBBBB, 0xCCCC, 0x0 }; // two-byte characters
33+
34+
CharPointer_UTF32 pointers[] { CharPointer_UTF32 (stringA),
35+
CharPointer_UTF32 (stringB),
36+
CharPointer_UTF32 (stringC) };
37+
38+
for (auto originalPtr : pointers)
39+
{
40+
MemoryOutputStream stream;
41+
EXPECT_TRUE (stream.writeText (String (originalPtr), true, false, "\n"));
42+
EXPECT_NE (stream.getDataSize(), (size_t) 0);
43+
44+
CharPointer_UTF16 writtenPtr { reinterpret_cast<const CharPointer_UTF16::CharType*> (stream.getData()) };
45+
46+
for (auto currentOriginal = originalPtr; ! currentOriginal.isEmpty(); ++currentOriginal, ++writtenPtr)
47+
EXPECT_EQ (*currentOriginal, *writtenPtr);
48+
}
49+
}

0 commit comments

Comments
 (0)