t-pkg-queue.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * t-pkg-queue.c - test pkg-queue implementation
  4. *
  5. * Copyright © 2010 Guillem Jover <guillem@debian.org>
  6. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <config.h>
  21. #include <compat.h>
  22. #include <dpkg/test.h>
  23. #include <dpkg/dpkg-db.h>
  24. #include <dpkg/pkg-queue.h>
  25. static void
  26. test_pkg_queue_init(void)
  27. {
  28. struct pkg_queue q = PKG_QUEUE_INIT;
  29. struct pkg_list l;
  30. test_pass(q.length == 0);
  31. test_pass(q.head == NULL);
  32. test_pass(q.tail == NULL);
  33. test_pass(pkg_queue_is_empty(&q));
  34. q = (struct pkg_queue){ .length = 10, .head = &l, .tail = &l };
  35. pkg_queue_init(&q);
  36. test_pass(q.length == 0);
  37. test_pass(q.head == NULL);
  38. test_pass(q.tail == NULL);
  39. test_pass(pkg_queue_is_empty(&q));
  40. }
  41. static void
  42. test_pkg_queue_push_pop(void)
  43. {
  44. struct pkg_queue q = PKG_QUEUE_INIT;
  45. struct pkg_list *l1, *l2, *l3;
  46. struct pkginfo pkg, *pkgp;
  47. pkg_blank(&pkg);
  48. test_pass(pkg_queue_is_empty(&q));
  49. /* Test push operations. */
  50. l1 = pkg_queue_push(&q, &pkg);
  51. test_pass(l1 != NULL);
  52. test_pass(q.head == l1);
  53. test_pass(q.tail == l1);
  54. test_pass(q.length == 1);
  55. l2 = pkg_queue_push(&q, &pkg);
  56. test_pass(l2 != NULL);
  57. test_pass(q.head == l1);
  58. test_pass(q.tail == l2);
  59. test_pass(q.length == 2);
  60. l3 = pkg_queue_push(&q, &pkg);
  61. test_pass(l3 != NULL);
  62. test_pass(q.head == l1);
  63. test_pass(q.tail == l3);
  64. test_pass(q.length == 3);
  65. /* Test pop operations. */
  66. pkgp = pkg_queue_pop(&q);
  67. test_pass(pkgp != NULL);
  68. test_pass(q.head == l2);
  69. test_pass(q.tail == l3);
  70. test_pass(q.length == 2);
  71. pkgp = pkg_queue_pop(&q);
  72. test_pass(pkgp != NULL);
  73. test_pass(q.head == l3);
  74. test_pass(q.tail == l3);
  75. test_pass(q.length == 1);
  76. pkgp = pkg_queue_pop(&q);
  77. test_pass(pkgp != NULL);
  78. test_pass(q.head == NULL);
  79. test_pass(q.tail == NULL);
  80. test_pass(q.length == 0);
  81. test_pass(pkg_queue_is_empty(&q));
  82. pkgp = pkg_queue_pop(&q);
  83. test_pass(pkgp == NULL);
  84. test_pass(q.head == NULL);
  85. test_pass(q.tail == NULL);
  86. test_pass(q.length == 0);
  87. pkg_queue_destroy(&q);
  88. }
  89. static void
  90. test(void)
  91. {
  92. test_pkg_queue_init();
  93. test_pkg_queue_push_pop();
  94. }