Пример #1
0
int main ()
{
  try
  {
    // DefaultImpl
    //
    {
      Impl* a (new Impl);

      postcondition (a->refcount_value () == 1);

      a->remove_ref ();
    }

    // ~DefaultImpl
    //
    {
      Impl* a (new Impl);
      a->remove_ref ();
    }

    // add_ref
    //
    {
      Impl* a (new Impl);

      a->add_ref ();

      postcondition (a->refcount_value () == 2);

      a->remove_ref ();
      a->remove_ref ();
    }


    // remove_ref
    //
    {
      bool destroyed (false);
      Impl* a (new Impl (destroyed));

      a->add_ref ();
      a->remove_ref ();

      postcondition (destroyed == false && a->refcount_value () == 1);

      a->remove_ref ();

      postcondition (destroyed == true);
    }


    // refcount_value
    //
    {
      Impl* a (new Impl);

      postcondition (a->refcount_value () == 1);
    }

    // lock_i
    //
    {
      Impl* a (new Impl);
      a->lock ();
    }
  }
  catch (...)
  {
    return -1;
  }
}
Пример #2
0
int main ()
{
  try
  {
    // SmartPtr ()
    //
    {
      BasePtr a;

      postcondition (a.in () == 0);
    }

    // SmartPtr (Type*)
    //
    {
      Impl* a (new Impl);
      ImplPtr b (a);

      postcondition (b.in () == a && a->refcount_value () == 1);
    }

    // SmartPtr (SmartPtr<Type> const&)
    //
    {
      ImplPtr a (new Impl);
      ImplPtr b (a);

      postcondition (a.in () == b.in () && a->refcount_value () == 2);
    }

    // SmartPtr (SmartPtr<Other> const&)
    //
    {
      ImplPtr a (new Impl);
      BasePtr b (a);

      postcondition (b.in () == static_cast<Base*>(a.in ()) &&
                     b->refcount_value () == 2);
    }

    // ~SmartPtr
    //
    {
      bool destroyed (false);
      {
        ImplPtr a (new Impl (destroyed));
      }

      postcondition (destroyed == true);
    }

    // operator= (Type* ptr)
    //
    {
      Impl* a (new Impl);
      ImplPtr b;
      b = a;

      postcondition (b.in () == a && a->refcount_value () == 1);
    }

    // operator= (SmartPtr<Type> const&)
    //
    {
      ImplPtr a (new Impl);
      ImplPtr b;
      b = a;

      postcondition (b.in () == a.in () && a->refcount_value () == 2);
    }

    // operator= (SmartPtr<Other> const&)
    //
    {
      ImplPtr a (new Impl);
      BasePtr b;
      b = a;

      postcondition (b.in () == static_cast<Base*>(a.in ()) &&
                     b->refcount_value () == 2);
    }

    // operator Type*
    //
    {
      Impl* a (new Impl);
      ImplPtr b (a);
      Impl* c (b);

      postcondition (a == c);
    }

    // operator->
    //
    {
      Impl* a (new Impl);
      ImplPtr b (a);
      Impl* c (b.operator-> ());

      postcondition (a == c);
    }

    // in
    //
    {
      Impl* a (new Impl);
      ImplPtr b (a);
      Impl* c (b.in ());

      postcondition (a == c);
    }

    // retn
    //
    {
      Impl* a (new Impl);
      ImplPtr b (a);
      Impl* c (b.retn ());

      postcondition (a == c);

      b = a; // give ownership back
    }

    // add_ref
    //
    {
      ImplPtr a (new Impl);
      ImplPtr b (add_ref (a));

      postcondition (a.in () == b.in () && b->refcount_value () == 2);
    }

    // smart_cast
    //
    {
      BasePtr a (new Impl);
      ImplPtr b (smart_cast<Impl>(a));

      postcondition (b != 0 && b->refcount_value () == 2);
    }

    // acquire
    //
    {
      bool destroyed (false);
      Base::count_t c (0);
      {
        c = acquire (new Impl (destroyed))->refcount_value ();
      }

      postcondition (c == 1 && destroyed == true);
    }
  }
  catch (...)
  {
    return -1;
  }
}