8
8
#include "greatest/greatest.h"
9
9
#include "aligned/aligned.h"
10
10
#include "latin1_to_utf8.h"
11
+ #include "utf8_to_utf32.h"
11
12
12
13
TEST test_latin1_to_utf8 (void ) {
13
14
const char * data_str = (char * )"Tony! Toni! Ton\xe9!" ;
@@ -52,25 +53,47 @@ TEST test_latin1_to_utf8(void) {
52
53
PASS ();
53
54
}
54
55
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é!";
56
+ TEST test_utf8_to_utf32 (void ) {
57
+ const char * data_str = (char * )"Tony! Toni! Toné!" ;
68
58
size_t len = strlen ((const char * )data_str );
69
59
char * data = aligned_malloc (len , 32 );
70
60
memcpy (data , data_str , len );
71
- size_t utf8_output_len = len + 1;
72
- char *utf8_output = aligned_malloc(utf8_output_len, 32);
73
- }*/
61
+ size_t utf32_output_len = len ;
62
+ uint32_t * utf32_output = aligned_malloc (utf32_output_len * sizeof (uint32_t ), 32 );
63
+
64
+ utf_result_t converted = convert_utf8_to_utf32 (data , len , utf32_output , utf32_output_len );
65
+ ASSERT_EQ (converted .return_code , SIMDUTF_SUCCESS );
66
+ ASSERT_EQ (converted .read_len , len );
67
+ ASSERT_EQ (converted .written_len , 17 );
68
+ ASSERT_EQ (utf32_output [converted .written_len - 2 ], 233 );
69
+
70
+ const unsigned char * data_long_str = (unsigned char * )"we on a world tour نحن في جولة حول العالم nous sommes en tournée mondiale мы в мировом турне a wa lori irin-ajo agbaye 私たちは世界ツアー中です είμαστε σε παγκόσμια περιοδεία በአለም ጉብኝት ላይ ነን jesteśmy w trasie dookoła świata 우리는 세계 여행을 하고 있어요 យើងកំពុងធ្វើដំណើរជុំវិញពិភពលោក ನಾವು ವಿಶ್ವ ಪ್ರವಾಸದಲ್ಲಿದ್ದೇವೆ. մենք համաշխարհային շրջագայության մեջ ենք míele xexeame katã ƒe tsaɖiɖi aɖe dzi เรากำลังทัวร์รอบโลก हम विश्व भ्रमण पर हैं pachantinpi puriypin kashanchis אנחנו בסיבוב הופעות עולמי kaulâh bâdâ è tur dhunnya qegħdin fuq tour tad-dinja ང་ཚོ་འཛམ་གླིང་སྐོར་བསྐྱོད་བྱེད་བཞིན་ཡོད།" ;
71
+ size_t len_long = strlen ((const char * )data_long_str );
72
+ char * data_long = aligned_malloc (len_long , 32 );
73
+ memcpy (data_long , data_long_str , len_long );
74
+ size_t utf32_output_len_long = len_long ;
75
+ uint32_t * utf32_output_long = aligned_malloc (utf32_output_len_long * sizeof (uint32_t ), 32 );
76
+ utf_result_t converted_long = convert_utf8_to_utf32 (data_long , len_long , utf32_output_long , utf32_output_len_long );
77
+ ASSERT_EQ (converted_long .return_code , SIMDUTF_SUCCESS );
78
+ ASSERT_EQ (converted_long .read_len , len_long );
79
+ ASSERT_EQ (converted_long .written_len , 563 );
80
+ ASSERT_EQ (utf32_output_long [converted_long .written_len - 1 ], 3853 );
81
+
82
+ memset (utf32_output , 0 , utf32_output_len * sizeof (uint32_t ));
83
+
84
+ converted_long = convert_valid_utf8_to_utf32 (data_long , len_long , utf32_output_long , utf32_output_len_long );
85
+ ASSERT_EQ (converted_long .return_code , SIMDUTF_SUCCESS );
86
+ ASSERT_EQ (converted_long .read_len , len_long );
87
+ ASSERT_EQ (converted_long .written_len , 563 );
88
+ ASSERT_EQ (utf32_output_long [converted_long .written_len - 1 ], 3853 );
89
+
90
+ aligned_free (data );
91
+ aligned_free (utf32_output );
92
+ aligned_free (data_long );
93
+ aligned_free (utf32_output_long );
94
+
95
+ PASS ();
96
+ }
74
97
75
98
76
99
/* Add definitions that need to be in the test runner's main file. */
@@ -80,6 +103,7 @@ int main(int argc, char **argv) {
80
103
GREATEST_MAIN_BEGIN (); /* command-line options, initialization. */
81
104
82
105
RUN_TEST (test_latin1_to_utf8 );
106
+ RUN_TEST (test_utf8_to_utf32 );
83
107
84
108
GREATEST_MAIN_END (); /* display results */
85
109
}
0 commit comments