symbian-qemu-0.9.1-12/dtc-trunk/tests/set_name.c
changeset 1 2fb8b9db1c86
equal deleted inserted replaced
0:ffa851df0825 1:2fb8b9db1c86
       
     1 /*
       
     2  * libfdt - Flat Device Tree manipulation
       
     3  *	Testcase for fdt_set_name()
       
     4  * Copyright (C) 2006 David Gibson, IBM Corporation.
       
     5  *
       
     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.
       
    10  *
       
    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.
       
    15  *
       
    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
       
    19  */
       
    20 #include <stdlib.h>
       
    21 #include <stdio.h>
       
    22 #include <string.h>
       
    23 #include <stdint.h>
       
    24 
       
    25 #include <fdt.h>
       
    26 #include <libfdt.h>
       
    27 
       
    28 #include "tests.h"
       
    29 #include "testdata.h"
       
    30 
       
    31 void check_set_name(void *fdt, const char *path, const char *newname)
       
    32 {
       
    33 	int offset;
       
    34 	const char *getname, *oldname;
       
    35 	int len, err;
       
    36 
       
    37 	oldname = strrchr(path, '/');
       
    38 	if (!oldname)
       
    39 		TEST_BUG();
       
    40 	oldname += 1;
       
    41 
       
    42 	offset = fdt_path_offset(fdt, path);
       
    43 	if (offset < 0)
       
    44 		FAIL("Couldn't find %s", path);
       
    45 
       
    46 	getname = fdt_get_name(fdt, offset, &len);
       
    47 	verbose_printf("fdt_get_name(%d) returns \"%s\" (len=%d)\n",
       
    48 		       offset, getname, len);
       
    49 	if (!getname)
       
    50 		FAIL("fdt_get_name(%d): %s", offset, fdt_strerror(len));
       
    51 
       
    52 	if (strcmp(getname, oldname) != 0)
       
    53 		FAIL("fdt_get_name(%s) returned \"%s\" instead of \"%s\"",
       
    54 		     path, getname, oldname);
       
    55 
       
    56 	if (len != strlen(getname))
       
    57 		FAIL("fdt_get_name(%s) returned length %d instead of %zd",
       
    58 		     path, len, strlen(getname));
       
    59 
       
    60 	err = fdt_set_name(fdt, offset, newname);
       
    61 	if (err)
       
    62 		FAIL("fdt_set_name(%d, \"%s\"): %s", offset, newname,
       
    63 		     fdt_strerror(err));
       
    64 
       
    65 	getname = fdt_get_name(fdt, offset, &len);
       
    66 	if (!getname)
       
    67 		FAIL("fdt_get_name(%d): %s", offset, fdt_strerror(len));
       
    68 
       
    69 	if (strcmp(getname, newname) != 0)
       
    70 		FAIL("fdt_get_name(%s) returned \"%s\" instead of \"%s\"",
       
    71 		     path, getname, newname);
       
    72 
       
    73 	if (len != strlen(getname))
       
    74 		FAIL("fdt_get_name(%s) returned length %d instead of %zd",
       
    75 		     path, len, strlen(getname));
       
    76 }
       
    77 
       
    78 int main(int argc, char *argv[])
       
    79 {
       
    80 	void *fdt;
       
    81 
       
    82 	test_init(argc, argv);
       
    83 	fdt = load_blob_arg(argc, argv);
       
    84 	fdt = open_blob_rw(fdt);
       
    85 
       
    86 	check_set_name(fdt, "/subnode@1", "subnode@17");
       
    87 	check_set_name(fdt, "/subnode@2/subsubnode@0", "fred@0");
       
    88 	check_set_name(fdt, "/subnode@17/subsubnode", "something@0");
       
    89 
       
    90 	PASS();
       
    91 }