Skip to content

Commit 1487fd6

Browse files
committed
[test] adding new API to tests
1 parent be4a09a commit 1487fd6

File tree

1 file changed

+34
-8
lines changed

1 file changed

+34
-8
lines changed

test.c

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,30 @@ TEST test_latin1_to_utf8(void) {
1717
size_t utf8_output_len = len + 1;
1818
char *utf8_output = aligned_malloc(utf8_output_len, 32);
1919

20-
size_t converted = convert_latin1_to_utf8(data, len, utf8_output, utf8_output_len);
21-
ASSERT_EQ(converted, len);
20+
utf_result_t converted = convert_latin1_to_utf8(data, len, utf8_output, utf8_output_len);
21+
ASSERT_EQ(converted.return_code, SIMDUTF_SUCCESS);
22+
ASSERT_EQ(converted.read_len, len);
23+
ASSERT_EQ(converted.written_len, utf8_output_len);
2224
ASSERT(strncmp(utf8_output, "Tony! Toni! Toné!", utf8_output_len) == 0);
2325

2426
const char *data_str_long = (char *)"Tony! Toni! Ton\xe9! Tony! Toni! Ton\xe9! Tony! Toni! Ton\xe9! Tony! Toni! Ton\xe9!";
25-
size_t len_long = strlen((const char *)data_str_long);
27+
size_t len_long = strlen(data_str_long);
2628
char *data_long = aligned_malloc(len_long, 32);
2729
memcpy(data_long, data_str_long, len_long);
2830

29-
size_t utf8_output_len_long = len_long + 1;
31+
size_t utf8_output_len_long = len_long + 4;
3032
char *utf8_output_long = aligned_malloc(utf8_output_len_long, 32);
3133

32-
size_t converted_long = convert_latin1_to_utf8(data_long, len_long, utf8_output_long, utf8_output_len_long);
33-
ASSERT_EQ(converted_long, len_long);
34+
utf_result_t converted_long = convert_latin1_to_utf8(data_long, len_long, utf8_output_long, utf8_output_len_long);
35+
ASSERT_EQ(converted_long.return_code, SIMDUTF_SUCCESS);
36+
ASSERT_EQ(converted_long.read_len, len_long);
37+
ASSERT_EQ(converted_long.written_len, utf8_output_len_long);
3438
ASSERT(strncmp(utf8_output_long, "Tony! Toni! Toné! Tony! Toni! Toné! Tony! Toni! Toné! Tony! Toni! Toné!", utf8_output_len_long) == 0);
3539

36-
size_t converted_too_short = convert_latin1_to_utf8(data_long, len_long, utf8_output, utf8_output_len);
37-
ASSERT_EQ(converted_too_short, len);
40+
utf_result_t converted_too_short = convert_latin1_to_utf8(data_long, len_long, utf8_output, utf8_output_len);
41+
ASSERT_EQ(converted_too_short.return_code, SIMDUTF_SUCCESS);
42+
ASSERT_EQ(converted_too_short.read_len, len);
43+
ASSERT_EQ(converted_too_short.written_len, utf8_output_len);
3844
ASSERT(strncmp(utf8_output, "Tony! Toni! Toné!", utf8_output_len) == 0);
3945

4046
aligned_free(data_long);
@@ -46,6 +52,26 @@ TEST test_latin1_to_utf8(void) {
4652
PASS();
4753
}
4854

55+
/*
56+
int strlen16(const char16_t* strarg)
57+
{
58+
if(!strarg)
59+
return -1; //strarg is NULL pointer
60+
char16_t* str = strarg;
61+
for(;*str;++str)
62+
; // empty body
63+
return str-strarg;
64+
}
65+
66+
TEST test_utf16be_to_utf8(void) {
67+
const char16_t *data_str = u"Tony! Toni! Toné!";
68+
size_t len = strlen((const char *)data_str);
69+
char *data = aligned_malloc(len, 32);
70+
memcpy(data, data_str, len);
71+
size_t utf8_output_len = len + 1;
72+
char *utf8_output = aligned_malloc(utf8_output_len, 32);
73+
}*/
74+
4975

5076
/* Add definitions that need to be in the test runner's main file. */
5177
GREATEST_MAIN_DEFS();

0 commit comments

Comments
 (0)