2 * Copyright 2011 The Chromium Authors, All Rights Reserved.
4 * utilfdt_test - Tests for utilfdt library
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
33 static void check(const char *fmt, int expect_type, int expect_size)
38 if (utilfdt_decode_type(fmt, &type, &size))
39 FAIL("format '%s': valid format string returned failure", fmt);
40 if (expect_type != type)
41 FAIL("format '%s': expected type='%c', got type='%c'", fmt,
43 if (expect_size != size)
44 FAIL("format '%s': expected size=%d, got size=%d", fmt,
48 static void checkfail(const char *fmt)
53 if (!utilfdt_decode_type(fmt, &type, &size))
54 FAIL("format '%s': invalid format string returned success",
59 * Add the given modifier to each of the valid sizes, and check that we get
62 * \param modifier Modifer string to use as a prefix
63 * \param expected_size The size (in bytes) that we expect (ignored for
66 static void check_sizes(char *modifier, int expected_size)
70 /* set up a string with a hole in it for the format character */
71 if (strlen(modifier) + 2 >= sizeof(fmt))
72 FAIL("modifier string '%s' too long", modifier);
73 strcpy(fmt, modifier);
74 ptr = fmt + strlen(fmt);
77 /* now try each format character in turn */
79 check(fmt, 'i', expected_size);
82 check(fmt, 'u', expected_size);
85 check(fmt, 'x', expected_size);
91 static void test_utilfdt_decode_type(void)
96 /* check all the valid modifiers and sizes */
103 /* try every other character */
105 for (ch = ' '; ch < 127; ch++) {
106 if (!strchr("iuxs", ch)) {
113 /* try a few modifiers at the end */
118 /* and one for the doomsday archives */
119 checkfail("He has all the virtues I dislike and none of the vices "
123 int main(int argc, char *argv[])
125 test_utilfdt_decode_type();