unicode_ut.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Unit tests for Unicode functions
  4. *
  5. * Copyright (c) 2018 Heinrich Schuchardt <xypron.glpk@gmx.de>
  6. */
  7. #include <common.h>
  8. #include <charset.h>
  9. #include <command.h>
  10. #include <errno.h>
  11. #include <test/test.h>
  12. #include <test/suites.h>
  13. #include <test/ut.h>
  14. /* Linker list entry for a Unicode test */
  15. #define UNICODE_TEST(_name) UNIT_TEST(_name, 0, unicode_test)
  16. /* Constants c1-c4 and d1-d4 encode the same letters */
  17. /* Six characters translating to one utf-8 byte each. */
  18. static const u16 c1[] = {0x55, 0x2d, 0x42, 0x6f, 0x6f, 0x74, 0x00};
  19. /* One character translating to two utf-8 bytes */
  20. static const u16 c2[] = {0x6b, 0x61, 0x66, 0x62, 0xe1, 0x74, 0x75, 0x72, 0x00};
  21. /* Three characters translating to three utf-8 bytes each */
  22. static const u16 c3[] = {0x6f5c, 0x6c34, 0x8266, 0x00};
  23. /* Three letters translating to four utf-8 bytes each */
  24. static const u16 c4[] = {0xd801, 0xdc8d, 0xd801, 0xdc96, 0xd801, 0xdc87,
  25. 0x0000};
  26. /* Illegal utf-16 strings */
  27. static const u16 i1[] = {0x69, 0x31, 0xdc87, 0x6c, 0x00};
  28. static const u16 i2[] = {0x69, 0x32, 0xd801, 0xd801, 0x6c, 0x00};
  29. static const u16 i3[] = {0x69, 0x33, 0xd801, 0x00};
  30. /* Six characters translating to one utf-16 word each. */
  31. static const char d1[] = {0x55, 0x2d, 0x42, 0x6f, 0x6f, 0x74, 0x00};
  32. /* Eight characters translating to one utf-16 word each */
  33. static const char d2[] = {0x6b, 0x61, 0x66, 0x62, 0xc3, 0xa1, 0x74, 0x75,
  34. 0x72, 0x00};
  35. /* Three characters translating to one utf-16 word each */
  36. static const char d3[] = {0xe6, 0xbd, 0x9c, 0xe6, 0xb0, 0xb4, 0xe8, 0x89,
  37. 0xa6, 0x00};
  38. /* Three letters translating to two utf-16 word each */
  39. static const char d4[] = {0xf0, 0x90, 0x92, 0x8d, 0xf0, 0x90, 0x92, 0x96,
  40. 0xf0, 0x90, 0x92, 0x87, 0x00};
  41. /* Illegal utf-8 strings */
  42. static const char j1[] = {0x6a, 0x31, 0xa1, 0x6c, 0x00};
  43. static const char j2[] = {0x6a, 0x32, 0xc3, 0xc3, 0x6c, 0x00};
  44. static const char j3[] = {0x6a, 0x33, 0xf0, 0x90, 0xf0, 0x00};
  45. static int unicode_test_u16_strlen(struct unit_test_state *uts)
  46. {
  47. ut_asserteq(6, u16_strlen(c1));
  48. ut_asserteq(8, u16_strlen(c2));
  49. ut_asserteq(3, u16_strlen(c3));
  50. ut_asserteq(6, u16_strlen(c4));
  51. return 0;
  52. }
  53. UNICODE_TEST(unicode_test_u16_strlen);
  54. static int unicode_test_u16_strdup(struct unit_test_state *uts)
  55. {
  56. u16 *copy = u16_strdup(c4);
  57. ut_assert(copy != c4);
  58. ut_assert(!memcmp(copy, c4, sizeof(c4)));
  59. free(copy);
  60. return 0;
  61. }
  62. UNICODE_TEST(unicode_test_u16_strdup);
  63. static int unicode_test_u16_strcpy(struct unit_test_state *uts)
  64. {
  65. u16 *r;
  66. u16 copy[10];
  67. r = u16_strcpy(copy, c1);
  68. ut_assert(r == copy);
  69. ut_assert(!memcmp(copy, c1, sizeof(c1)));
  70. return 0;
  71. }
  72. UNICODE_TEST(unicode_test_u16_strcpy);
  73. /* U-Boot uses UTF-16 strings in the EFI context only. */
  74. #if CONFIG_IS_ENABLED(EFI_LOADER) && !defined(API_BUILD)
  75. static int unicode_test_string16(struct unit_test_state *uts)
  76. {
  77. char buf[20];
  78. /* Test length and precision */
  79. memset(buf, 0xff, sizeof(buf));
  80. sprintf(buf, "%8.6ls", c2);
  81. ut_asserteq(' ', buf[1]);
  82. ut_assert(!strncmp(&buf[2], d2, 7));
  83. ut_assert(!buf[9]);
  84. memset(buf, 0xff, sizeof(buf));
  85. sprintf(buf, "%8.6ls", c4);
  86. ut_asserteq(' ', buf[4]);
  87. ut_assert(!strncmp(&buf[5], d4, 12));
  88. ut_assert(!buf[17]);
  89. memset(buf, 0xff, sizeof(buf));
  90. sprintf(buf, "%-8.2ls", c4);
  91. ut_asserteq(' ', buf[8]);
  92. ut_assert(!strncmp(buf, d4, 8));
  93. ut_assert(!buf[14]);
  94. /* Test handling of illegal utf-16 sequences */
  95. memset(buf, 0xff, sizeof(buf));
  96. sprintf(buf, "%ls", i1);
  97. ut_asserteq_str("i1?l", buf);
  98. memset(buf, 0xff, sizeof(buf));
  99. sprintf(buf, "%ls", i2);
  100. ut_asserteq_str("i2?l", buf);
  101. memset(buf, 0xff, sizeof(buf));
  102. sprintf(buf, "%ls", i3);
  103. ut_asserteq_str("i3?", buf);
  104. return 0;
  105. }
  106. UNICODE_TEST(unicode_test_string16);
  107. #endif
  108. static int unicode_test_utf8_get(struct unit_test_state *uts)
  109. {
  110. const char *s;
  111. s32 code;
  112. int i;
  113. /* Check characters less than 0x800 */
  114. s = d2;
  115. for (i = 0; i < 8; ++i) {
  116. code = utf8_get((const char **)&s);
  117. /* c2 is the utf-8 encoding of d2 */
  118. ut_asserteq(c2[i], code);
  119. if (!code)
  120. break;
  121. }
  122. ut_asserteq_ptr(s, d2 + 9)
  123. /* Check characters less than 0x10000 */
  124. s = d3;
  125. for (i = 0; i < 4; ++i) {
  126. code = utf8_get((const char **)&s);
  127. /* c3 is the utf-8 encoding of d3 */
  128. ut_asserteq(c3[i], code);
  129. if (!code)
  130. break;
  131. }
  132. ut_asserteq_ptr(s, d3 + 9)
  133. /* Check character greater 0xffff */
  134. s = d4;
  135. code = utf8_get((const char **)&s);
  136. ut_asserteq(0x0001048d, code);
  137. ut_asserteq_ptr(s, d4 + 4);
  138. return 0;
  139. }
  140. UNICODE_TEST(unicode_test_utf8_get);
  141. static int unicode_test_utf8_put(struct unit_test_state *uts)
  142. {
  143. char buffer[8] = { 0, };
  144. char *pos;
  145. /* Commercial at, translates to one character */
  146. pos = buffer;
  147. ut_assert(!utf8_put('@', &pos))
  148. ut_asserteq(1, pos - buffer);
  149. ut_asserteq('@', buffer[0]);
  150. ut_assert(!buffer[1]);
  151. /* Latin letter G with acute, translates to two charactes */
  152. pos = buffer;
  153. ut_assert(!utf8_put(0x1f4, &pos));
  154. ut_asserteq(2, pos - buffer);
  155. ut_asserteq_str("\xc7\xb4", buffer);
  156. /* Tagalog letter i, translates to three characters */
  157. pos = buffer;
  158. ut_assert(!utf8_put(0x1701, &pos));
  159. ut_asserteq(3, pos - buffer);
  160. ut_asserteq_str("\xe1\x9c\x81", buffer);
  161. /* Hamster face, translates to four characters */
  162. pos = buffer;
  163. ut_assert(!utf8_put(0x1f439, &pos));
  164. ut_asserteq(4, pos - buffer);
  165. ut_asserteq_str("\xf0\x9f\x90\xb9", buffer);
  166. /* Illegal code */
  167. pos = buffer;
  168. ut_asserteq(-1, utf8_put(0xd888, &pos));
  169. return 0;
  170. }
  171. UNICODE_TEST(unicode_test_utf8_put);
  172. static int unicode_test_utf8_utf16_strlen(struct unit_test_state *uts)
  173. {
  174. ut_asserteq(6, utf8_utf16_strlen(d1));
  175. ut_asserteq(8, utf8_utf16_strlen(d2));
  176. ut_asserteq(3, utf8_utf16_strlen(d3));
  177. ut_asserteq(6, utf8_utf16_strlen(d4));
  178. /* illegal utf-8 sequences */
  179. ut_asserteq(4, utf8_utf16_strlen(j1));
  180. ut_asserteq(4, utf8_utf16_strlen(j2));
  181. ut_asserteq(3, utf8_utf16_strlen(j3));
  182. return 0;
  183. }
  184. UNICODE_TEST(unicode_test_utf8_utf16_strlen);
  185. static int unicode_test_utf8_utf16_strnlen(struct unit_test_state *uts)
  186. {
  187. ut_asserteq(3, utf8_utf16_strnlen(d1, 3));
  188. ut_asserteq(6, utf8_utf16_strnlen(d1, 13));
  189. ut_asserteq(6, utf8_utf16_strnlen(d2, 6));
  190. ut_asserteq(2, utf8_utf16_strnlen(d3, 2));
  191. ut_asserteq(4, utf8_utf16_strnlen(d4, 2));
  192. ut_asserteq(6, utf8_utf16_strnlen(d4, 3));
  193. /* illegal utf-8 sequences */
  194. ut_asserteq(4, utf8_utf16_strnlen(j1, 16));
  195. ut_asserteq(4, utf8_utf16_strnlen(j2, 16));
  196. ut_asserteq(3, utf8_utf16_strnlen(j3, 16));
  197. return 0;
  198. }
  199. UNICODE_TEST(unicode_test_utf8_utf16_strnlen);
  200. /**
  201. * ut_u16_strcmp() - Compare to u16 strings.
  202. *
  203. * @a1: first string
  204. * @a2: second string
  205. * @count: number of u16 to compare
  206. * Return: -1 if a1 < a2, 0 if a1 == a2, 1 if a1 > a2
  207. */
  208. static int unicode_test_u16_strcmp(const u16 *a1, const u16 *a2, size_t count)
  209. {
  210. for (; (*a1 || *a2) && count; ++a1, ++a2, --count) {
  211. if (*a1 < *a2)
  212. return -1;
  213. if (*a1 > *a2)
  214. return 1;
  215. }
  216. return 0;
  217. }
  218. static int unicode_test_utf8_utf16_strcpy(struct unit_test_state *uts)
  219. {
  220. u16 buf[16];
  221. u16 *pos;
  222. pos = buf;
  223. utf8_utf16_strcpy(&pos, d1);
  224. ut_asserteq(6, pos - buf);
  225. ut_assert(!unicode_test_u16_strcmp(buf, c1, SIZE_MAX));
  226. pos = buf;
  227. utf8_utf16_strcpy(&pos, d2);
  228. ut_asserteq(8, pos - buf);
  229. ut_assert(!unicode_test_u16_strcmp(buf, c2, SIZE_MAX));
  230. pos = buf;
  231. utf8_utf16_strcpy(&pos, d3);
  232. ut_asserteq(3, pos - buf);
  233. ut_assert(!unicode_test_u16_strcmp(buf, c3, SIZE_MAX));
  234. pos = buf;
  235. utf8_utf16_strcpy(&pos, d4);
  236. ut_asserteq(6, pos - buf);
  237. ut_assert(!unicode_test_u16_strcmp(buf, c4, SIZE_MAX));
  238. /* Illegal utf-8 strings */
  239. pos = buf;
  240. utf8_utf16_strcpy(&pos, j1);
  241. ut_asserteq(4, pos - buf);
  242. ut_assert(!unicode_test_u16_strcmp(buf, L"j1?l", SIZE_MAX));
  243. pos = buf;
  244. utf8_utf16_strcpy(&pos, j2);
  245. ut_asserteq(4, pos - buf);
  246. ut_assert(!unicode_test_u16_strcmp(buf, L"j2?l", SIZE_MAX));
  247. pos = buf;
  248. utf8_utf16_strcpy(&pos, j3);
  249. ut_asserteq(3, pos - buf);
  250. ut_assert(!unicode_test_u16_strcmp(buf, L"j3?", SIZE_MAX));
  251. return 0;
  252. }
  253. UNICODE_TEST(unicode_test_utf8_utf16_strcpy);
  254. static int unicode_test_utf8_utf16_strncpy(struct unit_test_state *uts)
  255. {
  256. u16 buf[16];
  257. u16 *pos;
  258. pos = buf;
  259. memset(buf, 0, sizeof(buf));
  260. utf8_utf16_strncpy(&pos, d1, 4);
  261. ut_asserteq(4, pos - buf);
  262. ut_assert(!buf[4]);
  263. ut_assert(!unicode_test_u16_strcmp(buf, c1, 4));
  264. pos = buf;
  265. memset(buf, 0, sizeof(buf));
  266. utf8_utf16_strncpy(&pos, d2, 10);
  267. ut_asserteq(8, pos - buf);
  268. ut_assert(buf[4]);
  269. ut_assert(!unicode_test_u16_strcmp(buf, c2, SIZE_MAX));
  270. pos = buf;
  271. memset(buf, 0, sizeof(buf));
  272. utf8_utf16_strncpy(&pos, d3, 2);
  273. ut_asserteq(2, pos - buf);
  274. ut_assert(!buf[2]);
  275. ut_assert(!unicode_test_u16_strcmp(buf, c3, 2));
  276. pos = buf;
  277. memset(buf, 0, sizeof(buf));
  278. utf8_utf16_strncpy(&pos, d4, 2);
  279. ut_asserteq(4, pos - buf);
  280. ut_assert(!buf[4]);
  281. ut_assert(!unicode_test_u16_strcmp(buf, c4, 4));
  282. pos = buf;
  283. memset(buf, 0, sizeof(buf));
  284. utf8_utf16_strncpy(&pos, d4, 10);
  285. ut_asserteq(6, pos - buf);
  286. ut_assert(buf[5]);
  287. ut_assert(!unicode_test_u16_strcmp(buf, c4, SIZE_MAX));
  288. return 0;
  289. }
  290. UNICODE_TEST(unicode_test_utf8_utf16_strncpy);
  291. static int unicode_test_utf16_get(struct unit_test_state *uts)
  292. {
  293. const u16 *s;
  294. s32 code;
  295. int i;
  296. /* Check characters less than 0x10000 */
  297. s = c2;
  298. for (i = 0; i < 9; ++i) {
  299. code = utf16_get((const u16 **)&s);
  300. ut_asserteq(c2[i], code);
  301. if (!code)
  302. break;
  303. }
  304. ut_asserteq_ptr(c2 + 8, s);
  305. /* Check character greater 0xffff */
  306. s = c4;
  307. code = utf16_get((const u16 **)&s);
  308. ut_asserteq(0x0001048d, code);
  309. ut_asserteq_ptr(c4 + 2, s);
  310. return 0;
  311. }
  312. UNICODE_TEST(unicode_test_utf16_get);
  313. static int unicode_test_utf16_put(struct unit_test_state *uts)
  314. {
  315. u16 buffer[4] = { 0, };
  316. u16 *pos;
  317. /* Commercial at, translates to one word */
  318. pos = buffer;
  319. ut_assert(!utf16_put('@', &pos));
  320. ut_asserteq(1, pos - buffer);
  321. ut_asserteq((u16)'@', buffer[0]);
  322. ut_assert(!buffer[1]);
  323. /* Hamster face, translates to two words */
  324. pos = buffer;
  325. ut_assert(!utf16_put(0x1f439, &pos));
  326. ut_asserteq(2, pos - buffer);
  327. ut_asserteq((u16)0xd83d, buffer[0]);
  328. ut_asserteq((u16)0xdc39, buffer[1]);
  329. ut_assert(!buffer[2]);
  330. /* Illegal code */
  331. pos = buffer;
  332. ut_asserteq(-1, utf16_put(0xd888, &pos));
  333. return 0;
  334. }
  335. UNICODE_TEST(unicode_test_utf16_put);
  336. static int unicode_test_utf16_strnlen(struct unit_test_state *uts)
  337. {
  338. ut_asserteq(3, utf16_strnlen(c1, 3));
  339. ut_asserteq(6, utf16_strnlen(c1, 13));
  340. ut_asserteq(6, utf16_strnlen(c2, 6));
  341. ut_asserteq(2, utf16_strnlen(c3, 2));
  342. ut_asserteq(2, utf16_strnlen(c4, 2));
  343. ut_asserteq(3, utf16_strnlen(c4, 3));
  344. /* illegal utf-16 word sequences */
  345. ut_asserteq(4, utf16_strnlen(i1, 16));
  346. ut_asserteq(4, utf16_strnlen(i2, 16));
  347. ut_asserteq(3, utf16_strnlen(i3, 16));
  348. return 0;
  349. }
  350. UNICODE_TEST(unicode_test_utf16_strnlen);
  351. static int unicode_test_utf16_utf8_strlen(struct unit_test_state *uts)
  352. {
  353. ut_asserteq(6, utf16_utf8_strlen(c1));
  354. ut_asserteq(9, utf16_utf8_strlen(c2));
  355. ut_asserteq(9, utf16_utf8_strlen(c3));
  356. ut_asserteq(12, utf16_utf8_strlen(c4));
  357. /* illegal utf-16 word sequences */
  358. ut_asserteq(4, utf16_utf8_strlen(i1));
  359. ut_asserteq(4, utf16_utf8_strlen(i2));
  360. ut_asserteq(3, utf16_utf8_strlen(i3));
  361. return 0;
  362. }
  363. UNICODE_TEST(unicode_test_utf16_utf8_strlen);
  364. static int unicode_test_utf16_utf8_strnlen(struct unit_test_state *uts)
  365. {
  366. ut_asserteq(3, utf16_utf8_strnlen(c1, 3));
  367. ut_asserteq(6, utf16_utf8_strnlen(c1, 13));
  368. ut_asserteq(7, utf16_utf8_strnlen(c2, 6));
  369. ut_asserteq(6, utf16_utf8_strnlen(c3, 2));
  370. ut_asserteq(8, utf16_utf8_strnlen(c4, 2));
  371. ut_asserteq(12, utf16_utf8_strnlen(c4, 3));
  372. return 0;
  373. }
  374. UNICODE_TEST(unicode_test_utf16_utf8_strnlen);
  375. static int unicode_test_utf16_utf8_strcpy(struct unit_test_state *uts)
  376. {
  377. char buf[16];
  378. char *pos;
  379. pos = buf;
  380. utf16_utf8_strcpy(&pos, c1);
  381. ut_asserteq(6, pos - buf);
  382. ut_asserteq_str(d1, buf);
  383. pos = buf;
  384. utf16_utf8_strcpy(&pos, c2);
  385. ut_asserteq(9, pos - buf);
  386. ut_asserteq_str(d2, buf);
  387. pos = buf;
  388. utf16_utf8_strcpy(&pos, c3);
  389. ut_asserteq(9, pos - buf);
  390. ut_asserteq_str(d3, buf);
  391. pos = buf;
  392. utf16_utf8_strcpy(&pos, c4);
  393. ut_asserteq(12, pos - buf);
  394. ut_asserteq_str(d4, buf);
  395. /* Illegal utf-16 strings */
  396. pos = buf;
  397. utf16_utf8_strcpy(&pos, i1);
  398. ut_asserteq(4, pos - buf);
  399. ut_asserteq_str("i1?l", buf);
  400. pos = buf;
  401. utf16_utf8_strcpy(&pos, i2);
  402. ut_asserteq(4, pos - buf);
  403. ut_asserteq_str("i2?l", buf);
  404. pos = buf;
  405. utf16_utf8_strcpy(&pos, i3);
  406. ut_asserteq(3, pos - buf);
  407. ut_asserteq_str("i3?", buf);
  408. return 0;
  409. }
  410. UNICODE_TEST(unicode_test_utf16_utf8_strcpy);
  411. static int unicode_test_utf16_utf8_strncpy(struct unit_test_state *uts)
  412. {
  413. char buf[16];
  414. char *pos;
  415. pos = buf;
  416. memset(buf, 0, sizeof(buf));
  417. utf16_utf8_strncpy(&pos, c1, 4);
  418. ut_asserteq(4, pos - buf);
  419. ut_assert(!buf[4]);
  420. ut_assert(!strncmp(buf, d1, 4));
  421. pos = buf;
  422. memset(buf, 0, sizeof(buf));
  423. utf16_utf8_strncpy(&pos, c2, 10);
  424. ut_asserteq(9, pos - buf);
  425. ut_assert(buf[4]);
  426. ut_assert(!strncmp(buf, d2, SIZE_MAX));
  427. pos = buf;
  428. memset(buf, 0, sizeof(buf));
  429. utf16_utf8_strncpy(&pos, c3, 2);
  430. ut_asserteq(6, pos - buf);
  431. ut_assert(!buf[6]);
  432. ut_assert(!strncmp(buf, d3, 6));
  433. pos = buf;
  434. memset(buf, 0, sizeof(buf));
  435. utf16_utf8_strncpy(&pos, c4, 2);
  436. ut_asserteq(8, pos - buf);
  437. ut_assert(!buf[8]);
  438. ut_assert(!strncmp(buf, d4, 8));
  439. pos = buf;
  440. memset(buf, 0, sizeof(buf));
  441. utf16_utf8_strncpy(&pos, c4, 10);
  442. ut_asserteq(12, pos - buf);
  443. ut_assert(buf[5]);
  444. ut_assert(!strncmp(buf, d4, SIZE_MAX));
  445. return 0;
  446. }
  447. UNICODE_TEST(unicode_test_utf16_utf8_strncpy);
  448. static int unicode_test_utf_to_lower(struct unit_test_state *uts)
  449. {
  450. ut_asserteq('@', utf_to_lower('@'));
  451. ut_asserteq('a', utf_to_lower('A'));
  452. ut_asserteq('z', utf_to_lower('Z'));
  453. ut_asserteq('[', utf_to_lower('['));
  454. ut_asserteq('m', utf_to_lower('m'));
  455. /* Latin letter O with diaresis (umlaut) */
  456. ut_asserteq(0x00f6, utf_to_lower(0x00d6));
  457. #ifdef CONFIG_EFI_UNICODE_CAPITALIZATION
  458. /* Cyrillic letter I*/
  459. ut_asserteq(0x0438, utf_to_lower(0x0418));
  460. #endif
  461. return 0;
  462. }
  463. UNICODE_TEST(unicode_test_utf_to_lower);
  464. static int unicode_test_utf_to_upper(struct unit_test_state *uts)
  465. {
  466. ut_asserteq('`', utf_to_upper('`'));
  467. ut_asserteq('A', utf_to_upper('a'));
  468. ut_asserteq('Z', utf_to_upper('z'));
  469. ut_asserteq('{', utf_to_upper('{'));
  470. ut_asserteq('M', utf_to_upper('M'));
  471. /* Latin letter O with diaresis (umlaut) */
  472. ut_asserteq(0x00d6, utf_to_upper(0x00f6));
  473. #ifdef CONFIG_EFI_UNICODE_CAPITALIZATION
  474. /* Cyrillic letter I */
  475. ut_asserteq(0x0418, utf_to_upper(0x0438));
  476. #endif
  477. return 0;
  478. }
  479. UNICODE_TEST(unicode_test_utf_to_upper);
  480. static int unicode_test_u16_strncmp(struct unit_test_state *uts)
  481. {
  482. ut_assert(u16_strncmp(L"abc", L"abc", 3) == 0);
  483. ut_assert(u16_strncmp(L"abcdef", L"abcghi", 3) == 0);
  484. ut_assert(u16_strncmp(L"abcdef", L"abcghi", 6) < 0);
  485. ut_assert(u16_strncmp(L"abcghi", L"abcdef", 6) > 0);
  486. ut_assert(u16_strcmp(L"abc", L"abc") == 0);
  487. ut_assert(u16_strcmp(L"abcdef", L"deghi") < 0);
  488. ut_assert(u16_strcmp(L"deghi", L"abcdef") > 0);
  489. return 0;
  490. }
  491. UNICODE_TEST(unicode_test_u16_strncmp);
  492. int do_ut_unicode(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  493. {
  494. struct unit_test *tests = ll_entry_start(struct unit_test, unicode_test);
  495. const int n_ents = ll_entry_count(struct unit_test, unicode_test);
  496. return cmd_ut_category("Unicode", tests, n_ents, argc, argv);
  497. }