projects/guix·blob master · refs

86 lines · 3.0 KiB

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