diff --git a/docs/system_base/libunistring/tc_libunistring_fun_001.yaml b/docs/system_base/libunistring/tc_libunistring_fun_001.yaml new file mode 100644 index 0000000000000000000000000000000000000000..1bd2065901457e4e26686ec0025dd2b8c21d0bdf --- /dev/null +++ b/docs/system_base/libunistring/tc_libunistring_fun_001.yaml @@ -0,0 +1,47 @@ +×÷Õß: xufei +ÓÅÏȼ¶: P1 +Ö§³Ö¼Ü¹¹: noarch +Ö´Ðз½Ê½: ×Ô¶¯ +²âÊÔÀàÐÍ: ¹¦ÄܲâÊÔ +ͨÓñêÇ©: local +ÓÃÀýÃèÊö: ²âÊÔlibunistring¿â¹¦ÄÜ +ÐÞ¸ÄÈË: xufei + +ǰÖÃÌõ¼þ: +- ¿É°²×°libunistring¿ª·¢°ü +- ¾ßÓÐrootȨÏÞ +- Ö§³ÖCÓïÑÔ±àÒë +- ÓÐ×ã¹»µÄ´ÅÅ̿ռä +- Ö§³ÖC11±ê×¼ +- Ö§³Ölibunistring¿â +- ¿É¶Áдµ±Ç°Ä¿Â¼ + +²âÊÔ²½Öè: +- °²×°¿ª·¢°ü +- ÇåÀí¿ÉÄÜ´æÔڵľÉÎļþ +- ´´½¨²âÊÔ³ÌÐò +- ´´½¨libunistring_test.c +- ±àд²âÊÔ´úÂë +- ±àÒë³ÌÐò +- ʹÓÃgcc±àÒë +- ʹÓÃC11±ê×¼ºÍunistring¿â +- ÑéÖ¤¿ÉÖ´ÐÐÎļþ +- ¼ì²éa.outÎļþ´æÔÚ +- ÔËÐвâÊÔ³ÌÐò +- Ö´ÐÐa.out +- ÑéÖ¤Êä³ö½á¹û +- ¼ì²éÊä³öÊÇ·ñΪ"0000001000101" +- ÇåÀí»·¾³ +- ɾ³ýÉú³ÉÎļþ +- Ð¶ÔØ¿ª·¢°ü + +ÆÚÍû½á¹û: +- ³É¹¦°²×°¿ª·¢°ü +- ³É¹¦´´½¨²âÊÔ³ÌÐò +- ³É¹¦±àÒë³ÌÐò +- ³É¹¦Éú³Éa.outÎļþ +- ³É¹¦ÔËÐгÌÐò +- Êä³ö½á¹ûΪ"0000001000101" +- ËùÓÐÃüÁî·µ»ØÂëΪ0 +- ³É¹¦ÇåÀí»·¾³ +- libunistring¹¦ÄܲâÊÔͨ¹ý \ No newline at end of file diff --git a/tests/system_base/libunistring/libunistring_test.c b/tests/system_base/libunistring/libunistring_test.c new file mode 100644 index 0000000000000000000000000000000000000000..f22415852dcf553a767c68dfb27a8a601536efcb --- /dev/null +++ b/tests/system_base/libunistring/libunistring_test.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include + +size_t n_of_utf8_chars(const uint8_t *s) +{ + ucs4_t c; + size_t n = 0; + for (const uint8_t *it = s; it;it = u8_next(&c, it)) n++; + n--; + return n; +} + +int main(void) +{ + const uint8_t *s = (uint8_t *)" è‘« \t芦\n娃"; + size_t n = n_of_utf8_chars(s); + int *p = malloc(n * sizeof(int)); + const uint8_t *it = s; + for (size_t i = 0; i < n; i++) { + ucs4_t c; + it = u8_next(&c, it); + if (uc_is_property_white_space(c)) p[i] = 0; + else p[i] = 1; + } + for (size_t i = 0; i < n; i++) { + printf("%d", p[i]); + } + printf("\n"); + return 0; +} diff --git a/tests/system_base/libunistring/tc_libunistring_fun_001.py b/tests/system_base/libunistring/tc_libunistring_fun_001.py new file mode 100644 index 0000000000000000000000000000000000000000..d7b2c085311980f799d0e3ff86bf7d9f13e3fe40 --- /dev/null +++ b/tests/system_base/libunistring/tc_libunistring_fun_001.py @@ -0,0 +1,55 @@ +# -*- encoding: utf-8 -*- + +""" +@File: tc_libunistring_fun_001.py +@Time: 2026/04/28 10:23:53 +@Author: xufei +@Version: 1.0 +@Contact: xufei@inspur.com +@License: Mulan PSL v2 +@Modify: xufei +""" + +from common.basetest import LocalTest + + +class Test(LocalTest): + """ + See tc_libunistring_fun_001.yaml for details + + :avocado: tags=P1,noarch,local,libunistring + """ + PARAM_DIC = {"pkg_name": "libunistring libunistring-devel gc gcc"} + + def setUp(self): + super().setUp(self.PARAM_DIC) + self.log.info("Start to prepare the test environment.") + self.cmd('rm -rf ./a.out') + self.log.info("End to prepare the test environment.") + + def test(self): + self.log.info("Start to run test.") + + code1, result1 = self.cmd('gcc -std=c11 -pedantic -lunistring libunistring_test.c') + self.assertEqual(code1, 0, "compilation of libunistring_test.c is failed") + + code2, result2 = self.cmd('ls ./a.out') + self.assertEqual(code2, 0, "file a.out is not created") + + code3, result3 = self.cmd('./a.out') + self.assertEqual(code3, 0, "The executable program a.out execution has failed") + + expected_output = "0000001000101" + actual_output = result3.strip() + self.assertEqual(actual_output, expected_output, + f"Expected '{expected_output}', got '{actual_output}'") + + self.log.info("End to run test.") + + def tearDown(self): + super().tearDown(self.PARAM_DIC) + self.log.info("Start to restore the test environment.") + self.cmd('ls ./a.out && rm -rf ./a.out') + self.log.info("End to restore the test environment.") + +