/*
 * Copyright (C) 2020-2021 Aloysius Indrayanto
 *
 * This file is part of the eCxx library, see LICENSE file for the license details.
 */


#include "TestUtility.h"


//
// Test application
//
int main()
{
    _EXECUTECODE_CODESTR_NL1( eCxx::Ext::SharedPtr<eCxx::int32_t> sdv( new eCxx::int32_t(101) ); );
    _CODESTR_NL1_CODERES_NL2( "%zd", (eCxx::ssize_t) *sdv );

    _EXECUTECODE_CODESTR_NL1( eCxx::Ext::SharedPtr<eCxx::int32_t> smv = eCxx::Ext::makeSharedPtr<eCxx::int32_t>(-101); );
    _CODESTR_NL1_CODERES_NL2( "%zd", (eCxx::ssize_t) *smv );

    _EXECUTECODE_CODESTR_NL1( eCxx::Ext::SharedPtr<eCxx::int32_t[]> sda = new eCxx::int32_t[3]; );
    _EXECUTECODE_CODESTR_NL1( sda[0] = 10000; sda[1] = 10001; sda[2] = 10002; );
    _CODESTR_NL1_CODERES_NL1( "%zd", (eCxx::ssize_t) sda[0] );
    _CODESTR_NL1_CODERES_NL1( "%zd", (eCxx::ssize_t) sda[1] );
    _CODESTR_NL1_CODERES_NL2( "%zd", (eCxx::ssize_t) sda[2] );

    _EXECUTECODE_CODESTR_NL1( eCxx::Ext::SharedPtr<eCxx::int32_t[]> sma = eCxx::Ext::makeSharedPtr<eCxx::int32_t, 3>(-10000, -10001, -10002); );
    _CODESTR_NL1_CODERES_NL1( "%zd", (eCxx::ssize_t) sma[0] );
    _CODESTR_NL1_CODERES_NL1( "%zd", (eCxx::ssize_t) sma[1] );
    _CODESTR_NL1_CODERES_NL2( "%zd", (eCxx::ssize_t) sma[2] );

    _DIVIDERLINE_DASHSTR_NL2();



    _EXECUTECODE_CODESTR_NL1( eCxx::Ext::WeakPtr  <eCxx::int32_t> wdv   = sdv; );
    _EXECUTECODE_CODESTR_NL1( eCxx::Ext::SharedPtr<eCxx::int32_t> wdv_s = wdv.lock(); );
    _CODESTR_NL1_CODERES_NL2( "%zd [%p]", (eCxx::ssize_t) *wdv_s, wdv_s.get() );

    _CODESTR_NL1_CODERES_NL1( "%zd", (eCxx::ssize_t) wdv.expired() );
    _EXECUTECODE_CODESTR_NL1( sdv.reset(); );
    _CODESTR_NL1_CODERES_NL1( "%zd", (eCxx::ssize_t) wdv.expired() );
    _EXECUTECODE_CODESTR_NL1( wdv_s.reset(); );
    _CODESTR_NL1_CODERES_NL2( "%zd", (eCxx::ssize_t) wdv.expired() );

    _EXECUTECODE_CODESTR_NL1( wdv_s = wdv.lock(); );
    _CODESTR_NL1_CODERES_NL2( "[%p]", wdv_s.get() );

    _EXECUTECODE_CODESTR_NL2( wdv.reset(); );
    _DIVIDERLINE_DASHSTR_NL2();



    _EXECUTECODE_CODESTR_NL1( wdv = smv; );
    _CODESTR_NL1_CODERES_NL1( "%zd", (eCxx::ssize_t) wdv.expired() );
    _EXECUTECODE_CODESTR_NL1( smv.reset(); );
    _CODESTR_NL1_CODERES_NL2( "%zd", (eCxx::ssize_t) wdv.expired() );

    _EXECUTECODE_CODESTR_NL1( eCxx::Ext::WeakPtr<eCxx::int32_t[]> wda = sda; );
    _CODESTR_NL1_CODERES_NL1( "%zd", (eCxx::ssize_t) wda.expired() );
    _EXECUTECODE_CODESTR_NL1( sda.reset(); );
    _CODESTR_NL1_CODERES_NL2( "%zd", (eCxx::ssize_t) wda.expired() );

    _EXECUTECODE_CODESTR_NL1( wda = sma; );
    _CODESTR_NL1_CODERES_NL1( "%zd", (eCxx::ssize_t) wda.expired() );
    _EXECUTECODE_CODESTR_NL1( sma.reset(); );
    _CODESTR_NL1_CODERES_NL2( "%zd", (eCxx::ssize_t) wda.expired() );

    _DIVIDERLINE_DASHSTR_NL2();



    _EXECUTECODE_CODESTR_NL1( sma = eCxx::Ext::makeSharedPtr<eCxx::int32_t, 3>(-30000, -30001, -30002); );
    _CODESTR_NL1_CODERES_NL1( "%zd", (eCxx::ssize_t) sma[0] );
    _CODESTR_NL1_CODERES_NL1( "%zd", (eCxx::ssize_t) sma[1] );
    _CODESTR_NL1_CODERES_NL2( "%zd", (eCxx::ssize_t) sma[2] );

    _CODESTR_NL1_CODERES_NL2( "%zd", (eCxx::ssize_t) wda.expired() );
    _EXECUTECODE_CODESTR_NL1( wda = sma; );
    _CODESTR_NL1_CODERES_NL2( "%zd", (eCxx::ssize_t) wda.expired() );

    _CODESTR_NL1_CODERES_NL1( "%zd", (eCxx::ssize_t) wda.lock()[0] );
    _CODESTR_NL1_CODERES_NL1( "%zd", (eCxx::ssize_t) wda.lock()[1] );
    _CODESTR_NL1_CODERES_NL2( "%zd", (eCxx::ssize_t) wda.lock()[2] );

    _CODESTR_NL1_CODERES_NL2( "%zd", (eCxx::ssize_t) wda.expired() );
    _EXECUTECODE_CODESTR_NL1( sma.reset(); );
    _CODESTR_NL1_CODERES_NL2( "%zd", (eCxx::ssize_t) wda.expired() );



    return 0;
}
