/*****************************************************************************
 * $LastChangedDate: 2011-04-23 21:07:07 -0400 (Sat, 23 Apr 2011) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Test of NULL cases for the shptr0 template class.
 *//*
 * LEGAL:   COPYRIGHT (C) 2004 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

#define TESTING 1
#include "test.hh"
#include "base/module.hh"
using namespace base;
#include "test_shptr.hh"

/*****************************************************************************
 * Test shptr0
 *****************************************************************************/
class Dummy : public Shared
{
};

bool
TestShptr0( void )
{
    CDEBUG << "Testing shptr0...\n";

    shptr0<Dummy> dummyDefaultCtor;  // shptr(void)
    shptr0<Dummy> dummy = NULL;      // shptr(SHARED*)
    shptr0<Dummy> dummy2 = dummy;    // shptr copy ctor

    if ( dummy != NULL ) { Fail(); }
    if ( dummy2 != NULL ) { Fail(); }

    dummy = new Dummy;
    if ( dummy == NULL ) { Fail(); }
    if ( dummy.GetRefCount() != 1 ) { Fail(); }

    dummy = NULL;
    if ( dummy != NULL ) { Fail(); }

  {
    Dummy* pDummy1 = new Dummy;
    Dummy* pDummy2 = new Dummy;
    if ( pDummy1->GetRefCount() || pDummy2->GetRefCount() ) { Fail(); }
    shptr0<Dummy> shptrDummy1;
    shptr0<Dummy> shptrDummy2;
    shptrDummy1 = pDummy2;
    shptrDummy2 = pDummy1;
    if ( pDummy1->GetRefCount() != 1 || pDummy2->GetRefCount() != 1 ) { Fail(); }
  }

    return true;
}

/*****************************************************************************
 * main.
 *****************************************************************************/
int
main( int argc, char** argv )
{
    RUN_TEST( "shptr0", TEST_ERROR_MODE_ABORT,
              TestShptr0() )
}
