str_test.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. *******************************************************************************
  3. \file str_test.c
  4. \brief Tests for strings
  5. \project bee2/test
  6. \created 2017.01.12
  7. \version 2023.09.18
  8. \copyright The Bee2 authors
  9. \license Licensed under the Apache License, Version 2.0 (see LICENSE.txt).
  10. *******************************************************************************
  11. */
  12. #include <bee2/core/str.h>
  13. /*
  14. *******************************************************************************
  15. Тестирование
  16. *******************************************************************************
  17. */
  18. bool_t strTest()
  19. {
  20. char str[] = "123456";
  21. char buf[16];
  22. // len
  23. if (!strIsValid(str) ||
  24. strLen(str) + 1 != sizeof(str) ||
  25. strLen2(str, sizeof(str)) != strLen(str) ||
  26. strLen2(str, sizeof(str) + 1) != strLen(str))
  27. return FALSE;
  28. // cmp
  29. strCopy(buf, str);
  30. if (strCmp(buf, str) != 0 || !strEq(buf, str))
  31. return FALSE;
  32. // props
  33. if (!strIsNumeric(str) ||
  34. strIsNumeric("1234?") ||
  35. !strIsAlphanumeric(str) ||
  36. strIsAlphanumeric("1234?") ||
  37. !strIsAlphanumeric("1234aAz") ||
  38. !strIsPrintable(str) ||
  39. !strIsPrintable("12?=:") ||
  40. strIsPrintable("12&=:") ||
  41. strIsPrintable("1@2=:") ||
  42. !strStartsWith(str, "12") ||
  43. strStartsWith(str, "13") ||
  44. !strEndsWith(str, "56") ||
  45. strEndsWith(str, "1234567") ||
  46. strEndsWith(str, "57"))
  47. return FALSE;
  48. // rev
  49. strRev(str);
  50. if (!strEq(str, "654321"))
  51. return FALSE;
  52. strCopy(str, "1"), strRev(str);
  53. if (!strEq(str, "1"))
  54. return FALSE;
  55. strCopy(str, "12"), strRev(str);
  56. if (!strEq(str, "21"))
  57. return FALSE;
  58. strCopy(str, "123"), strRev(str);
  59. if (!strEq(str, "321"))
  60. return FALSE;
  61. // все нормально
  62. return TRUE;
  63. }