PowerToys/src/modules/powerrename/unittests/MockPowerRenameRegExEvents.cpp
Mehmet Murat Akburak da22e21a0e
[PowerRename] Fix tests inconsistency, improve test performance (#8129)
* Move retrieveing file attibutes to PowerRenameRegex
Move file attributes unit tests to PowerRenameRegexTests
Add file time field to MockPowerRenameItem

* Add file attributes unittests to PowerRenameManagerTests

* Change variable name

* Rearrange function arguments

* Check if file attributes are used only once

* Change variable name LocalTime -> fileTime, date -> time

* Set fileTime as a member of PowerRenameRegEx rather than passing as an argument

* Change function name isFileAttributesUsed() -> isFileTimeUsed()
Check before resetting fileTime

* Fix small bugs

* Fix typos

* Refactor for readability, move free calls to reachable places

* Fix search for area empty bug
searchTerm being empty is not an invalid argument rather it must return OK without any operation
Tests must check if Replace()  returns S_OK becuase later it checks its result

* Check return values of method calls in PowerRenameManager
Remove received argments checks from some methods because argument being null or empty string doesnt mean it is invalid or method fails

* Fix formatting. Remove overlooked comment. Fix error message.

* Change HRESULT declarations according to coding style

* Fix unhandled case. Refactor.
2020-12-14 10:28:12 +01:00

77 lines
1.7 KiB
C++

#include "pch.h"
#include "MockPowerRenameRegExEvents.h"
IFACEMETHODIMP_(ULONG)
CMockPowerRenameRegExEvents::AddRef()
{
return InterlockedIncrement(&m_refCount);
}
IFACEMETHODIMP_(ULONG)
CMockPowerRenameRegExEvents::Release()
{
long refCount = InterlockedDecrement(&m_refCount);
if (refCount == 0)
{
delete this;
}
return refCount;
}
IFACEMETHODIMP CMockPowerRenameRegExEvents::QueryInterface(_In_ REFIID riid, _Outptr_ void** ppv)
{
static const QITAB qit[] = {
QITABENT(CMockPowerRenameRegExEvents, IPowerRenameRegExEvents),
{ 0 }
};
return QISearch(this, qit, riid, ppv);
}
IFACEMETHODIMP CMockPowerRenameRegExEvents::OnSearchTermChanged(_In_ PCWSTR searchTerm)
{
CoTaskMemFree(m_searchTerm);
m_searchTerm = nullptr;
if (searchTerm != nullptr)
{
SHStrDup(searchTerm, &m_searchTerm);
}
return S_OK;
}
IFACEMETHODIMP CMockPowerRenameRegExEvents::OnReplaceTermChanged(_In_ PCWSTR replaceTerm)
{
CoTaskMemFree(m_replaceTerm);
m_replaceTerm = nullptr;
if (replaceTerm != nullptr)
{
SHStrDup(replaceTerm, &m_replaceTerm);
}
return S_OK;
}
IFACEMETHODIMP CMockPowerRenameRegExEvents::OnFlagsChanged(_In_ DWORD flags)
{
m_flags = flags;
return S_OK;
}
IFACEMETHODIMP CMockPowerRenameRegExEvents::OnFileTimeChanged(_In_ SYSTEMTIME fileTime)
{
m_fileTime = fileTime;
return S_OK;
}
HRESULT CMockPowerRenameRegExEvents::s_CreateInstance(_Outptr_ IPowerRenameRegExEvents** ppsrree)
{
*ppsrree = nullptr;
CMockPowerRenameRegExEvents* psrree = new CMockPowerRenameRegExEvents();
HRESULT hr = E_OUTOFMEMORY;
if (psrree)
{
hr = psrree->QueryInterface(IID_PPV_ARGS(ppsrree));
psrree->Release();
}
return hr;
}