@@ -17,24 +17,30 @@ TEST test_latin1_to_utf8(void) {
17
17
size_t utf8_output_len = len + 1 ;
18
18
char * utf8_output = aligned_malloc (utf8_output_len , 32 );
19
19
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 );
22
24
ASSERT (strncmp (utf8_output , "Tony! Toni! Toné!" , utf8_output_len ) == 0 );
23
25
24
26
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 );
26
28
char * data_long = aligned_malloc (len_long , 32 );
27
29
memcpy (data_long , data_str_long , len_long );
28
30
29
- size_t utf8_output_len_long = len_long + 1 ;
31
+ size_t utf8_output_len_long = len_long + 4 ;
30
32
char * utf8_output_long = aligned_malloc (utf8_output_len_long , 32 );
31
33
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 );
34
38
ASSERT (strncmp (utf8_output_long , "Tony! Toni! Toné! Tony! Toni! Toné! Tony! Toni! Toné! Tony! Toni! Toné!" , utf8_output_len_long ) == 0 );
35
39
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 );
38
44
ASSERT (strncmp (utf8_output , "Tony! Toni! Toné!" , utf8_output_len ) == 0 );
39
45
40
46
aligned_free (data_long );
@@ -46,6 +52,26 @@ TEST test_latin1_to_utf8(void) {
46
52
PASS ();
47
53
}
48
54
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
+
49
75
50
76
/* Add definitions that need to be in the test runner's main file. */
51
77
GREATEST_MAIN_DEFS ();
0 commit comments