/***{{{******************************************************************* * 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_o_small.h" #include "test_util.h" /* }}} */ /* {{{ */ CO_OBJECT (person, small) { CO_ATTR (int, id); }; /* }}} */ /* {{{ */ CO_OBJECT (employee, small) { co person; CO_ATTR (int, id); }; /* }}} */ #include "delegation.cometa" /* {{{ */ CO_METH (person, init) { person td; td = new (person_s); this -> data = td; CO_RETURN (int, 0); } /* }}} */ /* {{{ */ CO_METH (employee, init) { employee td; td = new (employee_s); this -> data = td; CO_RETURN (int, 0); } /* }}} */ /* {{{ */ CO_METH (employee, getid) { CO_METH_INI (employee, getid); return CO_D (td -> person, getid); } /* }}} */ /* {{{ */ CO_METH (employee, getid_nodeleg) { CO_METH_INI (employee, getid_nodeleg); return CO_M (td -> person, getid); } /* }}} */ /* {{{ */ CO_METH (employee, default) { CO_METH_INI (employee, default); CO_RETURN (int, 0); } /* }}} */ /* {{{ */ 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_o_small p, e; int pid_dir, pid_ind, eid_dir, eid_ind; int eid_nod; co super; super = co_init (); __co_file_init_delegation_c (super); // create new test object e = employee_new (); p = person_new (); ((employee) (e -> data)) -> person = p; ((employee) (e -> data)) -> id = 42; ((person) (p -> data)) -> id = 13; eid_ind = CO_M (e, getid) . _int; eid_dir = CO_A (int, e, id); pid_ind = CO_M (p, getid) . _int; pid_dir = CO_A (int, p, id); eid_nod = CO_M (e, getid_nodeleg) . _int; CO_DEBUG (1, "pid: dir = %d, ind = %d", pid_dir, pid_ind); CO_DEBUG (1, "eid: dir = %d, ind = %d, nodeleg = %d", eid_dir, eid_ind, eid_nod); if (eid_ind != eid_dir || eid_dir != 42 || pid_dir != 13) error (1, "unexpected results\n"); if (pid_dir != pid_ind || pid_dir != eid_nod) error (2, "bad non-delegated results\n"); return 0; } /* }}} */