2 * This file is part of DisOrder.
3 * Copyright (C) 2005, 2007, 2008 Richard Kettlewell
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 static void test_basen(void) {
25 insist(basen(v, 1, buffer, sizeof buffer, 10) == 0);
26 check_string(buffer, "999");
27 memset(v, 0xFF, sizeof v);
28 insist(nesab(v, 1, buffer, 10) == 0);
29 check_integer(v[0], 999);
30 check_integer(v[1], 0xFFFFFFFF);
31 insist(nesab(v, 4, buffer, 10) == 0);
32 check_integer(v[0], 0);
33 check_integer(v[1], 0);
34 check_integer(v[2], 0);
35 check_integer(v[3], 999);
36 check_integer(v[4], 0xFFFFFFFF);
38 v[0] = 1+2*7+3*7*7+4*7*7*7;
39 insist(basen(v, 1, buffer, sizeof buffer, 7) == 0);
40 check_string(buffer, "4321");
46 insist(basen(v, 4, buffer, sizeof buffer, 256) == 0);
47 check_string(buffer, "123456789abcdef");
48 memset(v, 0xFF, sizeof v);
49 insist(nesab(v, 4, buffer, 256) == 0);
50 check_integer(v[0], 0x00010203);
51 check_integer(v[1], 0x04050607);
52 check_integer(v[2], 0x08090A0B);
53 check_integer(v[3], 0x0C0D0E0F);
54 check_integer(v[4], 0xFFFFFFFF);
55 memset(v, 0xFF, sizeof v);
56 insist(nesab(v, 8, buffer, 256) == 0);
57 check_integer(v[0], 0);
58 check_integer(v[1], 0);
59 check_integer(v[2], 0);
60 check_integer(v[3], 0);
61 check_integer(v[4], 0x00010203);
62 check_integer(v[5], 0x04050607);
63 check_integer(v[6], 0x08090A0B);
64 check_integer(v[7], 0x0C0D0E0F);
65 check_integer(v[8], 0xFFFFFFFF);
71 insist(basen(v, 4, buffer, sizeof buffer, 16) == 0);
72 check_string(buffer, "102030405060708090a0b0c0d0e0f");
73 memset(v, 0xFF, sizeof v);
74 insist(nesab(v, 4, buffer, 16) == 0);
75 check_integer(v[0], 0x00010203);
76 check_integer(v[1], 0x04050607);
77 check_integer(v[2], 0x08090A0B);
78 check_integer(v[3], 0x0C0D0E0F);
79 check_integer(v[4], 0xFFFFFFFF);
80 memset(v, 0xFF, sizeof v);
81 insist(nesab(v, 8, buffer, 16) == 0);
82 check_integer(v[0], 0);
83 check_integer(v[1], 0);
84 check_integer(v[2], 0);
85 check_integer(v[3], 0);
86 check_integer(v[4], 0x00010203);
87 check_integer(v[5], 0x04050607);
88 check_integer(v[6], 0x08090A0B);
89 check_integer(v[7], 0x0C0D0E0F);
90 check_integer(v[8], 0xFFFFFFFF);
96 insist(basen(v, 4, buffer, 10, 16) == -1);