<commit_before>/*
 * Copyright (c) 2007, <NAME> and IFS Institute for Software at HSR Rapperswil, Switzerland
 * All rights reserved.
 *
 * This library/application is free software; you can redistribute and/or modify it under the terms of
 * the license that is included with this library/application in the file license.txt.
 */

//--- interface include --------------------------------------------------------
#include "MemTrackerTest.h"

//--- test modules used --------------------------------------------------------
#include "TestSuite.h"

//--- module under test --------------------------------------------------------
#include "ITOStorage.h"

//--- standard modules used ----------------------------------------------------
#include "Dbg.h"
#include "MemHeader.h"

//--- c-modules used -----------------------------------------------------------

//---- MemTrackerTest ----------------------------------------------------------------
MemTrackerTest::MemTrackerTest(TString tstrName)
	: TestCaseType(tstrName)
{
	StartTrace(MemTrackerTest.Ctor);
}

MemTrackerTest::~MemTrackerTest()
{
	StartTrace(MemTrackerTest.Dtor);
}

// uncomment if something special needs to be done which isnt already done in base class
//void MemTrackerTest::setUp ()
//{
//	StartTrace(MemTrackerTest.setUp);
//}
//
//void MemTrackerTest::tearDown ()
//{
//	StartTrace(MemTrackerTest.tearDown);
//}

void MemTrackerTest::TrackAllocFreeTest()
{
	StartTrace(MemTrackerTest.TrackAllocFreeTest);
	MemTracker aTracker("AllocFreeTracker");

	void *vp32 = ::calloc(1, (MemoryHeader::AlignedSize() + 16));
	void *vp48 = ::calloc(1, (MemoryHeader::AlignedSize() + 32));

	memset(vp32, 0x55, (MemoryHeader::AlignedSize() + 16));
	memset(vp48, 0xaa, (MemoryHeader::AlignedSize() + 32));

	// use placement new operator to allocate MemoryHeader from
	MemoryHeader *pMH16 = new(vp32) MemoryHeader(16, MemoryHeader::eUsed), *pMH32 = new(vp48) MemoryHeader(32, MemoryHeader::eUsed);

	assertCompare(aTracker.fAllocated, equal_to, 0LL);
	assertCompare(aTracker.fMaxAllocated, equal_to, 0LL);
	assertCompare(aTracker.fNumAllocs, equal_to, 0LL);
	assertCompare(aTracker.fNumFrees, equal_to, 0LL);
	assertCompare(aTracker.fSizeAllocated, equal_to, 0LL);
	assertCompare(aTracker.fSizeFreed, equal_to, 0LL);
//	assertCompare(aTracker.fUsedList.size(), equal_to, (size_t)0); //TRACK_USED_MEMORYBLOCKS
	aTracker.TrackAlloc(pMH16);
	assertCompare(aTracker.fAllocated, equal_to, 16LL);
	assertCompare(aTracker.fMaxAllocated, equal_to, 16LL);
	assertCompare(aTracker.fNumAllocs, equal_to, 1LL);
	assertCompare(aTracker.fNumFrees, equal_to, 0LL);
	assertCompare(aTracker.fSizeAllocated, equal_to, 16LL);
	assertCompare(aTracker.fSizeFreed, equal_to, 0LL);
//	assertCompare(aTracker.fUsedList.size(), equal_to, (size_t)1);	//TRACK_USED_MEMORYBLOCKS
	aTracker.TrackAlloc(pMH32);
	assertCompare(aTracker.fAllocated, equal_to, 48LL);
	assertCompare(aTracker.fMaxAllocated, equal_to, 48LL);
	assertCompare(aTracker.fNumAllocs, equal_to, 2LL);
	assertCompare(aTracker.fNumFrees, equal_to, 0LL);
	assertCompare(aTracker.fSizeAllocated, equal_to, 48LL);
	assertCompare(aTracker.fSizeFreed, equal_to, 0LL);
//	assertCompare(aTracker.fUsedList.size(), equal_to, (size_t)2);	//TRACK_USED_MEMORYBLOCKS
	aTracker.TrackFree(pMH16);
	assertCompare(aTracker.fAllocated, equal_to, 32LL);
	assertCompare(aTracker.fMaxAllocated, equal_to, 48LL);
	assertCompare(aTracker.fNumAllocs, equal_to, 2LL);
	assertCompare(aTracker.fNumFrees, equal_to, 1LL);
	assertCompare(aTracker.fSizeAllocated, equal_to, 48LL);
	assertCompare(aTracker.fSizeFreed, equal_to, 16LL);
//	assertCompare(aTracker.fUsedList.size(), equal_to, (size_t)1);	//TRACK_USED_MEMORYBLOCKS

	aTracker.TrackFree(pMH32);
	assertCompare(aTracker.fAllocated, equal_to, 0LL);
	assertCompare(aTracker.fMaxAllocated, equal_to, 48LL);
	assertCompare(aTracker.fNumAllocs, equal_to, 2LL);
	assertCompare(aTracker.fNumFrees, equal_to, 2LL);
	assertCompare(aTracker.fSizeAllocated, equal_to, 48LL);
	assertCompare(aTracker.fSizeFreed, equal_to, 48LL);
//	assertCompare(aTracker.fUsedList.size(), equal_to, (size_t)0);	//TRACK_USED_MEMORYBLOCKS
}

