1 /*
2 * This testing program makes sure the byteswap functions work
3 *
4 * Copyright (C) 2000 by Theodore Ts'o.
5 *
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
25 #include "ext2_fs.h"
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
main(int argc,char ** argv)47 int main(int argc, char **argv)
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);
69
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");
90
91 return errors;
92 }
93