1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- ;; This file is part of scheme-GNUnet.
- ;; Copyright (C) 2021 Maxime Devos
- ;;
- ;; scheme-GNUnet is free software: you can redistribute it and/or modify it
- ;; under the terms of the GNU Affero General Public License as published
- ;; by the Free Software Foundation, either version 3 of the License,
- ;; or (at your option) any later version.
- ;;
- ;; scheme-GNUnet is distributed in the hope that it will be useful, but
- ;; WITHOUT ANY WARRANTY; without even the implied warranty of
- ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- ;; Affero General Public License for more details.
- ;;
- ;; You should have received a copy of the GNU Affero General Public License
- ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
- ;;
- ;; SPDX-License-Identifier: AGPL3.0-or-later
- (import (gnu gnunet utils bv-slice)
- (srfi srfi-26)
- (rnrs conditions)
- (rnrs bytevectors))
- (test-begin "bv-slice")
- ;; slice-copy!
- ;; TODO maybe more specific conditions
- (test-error "destination of slice-copy! must be writable"
- &assertion
- (slice-copy! (make-slice/read-write 9)
- (slice/read-only (make-slice/read-write 9))))
- (test-error "source of slice-copy! must be readable"
- &assertion
- (slice-copy! (slice/write-only (make-slice/read-write 9))
- (make-slice/read-write 9)))
- (test-error "lengths must match (1)"
- &assertion
- (slice-copy! (make-slice/read-write 9)
- (make-slice/read-write 0)))
- (test-error "lengths must match (2)"
- &assertion
- (slice-copy! (make-slice/read-write 0)
- (make-slice/read-write 9)))
- (test-equal "slice-copy! copies"
- #vu8(0 1 2 3)
- (let ((source (bv-slice/read-write #vu8(0 1 2 3)))
- (dest (make-slice/read-write 4)))
- (slice-copy! source dest)
- (slice-bv dest)))
- (test-equal "also if there's an offset in the source"
- #vu8(0 1 2 3)
- (let ((source (slice-slice (bv-slice/read-write #vu8(0 0 1 2 3)) 1))
- (dest (make-slice/read-write 4)))
- (slice-copy! source dest)
- (slice-bv dest)))
- (test-equal "also if the destination bv is long"
- #vu8(9 8 0 1 2 3)
- (let ((source (bv-slice/read-write #vu8(8 0 1 2)))
- (dest (slice-slice
- (bv-slice/read-write (bytevector-copy #vu8(9 7 7 7 7 3)))
- 1 4)))
- (slice-copy! source dest)
- (slice-bv dest)))
- (test-equal "slice-zero! writes zeros"
- #vu8(1 2 0 0 5 6 7 8)
- (let ((dest
- (slice-slice
- (bv-slice/read-write (bytevector-copy #vu8(1 2 3 4 5 6 7 8)))
- 2 2)))
- (slice-zero! dest)
- (slice-bv dest)))
- (test-error "slice-zero! requires writability"
- &assertion
- (slice-zero! (slice/write-only (make-slice/read-write 9))))
- (test-error "even if the length is zero"
- &assertion
- (slice-zero! (slice/write-only (make-slice/read-write 0))))
- (test-end "bv-slice")
- ;; ^ TODO: test other procedures
|