File: 586-aio-buffer-indexing.py

package info (click to toggle)
libnbd 1.24.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,956 kB
  • sloc: ansic: 55,063; ml: 12,326; sh: 8,817; python: 4,757; makefile: 3,036; perl: 165; cpp: 24
file content (49 lines) | stat: -rw-r--r-- 1,395 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# libnbd Python bindings
# Copyright Red Hat
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

# More tests of nbd.Buffer.  Indexing.

import nbd

ba = bytearray(512)
buf = nbd.Buffer.from_bytearray(ba)
assert len(buf) == 512

assert buf[0] == 0
assert buf[511] == 0
buf[0] = 1
assert buf[0] == 1
assert buf[511] == 0

for i in range(0, 511):
    buf[i] = i & 255
assert buf[0] == 0
assert buf[1] == 1
assert buf[255] == 255
assert buf[256] == 0
for i in range(0, 511):
    assert buf[i] == i & 255

for i in range(0, 511):
    buf[i] = 0
assert buf.is_zero() is True

# Check that an uninitialized buffer reads as zero.  It should be
# initialized on the first read.
buf2 = nbd.Buffer(512)
for i in range(0, 511):
    assert buf2[i] == 0