<commit_before>/*
 * Copyright(c) Sophist Solutions Inc. 1990-2011.  All rights reserved
 */
#include	"Stroika/Foundation/StroikaPreComp.h"

#include	"Stroika/Foundation/Debug/Assertions.h"
#include	"Stroika/Foundation/Debug/Trace.h"
#include	"Stroika/Foundation/Memory/SharedPtr.h"
#include	"Stroika/Foundation/Memory/WeakSharedPtr.h"

#include	"../TestHarness/SimpleClass.h"
#include	"../TestHarness/TestHarness.h"





using	namespace	Stroika;
using	namespace	Stroika::Foundation;
using	namespace	Stroika::Foundation::Memory;




namespace	{
	void	Test1 ()
		{
			struct	T1 {
				string x;
			};
			struct	T2 : T1 {
			};
			SharedPtr<T1>	t1 (new T1 ());
			VerifyTestResult (t1.IsUnique ());
			VerifyTestResult (t1.CurrentRefCount () == 1);
			SharedPtr<T2>	t2 (new T2 ());
			VerifyTestResult (t2.IsUnique ());
			VerifyTestResult (t2.CurrentRefCount () == 1);
			VerifyTestResult (t1 != t2);
			t1 = t2;
			VerifyTestResult (not t1.IsUnique ());
			VerifyTestResult (t1.CurrentRefCount () == 2);
			VerifyTestResult (not t2.IsUnique ());
			VerifyTestResult (t2.CurrentRefCount () == 2);
			VerifyTestResult (t1 == t2);
		}
	void	Test2_SharedFromThis ()
		{
			struct	TTT : Memory::enable_shared_from_this<TTT> {
				string x;
			};
			typedef	SharedPtr<TTT,SharedPtrFromThis_Traits<TTT>>	TTT_SP;

			TTT_SP	t1 (new TTT ());
			TTT_SP	t2 (new TTT ());
			t1 = t2;
			VerifyTestResult (t1.CurrentRefCount () == 2);
			TTT_SP	t3 (t1.get ());
			VerifyTestResult (t1.CurrentRefCount () == 3);
			TTT_SP	t4	=	t1.get()->shared_from_this ();
			VerifyTestResult (t1.CurrentRefCount () == 4);
		}
	void	Test3_WeakPtrs ()
		{
            {
			    WeakCapableSharedPtr<int>	t1 (new int ());
			    WeakSharedPtr<int>			wt1 (t1);
			    VerifyTestResult (wt1.Lock ().get () == t1.get ());
            }
            for (int i = 0; i < 1000; ++i) {
			    WeakSharedPtr<int>			wt1;
                {
			        WeakCapableSharedPtr<int>	t1 (new int ());
                    VerifyTestResult (t1.use_count () == 1);
                    wt1 = WeakSharedPtr<int> (t1);
                    VerifyTestResult (t1.use_count () == 1);
			        VerifyTestResult (wt1.Lock ().get () == t1.get ());
                    VerifyTestResult (t1.use_count () == 1);
                }
                VerifyTestResult (wt1.Lock ().get () == nullptr);
            }
		}
	void	Test4_WeakPtrsWithSharedWithThis ()
		{
            {
			    struct	TTT : Memory::enable_shared_from_this<TTT> {
				    string x;
			    };
			    //typedef	WeakCapableSharedPtr<TTT,SharedPtrFromThis_Traits<TTT>>	TTT_SP;
                typedef SharedPtr<TTT,WeakSharedPtrCapableSharedPtrTraits<SharedPtrFromThis_Traits<TTT>>> TTT_SP;
#if 0
			    TTT_SP	t1 (new TTT ());
			    WeakSharedPtr<TTT>			wt1 (t1);
			    VerifyTestResult (wt1.Lock ().get () == t1.get ());
#endif
            }
		}
}


namespace	{

	void	DoRegressionTests_ ()
		{
		    Test1 ();
			Test2_SharedFromThis ();
			Test3_WeakPtrs ();
            Test4_WeakPtrsWithSharedWithThis ();
		}
}



int main (int argc, const char* argv[])
{
	Stroika::TestHarness::Setup ();
	Stroika::TestHarness::PrintPassOrFail (DoRegressionTests_);
	return EXIT_SUCCESS;
}


<commit_msg>Slight progress on regression test for combining WeakSharedPtr<> with SharedFromThis<commit_after>/*
 * Copyright(c) Sophist Solutions Inc. 1990-2011.  All rights reserved
 */
