blob: 1d31bffe9f66701581c6ae7cff27da1dc862a37c [file] [log] [blame]
Lorenz Brun378a4452021-01-26 13:47:41 +01001// Copyright 2020 The Monogon Project Authors.
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17package erofs
18
19import (
20 "bytes"
21 "encoding/binary"
22 "testing"
23
24 "github.com/stretchr/testify/assert"
25)
26
Serge Bazanski216fe7b2021-05-21 18:36:16 +020027// These test that the specified structures serialize to the same number of
28// bytes as the ones in the EROFS kernel module.
Lorenz Brun378a4452021-01-26 13:47:41 +010029
30func TestSuperblockSize(t *testing.T) {
31 var buf bytes.Buffer
32 if err := binary.Write(&buf, binary.LittleEndian, &superblock{}); err != nil {
33 t.Fatalf("failed to write superblock: %v", err)
34 }
35 assert.Equal(t, 128, buf.Len())
36}
37
38func TestDirectoryEntrySize(t *testing.T) {
39 var buf bytes.Buffer
40 if err := binary.Write(&buf, binary.LittleEndian, &directoryEntryRaw{}); err != nil {
41 t.Fatalf("failed to write directory entry: %v", err)
42 }
43 assert.Equal(t, 12, buf.Len())
44}
45
46func TestInodeCompactSize(t *testing.T) {
47 var buf bytes.Buffer
48 if err := binary.Write(&buf, binary.LittleEndian, &inodeCompact{}); err != nil {
49 t.Fatalf("failed to write compact inode: %v", err)
50 }
51 assert.Equal(t, 32, buf.Len())
52}