/*1* Copyright (c) 2010 Kungliga Tekniska Högskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Portions Copyright (c) 2010 Apple Inc. All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10*11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13*14* 2. Redistributions in binary form must reproduce the above copyright15* notice, this list of conditions and the following disclaimer in the16* documentation and/or other materials provided with the distribution.17*18* 3. Neither the name of the Institute nor the names of its contributors19* may be used to endorse or promote products derived from this software20* without specific prior written permission.21*22* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND23* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32* SUCH DAMAGE.33*/3435#include <stdio.h>36#include <err.h>3738#include "heimbase.h"39#include "heimbasepriv.h"4041static void42memory_free(heim_object_t obj)43{44}4546static int47test_memory(void)48{49void *ptr;5051ptr = heim_alloc(10, "memory", memory_free);5253heim_retain(ptr);54heim_release(ptr);5556heim_retain(ptr);57heim_release(ptr);5859heim_release(ptr);6061ptr = heim_alloc(10, "memory", NULL);62heim_release(ptr);6364return 0;65}6667static int68test_dict(void)69{70heim_dict_t dict;71heim_number_t a1 = heim_number_create(1);72heim_string_t a2 = heim_string_create("hejsan");73heim_number_t a3 = heim_number_create(3);74heim_string_t a4 = heim_string_create("foosan");7576dict = heim_dict_create(10);7778heim_dict_add_value(dict, a1, a2);79heim_dict_add_value(dict, a3, a4);8081heim_dict_delete_key(dict, a3);82heim_dict_delete_key(dict, a1);8384heim_release(a1);85heim_release(a2);86heim_release(a3);87heim_release(a4);8889heim_release(dict);9091return 0;92}9394static int95test_auto_release(void)96{97heim_auto_release_t ar1, ar2;98heim_number_t n1;99heim_string_t s1;100101ar1 = heim_auto_release_create();102103s1 = heim_string_create("hejsan");104heim_auto_release(s1);105106n1 = heim_number_create(1);107heim_auto_release(n1);108109ar2 = heim_auto_release_create();110111n1 = heim_number_create(1);112heim_auto_release(n1);113114heim_release(ar2);115heim_release(ar1);116117return 0;118}119120static int121test_string(void)122{123heim_string_t s1, s2;124const char *string = "hejsan";125126s1 = heim_string_create(string);127s2 = heim_string_create(string);128129if (heim_cmp(s1, s2) != 0) {130printf("the same string is not the same\n");131exit(1);132}133134heim_release(s1);135heim_release(s2);136137return 0;138}139140int141main(int argc, char **argv)142{143int res = 0;144145res |= test_memory();146res |= test_dict();147res |= test_auto_release();148res |= test_string();149150return res;151}152153154