2
* Copyright (c) 2011 Martin Sucha
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
9
* - Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* - Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* - The name of the author may not be used to endorse or promote products
15
* derived from this software without specific prior written permission.
17
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
#include "../tester.h"
36
static ext2_superblock_t *fake_superblock1()
41
buf = malloc(EXT2_SUPERBLOCK_SIZE);
46
for (i = 0; i < EXT2_SUPERBLOCK_SIZE; i++) {
50
return (ext2_superblock_t *) buf;
53
const char *test_libext2_1(void)
55
ext2_superblock_t *fake1;
57
TPRINTF("Testing libext2 superblock getters...\n");
58
TPRINTF("Simple test for correct position and byte order\n");
60
fake1 = fake_superblock1();
62
return "Failed allocating memory for test superblock 1";
65
ASSERT_EQ_32(0x03020100, ext2_superblock_get_total_inode_count(fake1),
66
"Failed getting total inode count");
67
ASSERT_EQ_32(0x07060504, ext2_superblock_get_total_block_count(fake1),
68
"Failed getting total block count");
69
ASSERT_EQ_32(0x0B0A0908, ext2_superblock_get_reserved_block_count(fake1),
70
"Failed getting reserved block count");
71
ASSERT_EQ_32(0x0F0E0D0C, ext2_superblock_get_free_block_count(fake1),
72
"Failed getting free block count");
73
ASSERT_EQ_32(0x13121110, ext2_superblock_get_free_inode_count(fake1),
74
"Failed getting free inode count");
75
ASSERT_EQ_32(0x17161514, ext2_superblock_get_first_block(fake1),
76
"Failed getting first block number");
77
ASSERT_EQ_32(0x1B1A1918, ext2_superblock_get_block_size_log2(fake1),
78
"Failed getting log block size");
79
ASSERT_EQ_32(0x1F1E1D1C, ext2_superblock_get_fragment_size_log2(fake1),
80
"Failed getting log fragment size");
81
ASSERT_EQ_32(0x23222120, ext2_superblock_get_blocks_per_group(fake1),
82
"Failed getting blocks per group");
83
ASSERT_EQ_32(0x27262524, ext2_superblock_get_fragments_per_group(fake1),
84
"Failed getting fragments per group");
85
ASSERT_EQ_32(0x2B2A2928, ext2_superblock_get_inodes_per_group(fake1),
86
"Failed getting inodes per group");
87
ASSERT_EQ_16(0x3938, ext2_superblock_get_magic(fake1),
88
"Failed getting magic number");
89
ASSERT_EQ_16(0x3B3A, ext2_superblock_get_state(fake1),
90
"Failed getting state");
91
ASSERT_EQ_16(0x3F3E, ext2_superblock_get_rev_minor(fake1),
92
"Failed getting minor revision number");
93
ASSERT_EQ_32(0x4B4A4948, ext2_superblock_get_os(fake1),
95
ASSERT_EQ_32(0x4F4E4D4C, ext2_superblock_get_rev_major(fake1),
96
"Failed getting major revision number");
97
ASSERT_EQ_32(0x57565554, ext2_superblock_get_first_inode(fake1),
98
"Failed getting first inode number");
99
ASSERT_EQ_16(0x5958, ext2_superblock_get_inode_size(fake1),
100
"Failed getting size");
101
ASSERT_EQ_8(0x68, fake1->uuid[0], "UUID position is incorrect");
102
ASSERT_EQ_8(0x78, fake1->volume_name[0],
103
"Volume name position is incorrect");