4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 import "encoding/binary"
26 var expected405
= make([]byte, 512)
28 func psf(user_data
int, buf2
[]byte, offset
uint64, status
uint,
31 panic("expected user_data == 42")
34 panic("expected *error == 0")
37 panic("expected offset == 0")
39 if status
!= uint(READ_DATA
) {
40 panic("expected status == READ_DATA")
42 if !bytes
.Equal(buf2
, expected405
) {
43 fmt
.Printf("buf2 = %s\nexpected = %s\n", buf2
, expected405
)
44 panic("expected sub-buffer == expected pattern")
49 func Test405PReadStructured(t
*testing
.T
) {
51 for i
:= 0; i
< 512; i
+= 8 {
52 binary
.BigEndian
.PutUint64(expected405
[i
:i
+8], uint64(i
))
57 t
.Fatalf("could not create handle: %s", err
)
61 err
= h
.ConnectCommand([]string{
62 "nbdkit", "-s", "--exit-with-parent", "-v",
63 "pattern", "size=512",
66 t
.Fatalf("could not connect: %s", err
)
69 buf
:= make([]byte, 512)
70 err
= h
.PreadStructured(buf
, 0,
71 func(buf2
[]byte, offset
uint64, status
uint,
73 return psf(42, buf2
, offset
, status
, error
)
78 if !bytes
.Equal(buf
, expected405
) {
79 t
.Fatalf("did not read expected data")
82 var optargs PreadStructuredOptargs
83 optargs
.FlagsSet
= true
84 optargs
.Flags
= CMD_FLAG_DF
85 wrap
:= func(buf2
[]byte, offset
uint64, status
uint, error
*int) int {
86 return psf(42, buf2
, offset
, status
, error
)
88 err
= h
.PreadStructured(buf
, 0, wrap
, &optargs
)
92 if !bytes
.Equal(buf
, expected405
) {
93 t
.Fatalf("did not read expected data")