blob: 2e4938e854fe05708c2afbe5e425d92603deb61f [file] [log] [blame]
Tim Windelschmidt6d33a432025-02-04 14:34:25 +01001// Copyright The Monogon Project Authors.
Lorenz Brun378a4452021-01-26 13:47:41 +01002// SPDX-License-Identifier: Apache-2.0
Lorenz Brun378a4452021-01-26 13:47:41 +01003
4package erofs
5
6import (
7 "reflect"
8 "testing"
9)
10
11func TestEncodeSmallVLEBlock(t *testing.T) {
12 type args struct {
13 vals [2]uint16
14 blkaddr uint32
15 }
16 tests := []struct {
17 name string
18 args args
19 want [8]byte
20 }{
21 {
22 name: "Reference",
23 args: args{vals: [2]uint16{vleClusterTypeHead | 1527, vleClusterTypeNonhead | 1}, blkaddr: 1},
24 want: [8]byte{0xf7, 0x15, 0x01, 0x20, 0x01, 0x00, 0x00, 0x00},
25 },
26 }
27 for _, tt := range tests {
28 t.Run(tt.name, func(t *testing.T) {
29 if got := encodeSmallVLEBlock(tt.args.vals, tt.args.blkaddr); !reflect.DeepEqual(got, tt.want) {
30 t.Errorf("encodeSmallVLEBlock() = %v, want %v", got, tt.want)
31 }
32 })
33 }
34}
35
36func TestEncodeBigVLEBlock(t *testing.T) {
37 type args struct {
38 vals [16]uint16
39 blkaddr uint32
40 }
41 tests := []struct {
42 name string
43 args args
44 want [32]byte
45 }{
46 {
47 name: "Reference",
48 args: args{
49 vals: [16]uint16{
50 vleClusterTypeNonhead | 2,
51 vleClusterTypeHead | 1460,
52 vleClusterTypeNonhead | 1,
53 vleClusterTypeNonhead | 2,
54 vleClusterTypeHead | 2751,
55 vleClusterTypeNonhead | 1,
56 vleClusterTypeNonhead | 2,
57 vleClusterTypeHead | 940,
58 vleClusterTypeNonhead | 1,
59 vleClusterTypeHead | 3142,
60 vleClusterTypeNonhead | 1,
61 vleClusterTypeNonhead | 2,
62 vleClusterTypeHead | 1750,
63 vleClusterTypeNonhead | 1,
64 vleClusterTypeNonhead | 2,
65 vleClusterTypeHead | 683,
66 },
67 blkaddr: 3,
68 },
69 want: [32]byte{0x02, 0x20, 0x6d, 0x15, 0x00, 0x0a, 0x80, 0xbf, 0x5a, 0x00, 0x28, 0x00, 0xb2, 0x4e, 0x01, 0xa0, 0x11, 0x17, 0x00, 0x0a, 0x80, 0xd6, 0x56, 0x00, 0x28, 0x00, 0xae, 0x4a, 0x03, 0x00, 0x00, 0x00}},
70 }
71 for _, tt := range tests {
72 t.Run(tt.name, func(t *testing.T) {
73 if got := encodeBigVLEBlock(tt.args.vals, tt.args.blkaddr); !reflect.DeepEqual(got, tt.want) {
74 t.Errorf("encodeBigVLEBlock() = %v, want %v", got, tt.want)
75 }
76 })
77 }
78}