rpm.scm 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2023 Maxim Cournoyer <maxim.cournoyer@gmail.com>
  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-rpm)
  19. #:use-module (guix rpm)
  20. #:use-module (rnrs bytevectors)
  21. #:use-module (srfi srfi-1)
  22. #:use-module (srfi srfi-26)
  23. #:use-module (srfi srfi-64)
  24. #:use-module (srfi srfi-71))
  25. ;; For white-box testing.
  26. (define-syntax-rule (expose-internal name)
  27. (define name (@@ (guix rpm) name)))
  28. (expose-internal RPMTAG_ARCH)
  29. (expose-internal RPMTAG_LICENSE)
  30. (expose-internal RPMTAG_NAME)
  31. (expose-internal RPMTAG_OS)
  32. (expose-internal RPMTAG_RELEASE)
  33. (expose-internal RPMTAG_SUMMARY)
  34. (expose-internal RPMTAG_VERSION)
  35. (expose-internal header-entry-count)
  36. (expose-internal header-entry-tag)
  37. (expose-internal header-entry-value)
  38. (expose-internal header-entry?)
  39. (expose-internal make-header)
  40. (expose-internal make-header-entry)
  41. (expose-internal make-header-index+data)
  42. (test-begin "rpm")
  43. (test-equal "lead must be 96 bytes long"
  44. 96
  45. (length (generate-lead "hello-2.12.1")))
  46. (define header-entries
  47. (list (make-header-entry RPMTAG_NAME 1 "hello")
  48. (make-header-entry RPMTAG_VERSION 1 "2.12.1")
  49. (make-header-entry RPMTAG_RELEASE 1 "0")
  50. (make-header-entry RPMTAG_SUMMARY 1
  51. "Hello, GNU world: An example GNU package")
  52. (make-header-entry RPMTAG_LICENSE 1 "GPL 3 or later")
  53. (make-header-entry RPMTAG_OS 1 "Linux")
  54. (make-header-entry RPMTAG_ARCH 1 "x86_64")))
  55. (define expected-header-index-length
  56. (* 16 (length header-entries))) ;16 bytes per index entry
  57. (define expected-header-data-length
  58. (+ (length header-entries) ;to account for null bytes
  59. (fold + 0 (map (compose string-length (cut header-entry-value <>))
  60. header-entries))))
  61. (let ((index data (make-header-index+data header-entries)))
  62. (test-equal "header index"
  63. expected-header-index-length
  64. (length index))
  65. ;; This test depends on the fact that only STRING entries are used, and that
  66. ;; they are composed of single byte characters and the delimiting null byte.
  67. (test-equal "header data"
  68. expected-header-data-length
  69. (length data)))
  70. (test-equal "complete header section"
  71. (+ 16 ;leading magic + count bytes
  72. expected-header-index-length expected-header-data-length)
  73. (length (make-header header-entries)))
  74. (test-end)