symbian-qemu-0.9.1-12/dtc-trunk/tests/setprop.c
changeset 1 2fb8b9db1c86
equal deleted inserted replaced
0:ffa851df0825 1:2fb8b9db1c86
       
     1 /*
       
     2  * libfdt - Flat Device Tree manipulation
       
     3  *	Testcase for fdt_setprop()
       
     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 
       
    21 #include <stdlib.h>
       
    22 #include <stdio.h>
       
    23 #include <string.h>
       
    24 #include <ctype.h>
       
    25 #include <stdint.h>
       
    26 
       
    27 #include <fdt.h>
       
    28 #include <libfdt.h>
       
    29 
       
    30 #include "tests.h"
       
    31 #include "testdata.h"
       
    32 
       
    33 #define SPACE		65536
       
    34 #define NEW_STRING	"here is quite a long test string, blah blah blah"
       
    35 
       
    36 int main(int argc, char *argv[])
       
    37 {
       
    38 	void *fdt;
       
    39 	void *buf;
       
    40 	const uint32_t *intp;
       
    41 	const char *strp;
       
    42 	int err;
       
    43 
       
    44 	test_init(argc, argv);
       
    45 	fdt = load_blob_arg(argc, argv);
       
    46 
       
    47 	buf = xmalloc(SPACE);
       
    48 
       
    49 	err = fdt_open_into(fdt, buf, SPACE);
       
    50 	if (err)
       
    51 		FAIL("fdt_open_into(): %s", fdt_strerror(err));
       
    52 
       
    53 	fdt = buf;
       
    54 
       
    55 	intp = check_getprop_cell(fdt, 0, "prop-int", TEST_VALUE_1);
       
    56 
       
    57 	verbose_printf("Old int value was 0x%08x\n", *intp);
       
    58 	err = fdt_setprop_string(fdt, 0, "prop-int", NEW_STRING);
       
    59 	if (err)
       
    60 		FAIL("Failed to set \"prop-int\" to \"%s\": %s",
       
    61 		     NEW_STRING, fdt_strerror(err));
       
    62 
       
    63 	strp = check_getprop_string(fdt, 0, "prop-int", NEW_STRING);
       
    64 	verbose_printf("New value is \"%s\"\n", strp);
       
    65 
       
    66 	strp = check_getprop(fdt, 0, "prop-str", strlen(TEST_STRING_1)+1,
       
    67 			     TEST_STRING_1);
       
    68 
       
    69 	verbose_printf("Old string value was \"%s\"\n", strp);
       
    70 	err = fdt_setprop(fdt, 0, "prop-str", NULL, 0);
       
    71 	if (err)
       
    72 		FAIL("Failed to empty \"prop-str\": %s",
       
    73 		     fdt_strerror(err));
       
    74 
       
    75 	check_getprop(fdt, 0, "prop-str", 0, NULL);
       
    76 
       
    77 	PASS();
       
    78 }