]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blame - lib/ext2fs/tst_byteswap.c
Remove trailing whitespace for the entire source tree
[thirdparty/e2fsprogs.git] / lib / ext2fs / tst_byteswap.c
CommitLineData
9ec53cf4
TT
1/*
2 * This testing program makes sure the byteswap functions work
3 *
4 * Copyright (C) 2000 by Theodore Ts'o.
efc6f628 5 *
9ec53cf4
TT
6 * %Begin-Header%
7 * This file may be redistributed under the terms of the GNU Public
8 * License.
9 * %End-Header%
10 */
11
12#include <stdio.h>
13#include <string.h>
14#if HAVE_UNISTD_H
15#include <unistd.h>
16#endif
17#include <fcntl.h>
18#include <time.h>
19#include <sys/stat.h>
20#include <sys/types.h>
21#if HAVE_ERRNO_H
22#include <errno.h>
23#endif
24
9ec53cf4 25#include "ext2_fs.h"
9ec53cf4
TT
26#include "ext2fs.h"
27
28__u16 test1[] = {
29 0x0001, 0x0100,
30 0x1234, 0x3412,
31 0xff00, 0x00ff,
32 0x4000, 0x0040,
33 0xfeff, 0xfffe,
34 0x0000, 0x0000
35 };
36
37__u32 test2[] = {
38 0x00000001, 0x01000000,
39 0x80000000, 0x00000080,
40 0x12345678, 0x78563412,
41 0xffff0000, 0x0000ffff,
42 0x00ff0000, 0x0000ff00,
43 0xff000000, 0x000000ff,
44 0x00000000, 0x00000000
45 };
46
546a1ff1 47int main(int argc, char **argv)
9ec53cf4
TT
48{
49 int i;
50 int errors = 0;
51
52 printf("Testing ext2fs_swab16\n");
53 i=0;
54 do {
55 printf("swab16(0x%04x) = 0x%04x\n", test1[i],
56 ext2fs_swab16(test1[i]));
57 if (ext2fs_swab16(test1[i]) != test1[i+1]) {
58 printf("Error!!! %04x != %04x\n",
59 ext2fs_swab16(test1[i]), test1[i+1]);
60 errors++;
61 }
62 if (ext2fs_swab16(test1[i+1]) != test1[i]) {
63 printf("Error!!! %04x != %04x\n",
64 ext2fs_swab16(test1[i+1]), test1[i]);
65 errors++;
66 }
67 i += 2;
68 } while (test1[i] != 0);
efc6f628 69
9ec53cf4
TT
70 printf("Testing ext2fs_swab32\n");
71 i = 0;
72 do {
73 printf("swab32(0x%08x) = 0x%08x\n", test2[i],
74 ext2fs_swab32(test2[i]));
75 if (ext2fs_swab32(test2[i]) != test2[i+1]) {
76 printf("Error!!! %04x != %04x\n",
77 ext2fs_swab32(test2[i]), test2[i+1]);
78 errors++;
79 }
80 if (ext2fs_swab32(test2[i+1]) != test2[i]) {
81 printf("Error!!! %04x != %04x\n",
82 ext2fs_swab32(test2[i+1]), test2[i]);
83 errors++;
84 }
85 i += 2;
86 } while (test2[i] != 0);
87
88 if (!errors)
89 printf("No errors found in the byteswap implementation!\n");
efc6f628 90
9ec53cf4
TT
91 return errors;
92}