void MemTrackerTest::XxxTest()
{
	StartTrace(MemTrackerTest.XxxTest);
}

// builds up a suite of testcases, add a line for each testmethod
Test *MemTrackerTest::suite ()
{
	StartTrace(MemTrackerTest.suite);
	TestSuite *testSuite = new TestSuite;
	ADD_CASE(testSuite, MemTrackerTest, TrackAllocFreeTest);
//	ADD_CASE(testSuite, MemTrackerTest, XxxTest);
	return testSuite;
}
<commit_msg>re-enabled tests of excess tracker depending on the TRACE_STORAGE level<commit_after>/*
 * Copyright (c) 2007, <NAME> and IFS Institute for Software at HSR Rapperswil, Switzerland
 * All rights reserved.
 *
 * This library/application is free software; you can redistribute and/or modify it under the terms of
 * the license that is included with this library/application in the file license.txt.
 */

//--- interface include --------------------------------------------------------
#include "MemTrackerTest.h"

//--- test modules used --------------------------------------------------------
#include "TestSuite.h"

//--- module under test --------------------------------------------------------
#include "ITOStorage.h"

//--- standard modules used ----------------------------------------------------
#include "Dbg.h"
#include "MemHeader.h"

//--- c-modules used -----------------------------------------------------------

//---- MemTrackerTest ----------------------------------------------------------------
MemTrackerTest::MemTrackerTest(TString tstrName)
	: TestCaseType(tstrName)
{
	StartTrace(MemTrackerTest.Ctor);
}

MemTrackerTest::~MemTrackerTest()
{
	StartTrace(MemTrackerTest.Dtor);
}

// uncomment if something special needs to be done which isnt already done in base class
//void MemTrackerTest::setUp ()
//{
//	StartTrace(MemTrackerTest.setUp);
//}
//
//void MemTrackerTest::tearDown ()
//{
//	StartTrace(MemTrackerTest.tearDown);
//}

