Skip to content

Commit

Permalink
added test project
Browse files Browse the repository at this point in the history
  • Loading branch information
ozguronsoy committed Oct 20, 2024
1 parent c8dc782 commit 6a118fc
Show file tree
Hide file tree
Showing 18 changed files with 1,917 additions and 47 deletions.
12 changes: 12 additions & 0 deletions HephAudio.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HephCommon", "HephCommon\He
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ConsoleApplication1", "ConsoleApplication1\ConsoleApplication1.vcxproj", "{BC8D5B66-59C4-43D9-9A46-C08291B8035D}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test\test.vcxproj", "{D483B09F-9D19-4761-BD95-CE4C7BB1FADB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Expand All @@ -25,6 +27,14 @@ Global
{BC8D5B66-59C4-43D9-9A46-C08291B8035D}.Release|x64.Build.0 = Release|x64
{BC8D5B66-59C4-43D9-9A46-C08291B8035D}.Release|x86.ActiveCfg = Release|Win32
{BC8D5B66-59C4-43D9-9A46-C08291B8035D}.Release|x86.Build.0 = Release|Win32
{D483B09F-9D19-4761-BD95-CE4C7BB1FADB}.Debug|x64.ActiveCfg = Debug|x64
{D483B09F-9D19-4761-BD95-CE4C7BB1FADB}.Debug|x64.Build.0 = Debug|x64
{D483B09F-9D19-4761-BD95-CE4C7BB1FADB}.Debug|x86.ActiveCfg = Debug|Win32
{D483B09F-9D19-4761-BD95-CE4C7BB1FADB}.Debug|x86.Build.0 = Debug|Win32
{D483B09F-9D19-4761-BD95-CE4C7BB1FADB}.Release|x64.ActiveCfg = Release|x64
{D483B09F-9D19-4761-BD95-CE4C7BB1FADB}.Release|x64.Build.0 = Release|x64
{D483B09F-9D19-4761-BD95-CE4C7BB1FADB}.Release|x86.ActiveCfg = Release|Win32
{D483B09F-9D19-4761-BD95-CE4C7BB1FADB}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -36,6 +46,8 @@ Global
HephAudio\HephAudio.vcxitems*{bb93f558-91d0-4736-88af-56a3ad9532e9}*SharedItemsImports = 9
HephAudio\HephAudio.vcxitems*{bc8d5b66-59c4-43d9-9a46-c08291b8035d}*SharedItemsImports = 4
HephCommon\HephCommon.vcxitems*{bc8d5b66-59c4-43d9-9a46-c08291b8035d}*SharedItemsImports = 4
HephAudio\HephAudio.vcxitems*{d483b09f-9d19-4761-bd95-ce4c7bb1fadb}*SharedItemsImports = 4
HephCommon\HephCommon.vcxitems*{d483b09f-9d19-4761-bd95-ce4c7bb1fadb}*SharedItemsImports = 4
HephCommon\HephCommon.vcxitems*{de064538-da5c-4e0e-b44c-6a25c86fb48f}*SharedItemsImports = 9
EndGlobalSection
EndGlobal
44 changes: 39 additions & 5 deletions HephCommon/HeaderFiles/Buffers/BufferBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ namespace Heph
*/
virtual Tself operator<<(size_t rhs) const
{
if (rhs >= this->size)
{
Tself result{};
result.pData = BufferBase::Allocate(this->SizeAsByte());
result.size = this->size;
return result;
}

const size_t thisSize_byte = this->SizeAsByte();
const size_t rhsSize_byte = BufferBase::SizeAsByte(rhs);

Expand All @@ -151,11 +159,16 @@ namespace Heph
*/
virtual BufferBase& operator<<=(size_t rhs)
{
if (rhs > 0)
if (rhs >= this->size)
{
this->Reset();
}
else if (rhs > 0)
{
(void)std::memcpy(this->pData, this->pData + rhs, this->SizeAsByte() - BufferBase::SizeAsByte(rhs));
BufferBase::Initialize(this->pData + this->size - rhs, this->pData + this->size);
}

return *this;
}

Expand All @@ -168,6 +181,14 @@ namespace Heph
*/
virtual Tself operator>>(size_t rhs) const
{
if (rhs >= this->size)
{
Tself result{};
result.pData = BufferBase::Allocate(this->SizeAsByte());
result.size = this->size;
return result;
}

const size_t thisSize_byte = this->SizeAsByte();

Tself result{};
Expand All @@ -190,7 +211,11 @@ namespace Heph
*/
virtual BufferBase& operator>>=(size_t rhs)
{
if (rhs > 0)
if (rhs >= this->size)
{
this->Reset();
}
else if (rhs > 0)
{
(void)std::memcpy(this->pData + rhs, this->pData, this->SizeAsByte() - BufferBase::SizeAsByte(rhs));
BufferBase::Initialize(this->pData, this->pData + rhs);
Expand Down Expand Up @@ -391,8 +416,13 @@ namespace Heph
*/
virtual void Replace(const Tself& rhs, size_t index, size_t size)
{
if (size > rhs.size)
{
HEPH_RAISE_AND_THROW_EXCEPTION(this, InvalidArgumentException(HEPH_FUNC, "size cannot be greater than the rhs buffer size"))
}

BufferBase::Replace(this->pData, this->SizeAsByte(), rhs.pData,
rhs.SizeAsByte(), BufferBase::SizeAsByte(index));
BufferBase::SizeAsByte(size), BufferBase::SizeAsByte(index));
}

/**
Expand Down Expand Up @@ -495,7 +525,7 @@ namespace Heph
* @param pDataEnd end of the memory region.
*/
template<typename U = Tdata>
static typename std::enable_if<not std::is_class<U>::value>::type Initialize(U* pData, U* pDataEnd)
static typename std::enable_if<!std::is_class<U>::value>::type Initialize(U* pData, U* pDataEnd)
{
(void)std::memset(pData, 0, ((uint8_t*)pDataEnd) - ((uint8_t*)pData));
}
Expand Down Expand Up @@ -641,6 +671,10 @@ namespace Heph
{
return BufferBase::Append(pThisData, thisSize_byte, pRhsData, rhsSize_byte);
}
else if (index_byte == 0)
{
return BufferBase::Prepend(pThisData, thisSize_byte, pRhsData, rhsSize_byte);
}

Tdata* pResultData = (Tdata*)std::realloc(pThisData, thisSize_byte + rhsSize_byte);
if (pResultData == nullptr)
Expand Down Expand Up @@ -716,7 +750,7 @@ namespace Heph

static void Replace(Tdata* pThisData, size_t thisSize_byte, Tdata* pRhsData, size_t rhsSize_byte, size_t index_byte)
{
if (rhsSize_byte > 0)
if (thisSize_byte > 0 && rhsSize_byte > 0)
{
if (pThisData == nullptr)
{
Expand Down
18 changes: 9 additions & 9 deletions HephCommon/HeaderFiles/Buffers/BufferOperators.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Heph
#pragma region Event
/**
* @brief contains the results of the \link BufferOperatorEvents::OnResultCreated BufferOperatorEvents::OnResultCreated \endlink event.
*
*
*/
template<typename Lhs, typename Rhs>
struct HEPH_API BufferOperatorResultCreatedEventArgs : public EventArgs
Expand All @@ -36,7 +36,7 @@ namespace Heph
#pragma region Addition
/**
* @brief provides + and += operators to the buffer.
*
*
*/
template<class Lhs, typename LhsData, typename Rhs = LhsData, typename RhsData = Rhs>
class HEPH_API BufferAdditionOperator
Expand Down Expand Up @@ -151,7 +151,7 @@ namespace Heph
#pragma region Subtraction
/**
* @brief provides - and -= operators to the buffer.
*
*
*/
template<class Lhs, typename LhsData, typename Rhs = LhsData, typename RhsData = Rhs>
class HEPH_API BufferSubtractionOperator
Expand Down Expand Up @@ -310,7 +310,7 @@ namespace Heph
#pragma region Multiplication
/**
* @brief provides * and *= operators to the buffer.
*
*
*/
template<class Lhs, typename LhsData, typename Rhs = LhsData, typename RhsData = Rhs>
class HEPH_API BufferMultiplicationOperator
Expand Down Expand Up @@ -425,7 +425,7 @@ namespace Heph
#pragma region Division
/**
* @brief provides / and /= operators to the buffer.
*
*
*/
template<class Lhs, typename LhsData, typename Rhs = LhsData, typename RhsData = Rhs>
class HEPH_API BufferDivisionOperator
Expand Down Expand Up @@ -490,7 +490,7 @@ namespace Heph
}

template<typename U = Rhs, typename V = RhsData>
static inline typename std::enable_if<DEFINE_RHS_LHS_OPERATOR and std::is_same<U, V>::value, Lhs>::type ImplRhs(const U& rhs, const Lhs& lhs)
static inline typename std::enable_if<DEFINE_RHS_LHS_OPERATOR&& std::is_same<U, V>::value, Lhs>::type ImplRhs(const U& rhs, const Lhs& lhs)
{
Lhs result{};
BufferOperatorResultCreatedEventArgs<Lhs, Rhs> args(lhs, rhs, result);
Expand Down Expand Up @@ -545,7 +545,7 @@ namespace Heph
}

template<typename U = Rhs, typename V = RhsData>
static inline typename std::enable_if<DEFINE_RHS_LHS_OPERATOR and std::is_base_of<BufferBase<U, V>, U>::value, Lhs>::type ImplRhs(const U& rhs, const Lhs& lhs)
static inline typename std::enable_if<DEFINE_RHS_LHS_OPERATOR&& std::is_base_of<BufferBase<U, V>, U>::value, Lhs>::type ImplRhs(const U& rhs, const Lhs& lhs)
{
if (lhs.Size() != rhs.Size())
{
Expand Down Expand Up @@ -584,7 +584,7 @@ namespace Heph
#pragma region Arithmetic
/**
* @brief provides arithmetic operators to the buffer.
*
*
*/
template<class Lhs, typename LhsData, typename Rhs = LhsData, typename RhsData = Rhs>
class HEPH_API BufferArithmeticOperators :
Expand All @@ -602,7 +602,7 @@ namespace Heph
#pragma region Unary Minus
/**
* @brief provides unary minus operator to the buffer.
*
*
*/
template<class Lhs, typename LhsData>
class HEPH_API BufferUnaryMinusOperator
Expand Down
2 changes: 1 addition & 1 deletion HephCommon/HeaderFiles/Exceptions/Exception.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
#define HEPH_RAISE_AND_THROW_EXCEPTION(pSender, ex) { \
(ex).Raise((const void*)(pSender)); \
throw *Heph::Exception::GetLastException().get(); \
throw (ex); \
}

namespace Heph
Expand Down
15 changes: 13 additions & 2 deletions HephCommon/HeaderFiles/HephShared.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,18 @@ namespace Heph
*/
HEPH_API void ChangeEndian(uint8_t* pData, uint8_t dataSize);

inline constexpr Endian operator!(const Endian& lhs) { return (lhs & Endian::Big) ? Endian::Little : ((lhs == Endian::Little) ? Endian::Big : Endian::Unknown); }
inline constexpr Endian operator!(const Endian& lhs)
{
switch (lhs)
{
case Endian::Little:
return Endian::Big;
case Endian::Big:
return Endian::Little;
default:
return Endian::Unknown;
}
}

/**
* endianness of the current system.
Expand All @@ -180,7 +191,7 @@ namespace Heph
* changes the endianness of the provided data.
*
*/
#define HEPH_CHANGE_ENDIAN(pData, dataSize) Heph::ChangeEndian(pData, dataSize)
#define HEPH_CHANGE_ENDIAN(pData, dataSize) Heph::ChangeEndian((uint8_t*)(pData), dataSize)

enum ConvolutionMode
{
Expand Down
26 changes: 13 additions & 13 deletions HephCommon/HeaderFiles/HephTypeTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,27 @@ namespace Heph
template<class Lhs, class Rhs = Lhs, typename = void>
struct has_addition_assignment_operator : std::false_type {};
template<class Lhs, class Rhs>
struct has_addition_assignment_operator<Lhs, Rhs, typename std::enable_if<std::is_arithmetic<Lhs>::value and std::is_arithmetic<Rhs>::value>::type>
struct has_addition_assignment_operator<Lhs, Rhs, typename std::enable_if<std::is_arithmetic<Lhs>::value&& std::is_arithmetic<Rhs>::value>::type>
: std::true_type {};
template<class Lhs, class Rhs>
struct has_addition_assignment_operator<Lhs, Rhs,
struct has_addition_assignment_operator<Lhs, Rhs,
typename std::enable_if<std::is_same<Lhs&, decltype(std::declval<Lhs>() += std::declval<Rhs>())>::value>::type>
: std::true_type {};

template<class Lhs, class Rhs = Lhs, typename = void>
struct has_subtraction_assignment_operator : std::false_type {};
template<class Lhs, class Rhs>
struct has_subtraction_assignment_operator<Lhs, Rhs, typename std::enable_if<std::is_arithmetic<Lhs>::value and std::is_arithmetic<Rhs>::value>::type>
struct has_subtraction_assignment_operator<Lhs, Rhs, typename std::enable_if<std::is_arithmetic<Lhs>::value&& std::is_arithmetic<Rhs>::value>::type>
: std::true_type {};
template<class Lhs, class Rhs>
struct has_subtraction_assignment_operator<Lhs, Rhs,
struct has_subtraction_assignment_operator<Lhs, Rhs,
typename std::enable_if<std::is_same<Lhs&, decltype(std::declval<Lhs>() -= std::declval<Rhs>())>::value>::type>
: std::true_type {};

template<class Lhs, class Rhs = Lhs, typename = void>
struct has_multiplication_assignment_operator : std::false_type {};
template<class Lhs, class Rhs>
struct has_multiplication_assignment_operator<Lhs, Rhs, typename std::enable_if<std::is_arithmetic<Lhs>::value and std::is_arithmetic<Rhs>::value>::type>
struct has_multiplication_assignment_operator<Lhs, Rhs, typename std::enable_if<std::is_arithmetic<Lhs>::value&& std::is_arithmetic<Rhs>::value>::type>
: std::true_type {};
template<class Lhs, class Rhs>
struct has_multiplication_assignment_operator<Lhs, Rhs,
Expand All @@ -64,7 +64,7 @@ namespace Heph
template<class Lhs, class Rhs = Lhs, typename = void>
struct has_division_assignment_operator : std::false_type {};
template<class Lhs, class Rhs>
struct has_division_assignment_operator<Lhs, Rhs, typename std::enable_if<std::is_arithmetic<Lhs>::value and std::is_arithmetic<Rhs>::value>::type>
struct has_division_assignment_operator<Lhs, Rhs, typename std::enable_if<std::is_arithmetic<Lhs>::value&& std::is_arithmetic<Rhs>::value>::type>
: std::true_type {};
template<class Lhs, class Rhs>
struct has_division_assignment_operator<Lhs, Rhs,
Expand All @@ -76,13 +76,13 @@ namespace Heph
template<class Lhs, class Rhs, class Ret>
struct has_arithmetic_operators<Lhs, Rhs, Ret,
typename std::enable_if<
has_addition_operator<Lhs, Rhs, Ret>::value and
has_subtraction_operator<Lhs, Rhs, Ret>::value and
has_multiplication_operator<Lhs, Rhs, Ret>::value and
has_division_operator<Lhs, Rhs, Ret>::value and
has_addition_assignment_operator<Lhs, Rhs>::value and
has_subtraction_assignment_operator<Lhs, Rhs>::value and
has_multiplication_assignment_operator<Lhs, Rhs>::value and
has_addition_operator<Lhs, Rhs, Ret>::value&&
has_subtraction_operator<Lhs, Rhs, Ret>::value&&
has_multiplication_operator<Lhs, Rhs, Ret>::value&&
has_division_operator<Lhs, Rhs, Ret>::value&&
has_addition_assignment_operator<Lhs, Rhs>::value&&
has_subtraction_assignment_operator<Lhs, Rhs>::value&&
has_multiplication_assignment_operator<Lhs, Rhs>::value&&
has_division_assignment_operator<Lhs, Rhs>::value
>::type> : std::true_type {};
#pragma endregion
Expand Down
Loading

0 comments on commit 6a118fc

Please sign in to comment.