/***{{{******************************************************************* * 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" /* }}} */ #include "object-minimal.cometa" //COT_DEF (test_obj1); //COT_DEF (test_obj2); /* {{{ */ static co_v test_obj_msg (co o, co s, co_id_t a, va_list ap) { co_v rv; CO_DEBUG (1, "called"); rv . _int = 0; if (a == COM (return_42)) { rv . _int = 42; } if (a == COM (save)) { COX_THROW (undef); } if (a == COM (destroy)) { free (o); } return rv; } /* }}} */ /* {{{ */ static co test_obj_new (void) { co_o_small o; o = new (co_o_small_s); o -> msg_handle = test_obj_msg; cox_pop (o); //CO_BLESS_M (o, test_obj2); return o; } /* }}} */ /* {{{ */ int main (void) { co tst; int i; co super; super = co_init (); __co_file_init_object_minimal_c (super); tst = test_obj_new (); if (CO_M (tst, return_42) . _int != 42) error (1, "wrong return value\n"); /*#define CHKF \ if (((co_o_head) tst1) -> msg_proc) \ error (1, "flag not reset"); \ if (((co_o_head) tst2) -> msg_proc) \ error (1, "flag not reset"); // create new test object tst1 = CO_NEW (test_obj1); tst2 = CO_NEW (test_obj2); if (!tst1) error (1, "test object 1 creation failed\n"); if (!tst2) error (1, "test object 2 creation failed\n"); cox_pop (tst2); cox_pop (tst1); // test return status of CO_M if (CO_M (tst1, reload) . _int != 1) error (2, "eh\n"); CO_M (tst1, draw); *//*CO_CNT (tst1, cancel, tst1, save); CO_CNT (tst1, ok, tst1, reload); for (i = 0; i < 200; i ++) { COX_TRY { CO_EV (tst1, ok); CO_EV (tst1, ok); CO_EV (tst1, cancel); } COX_CATCH (err) { CHKF; } COX_CATCH_END; } CHKF; // test program behaviour when handling destruction events CO_CNT (tst1, destroyed, tst2, destroy); CO_CNT (tst2, ok, tst1, destroy); CO_EV (tst2, ok);*/ //CO_M (tst1, destroy); CO_M (super, exit, 0); //if (CO_DESTROY (tst1)) (4, "CO_DESTROY failed\n"); //if (tst1) error (5, "CO_DESTROY did not set tst to NULL\n"); return 0; } /* }}} */