arbiters.test 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. ;;;; arbiters.test --- test arbiters functions -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright (C) 2004, 2006 Free Software Foundation, Inc.
  4. ;;;;
  5. ;;;; This library is free software; you can redistribute it and/or
  6. ;;;; modify it under the terms of the GNU Lesser General Public
  7. ;;;; License as published by the Free Software Foundation; either
  8. ;;;; version 2.1 of the License, or (at your option) any later version.
  9. ;;;;
  10. ;;;; This library is distributed in the hope that it will be useful,
  11. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. ;;;; Lesser General Public License for more details.
  14. ;;;;
  15. ;;;; You should have received a copy of the GNU Lesser General Public
  16. ;;;; License along with this library; if not, write to the Free Software
  17. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. (define-module (test-suite test-arbiters)
  19. #:use-module (test-suite lib))
  20. ;;;
  21. ;;; arbiter display
  22. ;;;
  23. (with-test-prefix "arbiter display"
  24. ;; nothing fancy, just exercise the printing code
  25. (pass-if "never locked"
  26. (let ((arb (make-arbiter "foo"))
  27. (port (open-output-string)))
  28. (display arb port)
  29. #t))
  30. (pass-if "locked"
  31. (let ((arb (make-arbiter "foo"))
  32. (port (open-output-string)))
  33. (try-arbiter arb)
  34. (display arb port)
  35. #t))
  36. (pass-if "unlocked"
  37. (let ((arb (make-arbiter "foo"))
  38. (port (open-output-string)))
  39. (try-arbiter arb)
  40. (release-arbiter arb)
  41. (display arb port)
  42. #t)))
  43. ;;;
  44. ;;; try-arbiter
  45. ;;;
  46. (with-test-prefix "try-arbiter"
  47. (pass-if "lock"
  48. (let ((arb (make-arbiter "foo")))
  49. (try-arbiter arb)))
  50. (pass-if "already locked"
  51. (let ((arb (make-arbiter "foo")))
  52. (try-arbiter arb)
  53. (not (try-arbiter arb))))
  54. (pass-if "already locked twice"
  55. (let ((arb (make-arbiter "foo")))
  56. (try-arbiter arb)
  57. (try-arbiter arb)
  58. (not (try-arbiter arb)))))
  59. ;;;
  60. ;;; release-arbiter
  61. ;;;
  62. (with-test-prefix "release-arbiter"
  63. (pass-if "lock"
  64. (let ((arb (make-arbiter "foo")))
  65. (try-arbiter arb)
  66. (release-arbiter arb)))
  67. (pass-if "never locked"
  68. (let ((arb (make-arbiter "foo")))
  69. (not (release-arbiter arb))))
  70. (pass-if "never locked twice"
  71. (let ((arb (make-arbiter "foo")))
  72. (release-arbiter arb)
  73. (not (release-arbiter arb))))
  74. (pass-if "already unlocked"
  75. (let ((arb (make-arbiter "foo")))
  76. (try-arbiter arb)
  77. (release-arbiter arb)
  78. (not (release-arbiter arb))))
  79. (pass-if "already unlocked twice"
  80. (let ((arb (make-arbiter "foo")))
  81. (try-arbiter arb)
  82. (release-arbiter arb)
  83. (release-arbiter arb)
  84. (not (release-arbiter arb)))))