/***{{{******************************************************************* * This file is part of libco - object library for C * * Copyright (c) 2002 Peter Rockai (yenar) * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * * General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; see the file COPYING. If not, write to * * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * * Boston, MA 02111-1307, USA. * *******************************************************************}}}***/ /* {{{ file description */ /** \file object.c * \brief Test libco's object engine. Quite simple, for now. */ /* }}} */ /* {{{ includes */ #include "co_object.h" #include "test_util.h" /* }}} */ /* {{{ */ CO_OBJECT (person) { CO_HEAD_FULL; CO_ATTR (int, id); }; /* }}} */ #include "reflection.cometa" /* {{{ */ static co person_new (void) { co_o_head_full o; o = new (person_s); person_meth_ar_init (o); CO_BLESS (o, person, 0); return o; } /* }}} */ /* {{{ */ CO_METH (person, getid) { CO_METH_INI (person, getid); CO_RETURN (int, CO_A (int, self, id)); } /* }}} */ /* {{{ */ CO_METH (person, default) { CO_METH_INI (person, default); CO_RETURN (int, 0); } /* }}} */ /* {{{ */ int main (void) { co p; co super; int i; super = co_super_new (); __co_file_init_reflection_c (super); // create new test object p = CO_NEW (person); ((person) p) -> id = 13; if (! (i = CO_M (p, has_method, COM (getid)) . _int)) { CO_DEBUG (1, "getid = %d, result = %d", COM (getid), i); error (1, "existing method reported as not found\n"); } if ((i = CO_M (p, has_method, COM (foo)) . _int)) { CO_DEBUG (1, "getid = %d, result = %d", COM (getid), i); error (1, "nonexistent method reported as found\n"); } return 0; } /* }}} */