summaryrefslogtreecommitdiff
path: root/test/fs/detail/superblock_test.cpp
blob: fe88ccb4391cd4be5568e5deebfe58ff36db5d90 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include "fs/extfs.hpp"

#include "test/superblock/ext2-filetype.hpp"
#include "test/superblock/ext2-large_file.hpp"
#include "test/superblock/ext2-noopts.hpp"

#include <cute/cute.h>
#include <cute/cute_runner.h>
#include <cute/ostream_listener.h>
#include <cute/xml_listener.h>

#include <cstring>

using cft = fs::detail::superblock::compatible_feature;
using ift = fs::detail::superblock::incompatible_feature;
using rft = fs::detail::superblock::read_only_compatible_feature;

auto superblock_from_bytes(std::array<std::uint8_t, 1024> const & data)
  {
  auto block = fs::detail::superblock{};
  std::memcpy(reinterpret_cast<char *>(&block), data.data(), data.size());
  return block;
  }

void default_initialized_superblock_should_have_no_compatible_features()
  {
  ASSERT(!fs::detail::superblock{}.has_any({
      cft::directory_preallocation,
      cft::imagic_inodes,
      cft::has_journal,
      cft::extended_attribues,
      cft::resize_inode,
      cft::directory_indexing,
      cft::lazy_block_group_initialization,
      cft::exclude_inode,
      cft::exclude_bitmaps,
      cft::sparse_superblock_v2,
      }));
  }

void default_initialized_superblock_should_have_no_incompatible_features()
  {
  ASSERT(!fs::detail::superblock{}.has_any({
      ift::compression,
      ift::filetype,
      ift::recover,
      ift::journal_device,
      ift::meta_block_group,
      ift::extents,
      ift::large_file_system,
      ift::multiple_mount_protection,
      ift::flexible_block_groups,
      ift::large_extended_attribues_in_inodes,
      ift::data_in_directories,
      ift::metadata_checksum_seed_in_superblock,
      ift::large_directory,
      ift::data_in_inode,
      ift::encrypted_inodes,
      }));
  }

void default_initialized_superblock_should_have_no_read_only_compatible_features()
  {
  ASSERT(!fs::detail::superblock{}.has_any({
      rft::sparse_superblock,
      rft::large_file,
      rft::binary_tree_directories,
      rft::huge_file,
      }));
  }

void noopts_superblock_should_have_no_opts()
  {
  auto block = superblock_from_bytes(ext2_noopts);
  ASSERT(!block.has_any({
      cft::directory_preallocation,
      cft::imagic_inodes,
      cft::has_journal,
      cft::extended_attribues,
      cft::resize_inode,
      cft::directory_indexing,
      cft::lazy_block_group_initialization,
      cft::exclude_inode,
      cft::exclude_bitmaps,
      cft::sparse_superblock_v2,
      }));

  ASSERT(!block.has_any({
      ift::compression,
      ift::filetype,
      ift::recover,
      ift::journal_device,
      ift::meta_block_group,
      ift::extents,
      ift::large_file_system,
      ift::multiple_mount_protection,
      ift::flexible_block_groups,
      ift::large_extended_attribues_in_inodes,
      ift::data_in_directories,
      ift::metadata_checksum_seed_in_superblock,
      ift::large_directory,
      ift::data_in_inode,
      ift::encrypted_inodes,
      }));

  ASSERT(!block.has_any({
      rft::sparse_superblock,
      rft::large_file,
      rft::binary_tree_directories,
      rft::huge_file,
      }));
  }

void filetype_superblock_should_have_filetype_option()
  {
  auto block = superblock_from_bytes(ext2_filetype);
  ASSERT(block.has(ift::filetype));
  }

void large_file_superblock_should_have_large_file_option()
  {
  auto block = superblock_from_bytes(ext2_large_file);
  ASSERT(block.has(rft::large_file));
  }

int main(int argc, char * argv[])
  {
  auto tests = cute::suite{
    CUTE(default_initialized_superblock_should_have_no_compatible_features),
    CUTE(default_initialized_superblock_should_have_no_incompatible_features),
    CUTE(default_initialized_superblock_should_have_no_read_only_compatible_features),
    CUTE(noopts_superblock_should_have_no_opts),
    CUTE(filetype_superblock_should_have_filetype_option),
    CUTE(large_file_superblock_should_have_large_file_option),
  };

  cute::xml_file_opener resultFile{argc, argv};
  cute::xml_listener<cute::ostream_listener<>> listener{resultFile.out};
  return !cute::makeRunner(listener, argc, argv)(tests, "fs::detail::superblock");
  }