#include	"Stroika/Foundation/StroikaPreComp.h"

#include	"Stroika/Foundation/Debug/Assertions.h"
#include	"Stroika/Foundation/Debug/Trace.h"
#include	"Stroika/Foundation/Memory/SharedPtr.h"
#include	"Stroika/Foundation/Memory/WeakSharedPtr.h"

#include	"../TestHarness/SimpleClass.h"
#include	"../TestHarness/TestHarness.h"





using	namespace	Stroika;
using	namespace	Stroika::Foundation;
using	namespace	Stroika::Foundation::Memory;




namespace	{
	void	Test1 ()
		{
			struct	T1 {
				string x;
			};
			struct	T2 : T1 {
			};
			SharedPtr<T1>	t1 (new T1 ());
			VerifyTestResult (t1.IsUnique ());
			VerifyTestResult (t1.CurrentRefCount () == 1);
			SharedPtr<T2>	t2 (new T2 ());
			VerifyTestResult (t2.IsUnique ());
			VerifyTestResult (t2.CurrentRefCount () == 1);
			VerifyTestResult (t1 != t2);
			t1 = t2;
			VerifyTestResult (not t1.IsUnique ());
			VerifyTestResult (t1.CurrentRefCount () == 2);
			VerifyTestResult (not t2.IsUnique ());
			VerifyTestResult (t2.CurrentRefCount () == 2);
			VerifyTestResult (t1 == t2);
		}
	void	Test2_SharedFromThis ()
		{
			struct	TTT : Memory::enable_shared_from_this<TTT> {
				string x;
			};
			typedef	SharedPtr<TTT,SharedPtrFromThis_Traits<TTT>>	TTT_SP;

			TTT_SP	t1 (new TTT ());
			TTT_SP	t2 (new TTT ());
			t1 = t2;
			VerifyTestResult (t1.CurrentRefCount () == 2);
			TTT_SP	t3 (t1.get ());
			VerifyTestResult (t1.CurrentRefCount () == 3);
			TTT_SP	t4	=	t1.get()->shared_from_this ();
			VerifyTestResult (t1.CurrentRefCount () == 4);
		}
	void	Test3_WeakPtrs ()
		{
            {
			    WeakCapableSharedPtr<int>	t1 (new int ());
			    WeakSharedPtr<int>			wt1 (t1);
			    VerifyTestResult (wt1.Lock ().get () == t1.get ());
            }
            for (int i = 0; i < 1000; ++i) {
			    WeakSharedPtr<int>			wt1;
                {
			        WeakCapableSharedPtr<int>	t1 (new int ());
                    VerifyTestResult (t1.use_count () == 1);
                    wt1 = WeakSharedPtr<int> (t1);
                    VerifyTestResult (t1.use_count () == 1);
			        VerifyTestResult (wt1.Lock ().get () == t1.get ());
                    VerifyTestResult (t1.use_count () == 1);
                }
                VerifyTestResult (wt1.Lock ().get () == nullptr);
            }
		}
	void	Test4_WeakPtrsWithSharedWithThis ()
		{
            {
			    struct	TTT : Memory::enable_shared_from_this<TTT> {
				    string x;
			    };

#if 0
			    typedef	WeakCapableSharedPtr<TTT,SharedPtrFromThis_Traits<TTT>>	TTT_SP;
#else
                typedef SharedPtr<TTT,WeakSharedPtrCapableSharedPtrTraits<TTT, SharedPtrFromThis_Traits<TTT>>> TTT_SP;
#endif
			    TTT_SP	t1 (new TTT ());
#if 0
			    WeakSharedPtr<TTT>			wt1 (t1);
			    VerifyTestResult (wt1.Lock ().get () == t1.get ());
#endif
            }
		}
}


namespace	{

	void	DoRegressionTests_ ()
		{
		    Test1 ();
			Test2_SharedFromThis ();
			Test3_WeakPtrs ();
            Test4_WeakPtrsWithSharedWithThis ();
		}
}



int main (int argc, const char* argv[])
{
	Stroika::TestHarness::Setup ();
	Stroika::TestHarness::PrintPassOrFail (DoRegressionTests_);
	return EXIT_SUCCESS;
}



{'fraction_non_alphanumeric': 0.1377928483353884, 'fraction_numerical': 0.026664611590628853, 'mean_word_length': 2.746535796766744, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '299003', 'n_tokens_mistral': 2704, 'n_tokens_neox': 2367, 'n_words': 428}