obj_test.c 2.3 KB

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