tests/test-refcounting.cpp
changeset 18 9b30f80f6e49
parent 11 cfe800908837
     1.1 --- a/tests/test-refcounting.cpp	Sat Aug 31 19:52:41 2013 -0700
     1.2 +++ b/tests/test-refcounting.cpp	Fri Sep 06 13:54:31 2013 -0700
     1.3 @@ -43,6 +43,10 @@
     1.4    }
     1.5  };
     1.6  
     1.7 +class SubCounted : public Counted
     1.8 +{
     1.9 +};
    1.10 +
    1.11  static inline PassRef<Counted>
    1.12  PassThrough(const Ref<Counted> &obj)
    1.13  {
    1.14 @@ -60,22 +64,44 @@
    1.15    bool Run() KE_OVERRIDE
    1.16    {
    1.17      {
    1.18 -      Ref<Counted> obj(Newborn<Counted>(new Counted()));
    1.19 +      Ref<Counted> obj(new Counted());
    1.20      }
    1.21      if (!check(sDtors == 1, "Ref/Newborn counted properly"))
    1.22        return false;
    1.23 +    {
    1.24 +      PassRef<Counted> obj(new Counted());
    1.25 +    }
    1.26 +    if (!check(sDtors == 2, "Ref/Newborn counted properly"))
    1.27 +      return false;
    1.28 +    {
    1.29 +      Counted *counted = new Counted();
    1.30 +      counted->AddRef();
    1.31 +      Ref<Counted> obj(AdoptRef(counted));
    1.32 +    }
    1.33 +    if (!check(sDtors == 3, "Ref/Newborn counted properly"))
    1.34 +      return false;
    1.35 +
    1.36 +    // Check that subclass assignment works.
    1.37 +    {
    1.38 +      Ref<Counted> obj(new SubCounted());
    1.39 +      Ref<Counted> obj2(PassThrough(new SubCounted()));
    1.40 +    }
    1.41 +    if (!check(sDtors == 5, "Ref/Newborn counted properly"))
    1.42 +      return false;
    1.43 +
    1.44 +    sDtors = 0;
    1.45  
    1.46      {
    1.47 -      Ref<Counted> obj(Newborn<Counted>(new Counted()));
    1.48 +      Ref<Counted> obj(new Counted());
    1.49        Ref<Counted> obj2 = PassThrough(obj);
    1.50        Ref<Counted> obj3 = PassThrough(obj);
    1.51 -      if (!check(sDtors == 1, "destructor not called early"))
    1.52 +      if (!check(sDtors == 0, "destructor not called early"))
    1.53          return false;
    1.54        Ref<Counted> obj4 = PassThrough(PassThrough(PassThrough(obj)));
    1.55 -      if (!check(sDtors == 1, "destructor not called early"))
    1.56 +      if (!check(sDtors == 0, "destructor not called early"))
    1.57          return false;
    1.58      }
    1.59 -    if (!check(sDtors == 2, "PassRef/Ref counted properly"))
    1.60 +    if (!check(sDtors == 1, "PassRef/Ref counted properly"))
    1.61        return false;
    1.62  
    1.63      return true;