obj_test.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. *******************************************************************************
  3. \file obj_test.c
  4. \brief Tests for compound objects
  5. \project bee2/test
  6. \created 2013.04.16
  7. \version 2025.04.25
  8. \copyright The Bee2 authors
  9. \license Licensed under the Apache License, Version 2.0 (see LICENSE.txt).
  10. *******************************************************************************
  11. */
  12. #include <bee2/core/mem.h>
  13. #include <bee2/core/obj.h>
  14. /*
  15. *******************************************************************************
  16. Тестирование
  17. *******************************************************************************
  18. */
  19. struct obj_test1_t
  20. {
  21. obj_hdr_t hdr;
  22. octet* p1;
  23. word* p2;
  24. octet a1[12];
  25. word a2[12];
  26. };
  27. struct obj_test2_t
  28. {
  29. obj_hdr_t hdr;
  30. struct obj_test1_t* p1;
  31. octet* p2;
  32. octet a2[123];
  33. };
  34. bool_t objTest()
  35. {
  36. octet buf[1024];
  37. struct obj_test1_t obj1[1];
  38. struct obj_test2_t obj2[1];
  39. void* t;
  40. // настроить obj1
  41. obj1->hdr.keep = sizeof(struct obj_test1_t);
  42. obj1->hdr.p_count = 2;
  43. obj1->hdr.o_count = 0;
  44. obj1->p1 = obj1->a1;
  45. obj1->p2 = obj1->a2;
  46. memSet(obj1->a1, 0x11, sizeof(obj1->a1));
  47. memSet(obj1->a2, 0x12, sizeof(obj1->a2));
  48. // настроить obj2
  49. obj2->hdr.keep = sizeof(struct obj_test2_t);
  50. obj2->hdr.p_count = 2;
  51. obj2->hdr.o_count = 1;
  52. obj2->p1 = obj1;
  53. obj2->p2 = obj2->a2;
  54. memSet(obj2->a2, 0x22, sizeof(obj2->a2));
  55. // подготовить буфер
  56. if (sizeof(buf) < objKeep(obj1) + 2 * objKeep(obj2))
  57. return FALSE;
  58. memSetZero(buf, sizeof(buf));
  59. // копировать obj2 в buf
  60. objCopy(buf, obj2);
  61. // присоединить obj1 к buf
  62. objAppend(buf, obj1, 0);
  63. // получить встроенный объект
  64. t = objPtr(buf, 0, void);
  65. // проверить
  66. if (memCmp(objPtr(t, 0, void), obj1->a1, sizeof(obj1->a1)) != 0 ||
  67. memCmp(objPtr(t, 1, void), obj1->a2, sizeof(obj1->a2)) != 0 ||
  68. memCmp(objPtr(buf, 1, void), obj2->a2, sizeof(obj2->a2)))
  69. return FALSE;
  70. // присоединить buf к buf
  71. objAppend(buf, buf, 0);
  72. // получить встроенный объект
  73. t = objPtr(buf, 0, void);
  74. // проверить
  75. if (memCmp(objPtr(t, 1, void), obj2->a2, sizeof(obj2->a2)) != 0)
  76. return FALSE;
  77. // все нормально
  78. return TRUE;
  79. }