gnunet/tests/progress-info.scm

93 lines
3.2 KiB
Scheme
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;;;; -*- mode: Scheme; indent-tabs-mode: nil; fill-column: 80; -*-
;;;;
;;;; Copyright © 2015 Rémi Delrue <asgeir@free.fr>
;;;;
;;;; This program is free software: you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation, either version 3 of the License, or
;;;; (at your option) any later version.
;;;;
;;;; This program 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 General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(define-module (test-fs-progress-info)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-64)
#:use-module (rnrs bytevectors)
#:use-module (system foreign)
#:use-module (system foreign-padded)
#:use-module (gnu gnunet common)
#:use-module (gnu gnunet container metadata)
#:use-module (gnu gnunet fs progress-info))
(define-syntax-rule (pi-import name ...)
(begin (define name (@@ (gnu gnunet fs progress-info) name))
...))
(pi-import integer->progress-info-status
progress-info-status->integer
progress-info-get-type
bytevector-u8-fold
u8-bitmap->list)
(test-begin "test-fs-progress-info")
;; integer->progress-info-status
(test-equal '(#:unindex #:progress) (integer->progress-info-status 33))
(test-error 'invalid-arg (integer->progress-info-status 42))
;; progress-info-status->integer
(test-equal 8 (progress-info-status->integer '(#:download #:resume)))
(test-error 'invalid-arg (progress-info-status->integer
'(#:beam-me-up #:scotty)))
;; progress-info-get-type
(define progress-info-download-progress-signature
(list
(list '* '* '* '* '* '*
uint64
time-relative time-relative
uint64 uint32 int
(list '* uint64 uint64
time-relative
unsigned-int uint32 uint32))
unsigned-int
'*))
(test-equal progress-info-download-progress-signature
(progress-info-get-type #:download #:progress))
(test-error 'invalid-arg (progress-info-get-type #:maximum #:warp))
;; bytevector-u8-fold
(let ((bv (make-bytevector 1)))
(bytevector-u8-set! bv 0 #b01101010)
(test-equal '(1 1 1 1)
(bytevector-u8-fold (lambda (acc bool elt)
(if bool
(cons elt acc)
acc))
bv
'(1 1 1 1 1 1 1 1)
'())))
;; u8-bitmap->list
(let ((bv (make-bytevector 3)))
(bytevector-u8-set! bv 0 #b11000001)
(bytevector-u8-set! bv 1 #b00010100)
(bytevector-u8-set! bv 2 #b00010000)
(test-assert
(lset= eq?
'(#\T #\e #\r #\r #\y #\.)
(u8-bitmap->list bv 0
'(#\T #\e #\a #\. #\ #\E #\a #\r
#\l #\- #\G #\r #\a #\y #\. #\
#\H #\o #\t #\.)))))
(test-end)