/*! ========================================================================
** Extended Template and Library Test Suite
** Handle Template Class Test
-** $Id: handle.cpp,v 1.1.1.1 2005/01/04 01:31:48 darco Exp $
+** $Id$
**
** Copyright (c) 2002 Robert B. Quattlebaum Jr.
**
{
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<rhs.my_id;
etl::handle<my_test_obj> obj_handle(new my_test_obj(rand()));
- if(obj_handle != obj_handle.constant())
+ 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;
{
printf("handle: General-use test: ");
my_test_obj::instance_count=0;
-
+
obj_list my_list, my_other_list;
int i;
-
+
for(i=0;i<NUMBER_OF_OBJECTS;i++)
my_list.push_back( obj_handle(new my_test_obj(rand())) );
-
+
my_other_list=my_list;
if(my_test_obj::instance_count!=NUMBER_OF_OBJECTS)
{
printf(__FILE__":%d: On copy, instance count=%d, should be %d.\n",__LINE__,my_test_obj::instance_count,NUMBER_OF_OBJECTS);
return 1;
}
-
+
my_list.clear();
if(my_test_obj::instance_count!=NUMBER_OF_OBJECTS)
{
}
printf("PASSED\n");
-
+
return 0;
}
int rhandle_general_use_test(void)
{
-
-
+
+
printf("rhandle: General-use test: ");
my_test_obj::instance_count=0;
-
+
robj_list my_list;
int i;
-
+
robj_handle obj= new my_test_obj(rand());
for(i=0;i<NUMBER_OF_OBJECTS;i++)
my_list.push_back(obj);
obj_list my_other_list(my_list.begin(),my_list.end());
-
-
-
+
+
+
if(obj.count()!=NUMBER_OF_OBJECTS*2+1)
{
printf("FAILED!\n");
printf(__FILE__":%d: On copy, handle count=%d, should be %d.\n",__LINE__,obj.count(),NUMBER_OF_OBJECTS*2+1);
return 1;
}
-
+
if(obj.rcount()!=NUMBER_OF_OBJECTS+1)
{
printf("FAILED!\n");
printf(__FILE__":%d: On copy, instance count=%d, should be %d.\n",__LINE__,obj.rcount(),NUMBER_OF_OBJECTS+1);
return 1;
}
-
+
my_other_list.clear();
if(obj.rcount()!=obj.count())
robj_handle blah(obj.get());
}
-
+
my_list.clear();
obj.detach();
new_obj.detach();
-
+
if(my_test_obj::instance_count)
{
printf("FAILED!\n");
return 1;
}
-
-
+
+
std::vector<ListItem> my_item_list;
for(i=0;i<NUMBER_OF_OBJECTS;i++)
my_item_list.push_back(ListItem(new my_test_obj(rand()),3,4));
-
+
for(i=0;i<100;i++)
{
int src,dest;
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("PASSED\n");
-
+
return 0;
}
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<NUMBER_OF_OBJECTS;i++)
my_other_list.push_back( other_obj_handle(new my_other_test_obj(rand())) );
-
+
obj_list my_list(my_other_list.begin(),my_other_list.end());
if(my_test_obj::instance_count!=NUMBER_OF_OBJECTS)
{
printf(__FILE__":%d: On sort, instance count=%d, should be %d.\n",__LINE__,my_test_obj::instance_count,NUMBER_OF_OBJECTS*2);
return 1;
}
-
+
my_list.clear();
if(my_test_obj::instance_count!=NUMBER_OF_OBJECTS)
{
}
printf("PASSED\n");
-
+
return 0;
}
etl::handle<my_test_obj> obj;
etl::handle<my_other_test_obj> other_obj;
etl::loose_handle<my_other_test_obj> loose_obj;
-
+
other_obj.spawn();
loose_obj=other_obj;
-
+
obj=etl::handle<my_test_obj>::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;
}
error+=handle_inheritance_test();
error+=loose_handle_test();
error+=rhandle_general_use_test();
-
+
return error;
}