test/object_mgr/object_mgr_2.cpp
// A very simple test of the handle manager.
A very simple test of the handle manager.
A very simple test of the handle manager .
TEST(ObjectManagerTest, StoreAndRetrieve)
{
  shared_ptr<simple_object> objects[NUM_OBJECTS];
  GEN_HANDLE handles[NUM_OBJECTS];
  unique_ptr<object_manager> om = std::make_unique<object_manager>();
  for (int i = 0; i < NUM_OBJECTS; i++)
  {
    object_data d;
    objects[i] = make_shared<simple_object>();
    ASSERT_EQ(objects[i].use_count(), 1);
    d.object_ptr = dynamic_pointer_cast<IHandledObject>(objects[i]);
    handles[i] = om->store_object(d);
    d.object_ptr = nullptr;
    ASSERT_EQ(objects[i].use_count(), 2);
  }
  for (int i = 0; i < NUM_OBJECTS; i++)
  {
    ASSERT_EQ(objects[i], dynamic_pointer_cast<simple_object >(om->retrieve_object(handles[i])->object_ptr));
  }
  for (int i = 0; i < NUM_OBJECTS; i++)
  {
    om->remove_object(handles[i]);
    ASSERT_EQ(objects[i].use_count(), 1);
  }
}
TEST ( ObjectManagerTest , StoreAndRetrieve ) { shared_ptr < simple_object > objects [ NUM_OBJECTS ] ; GEN_HANDLE handles [ NUM_OBJECTS ] ; unique_ptr < object_manager > om = std :: make_unique < object_manager > ( ) ; for ( int i = 0 ; i < NUM_OBJECTS ; i ++ ) { object_data d ; objects [ i ] = make_shared < simple_object > ( ) ; ASSERT_EQ ( objects [ i ] . use_count ( ) , 1 ) ; d . object_ptr = dynamic_pointer_cast < IHandledObject > ( objects [ i ] ) ; handles [ i ] = om -> store_object ( d ) ; d . object_ptr = nullptr ; ASSERT_EQ ( objects [ i ] . use_count ( ) , 2 ) ; } for ( int i = 0 ; i < NUM_OBJECTS ; i ++ ) { ASSERT_EQ ( objects [ i ] , dynamic_pointer_cast < simple_object > ( om -> retrieve_object ( handles [ i ] ) -> object_ptr ) ) ; } for ( int i = 0 ; i < NUM_OBJECTS ; i ++ ) { om -> remove_object ( handles [ i ] ) ; ASSERT_EQ ( objects [ i ] . use_count ( ) , 1 ) ; } }
A very simple test of the handle manager.
A very simple test of the handle manager .