atomic.test 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. ;;;; atomic.test --- test suite for Guile's atomic operations -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright (C) 2016 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 3 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 atomic)
  19. #:use-module (ice-9 atomic)
  20. #:use-module ((oop goops) #:select (class-of <atomic-box>))
  21. #:use-module (test-suite lib))
  22. (with-test-prefix/c&e "atomics"
  23. (pass-if "predicate" (atomic-box? (make-atomic-box 42)))
  24. (pass-if-equal "ref" 42 (atomic-box-ref (make-atomic-box 42)))
  25. (pass-if-equal "swap" 42 (atomic-box-swap! (make-atomic-box 42) 10))
  26. (pass-if-equal "set and ref" 10
  27. (let ((box (make-atomic-box 42)))
  28. (atomic-box-set! box 10)
  29. (atomic-box-ref box)))
  30. (pass-if-equal "swap and ref" 10
  31. (let ((box (make-atomic-box 42)))
  32. (atomic-box-swap! box 10)
  33. (atomic-box-ref box)))
  34. (pass-if-equal "compare and swap" 42
  35. (let ((box (make-atomic-box 42)))
  36. (atomic-box-compare-and-swap! box 42 10)))
  37. (pass-if-equal "compare and swap (wrong)" 42
  38. (let ((box (make-atomic-box 42)))
  39. (atomic-box-compare-and-swap! box 43 10)))
  40. (pass-if-equal "compare and swap and ref" 10
  41. (let ((box (make-atomic-box 42)))
  42. (atomic-box-compare-and-swap! box 42 10)
  43. (atomic-box-ref box)))
  44. (pass-if-equal "compare and swap (wrong) and ref" 42
  45. (let ((box (make-atomic-box 42)))
  46. (atomic-box-compare-and-swap! box 43 10)
  47. (atomic-box-ref box)))
  48. (pass-if-equal "class-of" <atomic-box>
  49. (class-of (make-atomic-box 42))))