chiark / gitweb /
Add missing notification when scratch queued, lost a couple of commits back
[disorder] / libtests / t-basen.c
CommitLineData
b90f122b
RK
1/*
2 * This file is part of DisOrder.
3 * Copyright (C) 2005, 2007, 2008 Richard Kettlewell
4 *
e7eb3a27 5 * This program is free software: you can redistribute it and/or modify
b90f122b 6 * it under the terms of the GNU General Public License as published by
e7eb3a27 7 * the Free Software Foundation, either version 3 of the License, or
b90f122b 8 * (at your option) any later version.
e7eb3a27
RK
9 *
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.
14 *
b90f122b 15 * You should have received a copy of the GNU General Public License
e7eb3a27 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b90f122b
RK
17 */
18#include "test.h"
19
c68d8eba 20static void test_basen(void) {
1c814807 21 uint32_t v[64];
b90f122b
RK
22 char buffer[1024];
23
b90f122b
RK
24 v[0] = 999;
25 insist(basen(v, 1, buffer, sizeof buffer, 10) == 0);
26 check_string(buffer, "999");
1c814807
RK
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);
b90f122b
RK
37
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");
41
42 v[0] = 0x00010203;
43 v[1] = 0x04050607;
44 v[2] = 0x08090A0B;
45 v[3] = 0x0C0D0E0F;
46 insist(basen(v, 4, buffer, sizeof buffer, 256) == 0);
47 check_string(buffer, "123456789abcdef");
1c814807
RK
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);
b90f122b
RK
66
67 v[0] = 0x00010203;
68 v[1] = 0x04050607;
69 v[2] = 0x08090A0B;
70 v[3] = 0x0C0D0E0F;
71 insist(basen(v, 4, buffer, sizeof buffer, 16) == 0);
72 check_string(buffer, "102030405060708090a0b0c0d0e0f");
1c814807
RK
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);
b90f122b
RK
91
92 v[0] = 0x00010203;
93 v[1] = 0x04050607;
94 v[2] = 0x08090A0B;
95 v[3] = 0x0C0D0E0F;
96 insist(basen(v, 4, buffer, 10, 16) == -1);
97}
98
c68d8eba
RK
99TEST(basen);
100
b90f122b
RK
101/*
102Local Variables:
103c-basic-offset:2
104comment-column:40
105fill-column:79
106indent-tabs-mode:nil
107End:
108*/