void MemTrackerTest::TrackAllocFreeTest()
{
	StartTrace(MemTrackerTest.TrackAllocFreeTest);
	MemTracker aTracker("AllocFreeTracker");

	void *vp32 = ::calloc(1, (MemoryHeader::AlignedSize() + 16));
	void *vp48 = ::calloc(1, (MemoryHeader::AlignedSize() + 32));

	memset(vp32, 0x55, (MemoryHeader::AlignedSize() + 16));
	memset(vp48, 0xaa, (MemoryHeader::AlignedSize() + 32));

	// use placement new operator to allocate MemoryHeader from
	MemoryHeader *pMH16 = new(vp32) MemoryHeader(16, MemoryHeader::eUsed), *pMH32 = new(vp48) MemoryHeader(32, MemoryHeader::eUsed);

	assertCompare(aTracker.fAllocated, equal_to, 0LL);
	assertCompare(aTracker.fMaxAllocated, equal_to, 0LL);
	assertCompare(aTracker.fNumAllocs, equal_to, 0LL);
	assertCompare(aTracker.fNumFrees, equal_to, 0LL);
	assertCompare(aTracker.fSizeAllocated, equal_to, 0LL);
	assertCompare(aTracker.fSizeFreed, equal_to, 0LL);
	if ( aTracker.fpUsedList ) {
		assertCompare(aTracker.fpUsedList->size(), equal_to, (size_t)0);
	}
	aTracker.TrackAlloc(pMH16);
	assertCompare(aTracker.fAllocated, equal_to, 16LL);
	assertCompare(aTracker.fMaxAllocated, equal_to, 16LL);
	assertCompare(aTracker.fNumAllocs, equal_to, 1LL);
	assertCompare(aTracker.fNumFrees, equal_to, 0LL);
	assertCompare(aTracker.fSizeAllocated, equal_to, 16LL);
	assertCompare(aTracker.fSizeFreed, equal_to, 0LL);
	if ( aTracker.fpUsedList ) {
		assertCompare(aTracker.fpUsedList->size(), equal_to, (size_t)1);
	}
	aTracker.TrackAlloc(pMH32);
	assertCompare(aTracker.fAllocated, equal_to, 48LL);
	assertCompare(aTracker.fMaxAllocated, equal_to, 48LL);
	assertCompare(aTracker.fNumAllocs, equal_to, 2LL);
	assertCompare(aTracker.fNumFrees, equal_to, 0LL);
	assertCompare(aTracker.fSizeAllocated, equal_to, 48LL);
	assertCompare(aTracker.fSizeFreed, equal_to, 0LL);
	if ( aTracker.fpUsedList ) {
		assertCompare(aTracker.fpUsedList->size(), equal_to, (size_t)2);
	}
	aTracker.TrackFree(pMH16);
	assertCompare(aTracker.fAllocated, equal_to, 32LL);
	assertCompare(aTracker.fMaxAllocated, equal_to, 48LL);
	assertCompare(aTracker.fNumAllocs, equal_to, 2LL);
	assertCompare(aTracker.fNumFrees, equal_to, 1LL);
	assertCompare(aTracker.fSizeAllocated, equal_to, 48LL);
	assertCompare(aTracker.fSizeFreed, equal_to, 16LL);
	if ( aTracker.fpUsedList ) {
		assertCompare(aTracker.fpUsedList->size(), equal_to, (size_t)1);
	}

	aTracker.TrackFree(pMH32);
	assertCompare(aTracker.fAllocated, equal_to, 0LL);
	assertCompare(aTracker.fMaxAllocated, equal_to, 48LL);
	assertCompare(aTracker.fNumAllocs, equal_to, 2LL);
	assertCompare(aTracker.fNumFrees, equal_to, 2LL);
	assertCompare(aTracker.fSizeAllocated, equal_to, 48LL);
	assertCompare(aTracker.fSizeFreed, equal_to, 48LL);
	if ( aTracker.fpUsedList ) {
		assertCompare(aTracker.fpUsedList->size(), equal_to, (size_t)0);
	}
}

void MemTrackerTest::XxxTest()
{
	StartTrace(MemTrackerTest.XxxTest);
}

// builds up a suite of testcases, add a line for each testmethod
Test *MemTrackerTest::suite ()
{
	StartTrace(MemTrackerTest.suite);
	TestSuite *testSuite = new TestSuite;
	ADD_CASE(testSuite, MemTrackerTest, TrackAllocFreeTest);
//	ADD_CASE(testSuite, MemTrackerTest, XxxTest);
	return testSuite;
}
{'fraction_non_alphanumeric': 0.19514063697055928, 'fraction_numerical': 0.02057568129583014, 'mean_word_length': 4.018121911037891, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '1676118', 'n_tokens_mistral': 3152, 'n_tokens_neox': 2985, 'n_words': 572}