@@ -36,15 +36,16 @@ namespace CodexTest
36
36
//
37
37
TEST_CASE (" CodexTest_EncodeTrueUtf8_SingleSurrogates" , " [CodexTest]" )
38
38
{
39
- const charcount_t charCount = 1 ;
40
- utf8char_t encodedBuffer[(charCount + 1 ) * 3 ]; // +1 since the buffer will be null-terminated
39
+ const size_t charCount = 1 ;
40
+ constexpr size_t cbEncodedBuffer = charCount * 3 + 1 ; // +1 since the buffer will be null-terminated
41
+ utf8char_t encodedBuffer[cbEncodedBuffer];
41
42
42
43
char16 testValues[] = { 0xD800 , 0xDB7F , 0xDB80 , 0xDBFF , 0xDC00 , 0xDF80 , 0xDFFF };
43
44
const int numTestCases = _countof (testValues);
44
45
45
46
for (int i = 0 ; i < numTestCases; i++)
46
47
{
47
- size_t numEncodedBytes = utf8::EncodeTrueUtf8IntoAndNullTerminate (encodedBuffer, &testValues[i], charCount);
48
+ size_t numEncodedBytes = utf8::EncodeIntoAndNullTerminate<utf8::Utf8EncodingKind::TrueUtf8> (encodedBuffer, cbEncodedBuffer , &testValues[i], charCount);
48
49
CHECK (numEncodedBytes == 3 );
49
50
CheckIsUnicodeReplacementChar (encodedBuffer);
50
51
}
@@ -62,11 +63,12 @@ namespace CodexTest
62
63
const int numTestCases = _countof (testCases);
63
64
const charcount_t charCount = _countof (testCases[0 ].surrogatePair );
64
65
const charcount_t maxEncodedByteCount = _countof (testCases[0 ].utf8Encoding );
65
- utf8char_t encodedBuffer[maxEncodedByteCount + 1 ]; // +1 in case a null-terminating func is passed in
66
+ const size_t encodedBufferSize = maxEncodedByteCount + 1 ; // +1 in case a null-terminating func is passed in
67
+ utf8char_t encodedBuffer[encodedBufferSize];
66
68
67
69
for (int i = 0 ; i < numTestCases; i++)
68
70
{
69
- size_t numEncodedBytes = func (encodedBuffer, testCases[i].surrogatePair , charCount);
71
+ size_t numEncodedBytes = func (encodedBuffer, encodedBufferSize, testCases[i].surrogatePair , charCount);
70
72
CHECK (numEncodedBytes <= maxEncodedByteCount);
71
73
for (size_t j = 0 ; j < numEncodedBytes; j++)
72
74
{
@@ -106,7 +108,7 @@ namespace CodexTest
106
108
{ { 0xDBFF , 0xDFFF }, { 0xED , 0xAF , 0xBF , 0xED , 0xBF , 0xBF } } // U+10FFFF
107
109
};
108
110
109
- RunUtf8EncodingTestCase (testCases, static_cast <size_t (*)(utf8char_t *, const char16*, charcount_t )>(utf8::EncodeInto));
111
+ RunUtf8EncodingTestCase (testCases, static_cast <size_t (*)(utf8char_t *, size_t , const char16*, charcount_t )>(utf8::EncodeInto<utf8::Utf8EncodingKind::Cesu8> ));
110
112
}
111
113
112
114
TEST_CASE (" CodexTest_EncodeUtf8_PairedSurrogates" , " [CodexTest]" )
@@ -132,7 +134,7 @@ namespace CodexTest
132
134
{ { 0xDBFF , 0xDFFF }, { 0xF4 , 0x8F , 0xBF , 0xBF } } // U+10FFFF
133
135
};
134
136
135
- RunUtf8EncodingTestCase (testCases, utf8::EncodeTrueUtf8IntoAndNullTerminate );
137
+ RunUtf8EncodingTestCase (testCases, utf8::EncodeIntoAndNullTerminate<utf8::Utf8EncodingKind::TrueUtf8> );
136
138
}
137
139
138
140
TEST_CASE (" CodexTest_EncodeUtf8_NonCharacters" , " [CodexTest]" )
@@ -151,7 +153,7 @@ namespace CodexTest
151
153
{ { 0xFFFF }, { 0xEF , 0xBF , 0xBF } } // U+FFFF
152
154
};
153
155
154
- RunUtf8EncodingTestCase (testCases, utf8::EncodeTrueUtf8IntoAndNullTerminate );
156
+ RunUtf8EncodingTestCase (testCases, utf8::EncodeIntoAndNullTerminate<utf8::Utf8EncodingKind::TrueUtf8> );
155
157
}
156
158
157
159
TEST_CASE (" CodexTest_EncodeUtf8_BoundaryChars" , " [CodexTest]" )
@@ -180,8 +182,8 @@ namespace CodexTest
180
182
{ { 0xDBFF , 0xDFFF }, { 0xF4 , 0x8F , 0xBF , 0xBF } } // U+10FFFF
181
183
};
182
184
183
- RunUtf8EncodingTestCase (testCases, utf8::EncodeTrueUtf8IntoAndNullTerminate );
184
- RunUtf8EncodingTestCase (testCases2, utf8::EncodeTrueUtf8IntoAndNullTerminate );
185
+ RunUtf8EncodingTestCase (testCases, utf8::EncodeIntoAndNullTerminate<utf8::Utf8EncodingKind::TrueUtf8> );
186
+ RunUtf8EncodingTestCase (testCases2, utf8::EncodeIntoAndNullTerminate<utf8::Utf8EncodingKind::TrueUtf8> );
185
187
}
186
188
187
189
TEST_CASE (" CodexTest_EncodeUtf8_SimpleCharacters" , " [CodexTest]" )
@@ -201,15 +203,16 @@ namespace CodexTest
201
203
{ { 0x20AC }, { 0xE2 , 0x82 , 0xAC } } // U+20AC - Euro symbol
202
204
};
203
205
204
- RunUtf8EncodingTestCase (testCases, utf8::EncodeTrueUtf8IntoAndNullTerminate );
206
+ RunUtf8EncodingTestCase (testCases, utf8::EncodeIntoAndNullTerminate<utf8::Utf8EncodingKind::TrueUtf8> );
205
207
}
206
208
207
209
TEST_CASE (" CodexTest_EncodeTrueUtf8_SimpleString" , " [CodexTest]" )
208
210
{
209
211
const charcount_t charCount = 3 ;
210
- utf8char_t encodedBuffer[(charCount + 1 ) * 3 ]; // +1 since the buffer will be null terminated
212
+ constexpr size_t cbEncodedBuffer = charCount * 3 + 1 ; // +1 since the buffer will be null terminated
213
+ utf8char_t encodedBuffer[cbEncodedBuffer];
211
214
const char16* sourceBuffer = L" abc" ;
212
- size_t numEncodedBytes = utf8::EncodeTrueUtf8IntoAndNullTerminate (encodedBuffer, sourceBuffer, charCount);
215
+ size_t numEncodedBytes = utf8::EncodeIntoAndNullTerminate<utf8::Utf8EncodingKind::TrueUtf8> (encodedBuffer, cbEncodedBuffer , sourceBuffer, charCount);
213
216
CHECK (numEncodedBytes == charCount);
214
217
for (int i = 0 ; i < charCount; i++)
215
218
{
0 commit comments