You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

64 lines
2.2 KiB

  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (test-zlib)
  19. #:use-module (guix zlib)
  20. #:use-module (guix tests)
  21. #:use-module (srfi srfi-64)
  22. #:use-module (rnrs bytevectors)
  23. #:use-module (rnrs io ports)
  24. #:use-module (ice-9 match))
  25. ;; Test the (guix zlib) module.
  26. (unless (zlib-available?)
  27. (exit 77))
  28. (test-begin "zlib")
  29. (test-assert "compression/decompression pipe"
  30. (let ((data (random-bytevector (+ (random 10000)
  31. (* 20 1024)))))
  32. (match (pipe)
  33. ((parent . child)
  34. (match (primitive-fork)
  35. (0 ;compress
  36. (dynamic-wind
  37. (const #t)
  38. (lambda ()
  39. (close-port parent)
  40. (call-with-gzip-output-port child
  41. (lambda (port)
  42. (put-bytevector port data))))
  43. (lambda ()
  44. (primitive-exit 0))))
  45. (pid ;decompress
  46. (begin
  47. (close-port child)
  48. (let ((received (call-with-gzip-input-port parent
  49. (lambda (port)
  50. (get-bytevector-all port))
  51. #:buffer-size (* 64 1024))))
  52. (match (waitpid pid)
  53. ((_ . status)
  54. (and (zero? status)
  55. (port-closed? parent)
  56. (bytevector=? received data))))))))))))
  57. (test-end)