X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=ETL%2Ftags%2FETL_%40VERSION_MAJ%40_%40VERSION_MIN%40_%40VERSION_REV%40%2Ftest%2Fhandle.cpp;fp=ETL%2Ftags%2FETL_%40VERSION_MAJ%40_%40VERSION_MIN%40_%40VERSION_REV%40%2Ftest%2Fhandle.cpp;h=f66ff922cbecbca534cd8f86077c160b1dbfa949;hb=609ffb6c7ad2996e4dde68b1066a27e80ed8a153;hp=0000000000000000000000000000000000000000;hpb=2431de3e401e81fb920d57b4c278bd2b156c277e;p=synfig.git diff --git a/ETL/tags/ETL_@VERSION_MAJ@_@VERSION_MIN@_@VERSION_REV@/test/handle.cpp b/ETL/tags/ETL_@VERSION_MAJ@_@VERSION_MIN@_@VERSION_REV@/test/handle.cpp new file mode 100644 index 0000000..f66ff92 --- /dev/null +++ b/ETL/tags/ETL_@VERSION_MAJ@_@VERSION_MIN@_@VERSION_REV@/test/handle.cpp @@ -0,0 +1,482 @@ +/*! ======================================================================== +** Extended Template and Library Test Suite +** Handle Template Class Test +** $Id$ +** +** Copyright (c) 2002 Robert B. Quattlebaum Jr. +** +** This package 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 package 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. +** +** === N O T E S =========================================================== +** +** ========================================================================= */ + +/* === H E A D E R S ======================================================= */ + +#include +#include +#include +#include +#include +#include +#include + +/* === M A C R O S ========================================================= */ + +#define NUMBER_OF_OBJECTS 40000 +using namespace std; + +/* === C L A S S E S ======================================================= */ + +struct my_test_obj : public etl::rshared_object +{ + static int instance_count; + int my_id; + my_test_obj(int my_id=0):my_id(my_id) + { + instance_count++; + } + + virtual ~my_test_obj() + { + if(instance_count==0) + printf("Error, instance count is going past zero!\n"); + instance_count--; + } + + bool operator<(const my_test_obj &rhs)const + { + return my_id obj_handle; +typedef etl::rhandle robj_handle; +typedef etl::handle other_obj_handle; +typedef list< obj_handle > obj_list; +typedef list< other_obj_handle > other_obj_list; +typedef list< robj_handle > robj_list; + +int handle_basic_test() +{ + printf("handle: Size of a handle: %u\n",(unsigned int)sizeof(etl::handle)); + printf("handle: Size of a loose_handle: %u\n",(unsigned int)sizeof(etl::loose_handle)); + printf("handle: Size of a rhandle: %u\n",(unsigned int)sizeof(etl::rhandle)); + printf("handle: Size of a shared_object: %u\n",(unsigned int)sizeof(etl::shared_object)); + printf("handle: Size of a rshared_object: %u\n",(unsigned int)sizeof(etl::rshared_object)); + + printf("handle: Basic test: "); + my_test_obj::instance_count=0; + + { + etl::handle obj_handle(new my_test_obj(rand())); + } + + if(my_test_obj::instance_count!=0) + { + printf("FAILED!\n"); + printf(__FILE__":%d: on create/distroy, instance count=%d, should be zero.\n",__LINE__,my_test_obj::instance_count); + return 1; + } + + { + map > my_map; + etl::handle obj_handle(new my_test_obj(rand())); + my_map["bleh"]=obj_handle; + } + + if(my_test_obj::instance_count!=0) + { + printf("FAILED!\n"); + printf(__FILE__":%d: on create/distroy, instance count=%d, should be zero.\n",__LINE__,my_test_obj::instance_count); + return 1; + } + + etl::handle obj_handle(new my_test_obj(rand())); + + if(obj_handle != obj_handle.constant()) + { + printf("FAILED!\n"); + printf(__FILE__":%d: on call to handle<>::constant().\n",__LINE__); + return 1; + } + + printf("PASSED\n"); + + return 0; +} + +int handle_general_use_test(void) +{ + printf("handle: General-use test: "); + my_test_obj::instance_count=0; + + obj_list my_list, my_other_list; + int i; + + for(i=0;i my_item_list; + for(i=0;i=2); + my_item_list.erase(my_item_list.begin()+src); + assert(tmp.obj.rcount()>=1); + my_item_list.insert(my_item_list.begin()+dest,tmp); + assert(tmp.obj.rcount()>=2); + } + + my_item_list.clear(); + + if(my_test_obj::instance_count) + { + printf("FAILED!\n"); + printf(__FILE__":%d: On clear, instance count=%d, should be zero.\n",__LINE__,my_test_obj::instance_count); + return 1; + } + + printf("PASSED\n"); + + return 0; +} + +int handle_inheritance_test(void) +{ + printf("handle: Inheritance test: "); + my_test_obj::instance_count=0; + my_other_test_obj::instance_count=0; + + other_obj_list my_other_list; + int i; + + for(i=0;i handle) +{ + if(handle) { int i=handle.count(); i++; } +} + +int loose_handle_test(void) +{ + printf("handle: loose_handle test: "); + my_test_obj::instance_count=0; + + etl::loose_handle obj_handle_loose; + etl::handle obj_handle2; + + { + etl::handle obj_handle(new my_test_obj(rand())); + if(my_test_obj::instance_count!=1) + { + printf("FAILED!\n"); + printf(__FILE__":%d: on handle assignment from new object, instance count=%d, should be 1.\n",__LINE__,my_test_obj::instance_count); + return 1; + } + + obj_handle_loose=obj_handle; + if(obj_handle!=obj_handle_loose) + { + printf("FAILED!\n"); + printf(__FILE__":%d: on loose_handle assignment\n",__LINE__); + return 1; + } + + obj_handle2=obj_handle_loose; + if(my_test_obj::instance_count!=1) + { + printf("FAILED!\n"); + printf(__FILE__":%d: on handle assignment from loose_handle, instance count=%d, should be 1.\n",__LINE__,my_test_obj::instance_count); + return 1; + } + + test_func(obj_handle_loose); + if(my_test_obj::instance_count!=1) + { + printf("FAILED!\n"); + printf(__FILE__":%d: on handle assignment from loose_handle, instance count=%d, should be 1.\n",__LINE__,my_test_obj::instance_count); + return 1; + } + } + + if(my_test_obj::instance_count!=1) + { + printf("FAILED!\n"); + printf(__FILE__":%d: on create/destroy, instance count=%d, should be 1.\n",__LINE__,my_test_obj::instance_count); + return 1; + } + + printf("PASSED\n"); + return 0; +} + +int handle_cast_test() +{ + printf("handle: casting test: "); + + etl::handle obj; + etl::handle other_obj; + etl::loose_handle loose_obj; + + other_obj.spawn(); + loose_obj=other_obj; + + obj=etl::handle::cast_dynamic(loose_obj); + + if(obj!=other_obj) + { + printf("FAILED!\n"); + printf(__FILE__":%d: on handle assignment from loose_handle.\n",__LINE__); + return 1; + } + + printf("PASSED\n"); + return 0; +} + +/* === E N T R Y P O I N T ================================================= */ + +int main() +{ + int error=0; + + error+=handle_basic_test(); + error+=handle_cast_test(); + error+=handle_general_use_test(); + error+=handle_inheritance_test(); + error+=loose_handle_test(); + error+=rhandle_general_use_test(); + + return error; +}