X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=ETL%2Ftags%2FETL_0_04_10_rc1%2Ftest%2Fsmart_ptr.cpp;fp=ETL%2Ftags%2FETL_0_04_10_rc1%2Ftest%2Fsmart_ptr.cpp;h=38cbd2f40b7a258c0ea638b306627a79031491c2;hb=e46234d7b452318bb265f47ba85f2a5226f9657a;hp=0000000000000000000000000000000000000000;hpb=cef9c8d1550d556f712d82000680956beed5f2af;p=synfig.git diff --git a/ETL/tags/ETL_0_04_10_rc1/test/smart_ptr.cpp b/ETL/tags/ETL_0_04_10_rc1/test/smart_ptr.cpp new file mode 100644 index 0000000..38cbd2f --- /dev/null +++ b/ETL/tags/ETL_0_04_10_rc1/test/smart_ptr.cpp @@ -0,0 +1,319 @@ +/*! ======================================================================== +** Extended Template and Library Test Suite +** Smart Pointer 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 =========================================================== +** +** ========================================================================= */ + +//#define DEBUGPOINT() fprintf(stderr,__FILE__":%d: DEBUGPOINT\n",__LINE__) +#define DEBUGPOINT() + +/* === H E A D E R S ======================================================= */ + +#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 +{ + 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_smart_ptr; +typedef etl::smart_ptr other_obj_smart_ptr; +typedef list< obj_smart_ptr > obj_list; +typedef list< other_obj_smart_ptr > other_obj_list; + +int smart_ptr_basic_test(void) +{ + printf("smart_ptr: Size of a smart_ptr: %u\n",(unsigned int)sizeof(obj_smart_ptr)); + printf("smart_ptr: Size of a reference_counter: %u\n",(unsigned int)sizeof(etl::reference_counter)); + + + printf("smart_ptr: Basic test: "); + my_test_obj::instance_count=0; + + { + etl::smart_ptr obj_smart_ptr(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; + } + + { + DEBUGPOINT(); + map > my_map; + DEBUGPOINT(); + //etl::smart_ptr obj_smart_ptr(new my_test_obj(rand())); + etl::smart_ptr temp; + temp.spawn(); + DEBUGPOINT(); + temp.reset(); + DEBUGPOINT(); + my_map["bleh"]=temp; + DEBUGPOINT(); + } + + 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::smart_ptr obj_smart_ptr(new my_test_obj(rand())); + + if(obj_smart_ptr != obj_smart_ptr.constant()) + { + printf("FAILED!\n"); + printf(__FILE__":%d: on call to smart_ptr<>::constant().\n",__LINE__); + return 1; + } + + printf("PASSED\n"); + + return 0; +} + +int smart_ptr_general_use_test(void) +{ + printf("smart_ptr: General-use test: "); + my_test_obj::instance_count=0; + + obj_list my_list, my_other_list; + int i; + + for(i=0;i smart_ptr) +{ +} + +int loose_smart_ptr_test(void) +{ + printf("smart_ptr: loose_smart_ptr test: "); + my_test_obj::instance_count=0; + + etl::loose_smart_ptr obj_smart_ptr_loose; + etl::smart_ptr obj_smart_ptr2; + + { + etl::smart_ptr obj_smart_ptr(new my_test_obj(rand())); + if(my_test_obj::instance_count!=1) + { + printf("FAILED!\n"); + printf(__FILE__":%d: on smart_ptr assignment from new object, instance count=%d, should be 1.\n",__LINE__,my_test_obj::instance_count); + return 1; + } + + obj_smart_ptr_loose=obj_smart_ptr; + if(obj_smart_ptr!=obj_smart_ptr_loose) + { + printf("FAILED!\n"); + printf(__FILE__":%d: on loose_smart_ptr assignment\n",__LINE__); + return 1; + } + + obj_smart_ptr2=obj_smart_ptr_loose; + if(my_test_obj::instance_count!=1) + { + printf("FAILED!\n"); + printf(__FILE__":%d: on smart_ptr assignment from loose_smart_ptr, instance count=%d, should be 1.\n",__LINE__,my_test_obj::instance_count); + return 1; + } + + test_func(obj_smart_ptr_loose); + if(my_test_obj::instance_count!=1) + { + printf("FAILED!\n"); + printf(__FILE__":%d: on smart_ptr assignment from loose_smart_ptr, 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; +} + +/* === E N T R Y P O I N T ================================================= */ + +int main() +{ + int error=0; + + error+=smart_ptr_basic_test(); + error+=smart_ptr_general_use_test(); + error+=smart_ptr_inheritance_test(); + error+=loose_smart_ptr_test(); + + return error; +}