forked from audacity/audacity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow mocking preferences and AudioIO in unit tests
- Loading branch information
Showing
7 changed files
with
285 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
/*!******************************************************************** | ||
Audacity: A Digital Audio Editor | ||
MockedAudio.cpp | ||
Dmitry Vedenko | ||
**********************************************************************/ | ||
#include "MockedAudio.h" | ||
|
||
#include <portaudio.h> | ||
|
||
MockedAudio::MockedAudio() | ||
{ | ||
Pa_Initialize(); | ||
} | ||
|
||
MockedAudio::~MockedAudio() | ||
{ | ||
Pa_Terminate(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
/*!******************************************************************** | ||
Audacity: A Digital Audio Editor | ||
MockedAudio.h | ||
Dmitry Vedenko | ||
**********************************************************************/ | ||
#pragma once | ||
|
||
struct MockedAudio final | ||
{ | ||
MockedAudio(); | ||
~MockedAudio(); | ||
|
||
MockedAudio(const MockedAudio&) = delete; | ||
MockedAudio& operator=(const MockedAudio&) = delete; | ||
MockedAudio(MockedAudio&&) = delete; | ||
MockedAudio& operator=(MockedAudio&&) = delete; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
/*!******************************************************************** | ||
Audacity: A Digital Audio Editor | ||
MockedPrefs.cpp | ||
Dmitry Vedenko | ||
**********************************************************************/ | ||
#include "MockedPrefs.h" | ||
|
||
#include "Prefs.h" | ||
|
||
#include <unordered_map> | ||
|
||
class MockedFileConfig final : public FileConfig | ||
{ | ||
public: | ||
void SetPath(const wxString& path) override | ||
{ | ||
// To make GetPath to work consistently | ||
mPath = path; | ||
} | ||
|
||
const wxString& GetPath() const override | ||
{ | ||
return mPath; | ||
} | ||
|
||
bool GetFirstGroup(wxString& str, long& lIndex) const override | ||
{ | ||
return false; | ||
} | ||
|
||
bool GetNextGroup(wxString& str, long& lIndex) const override | ||
{ | ||
return false; | ||
} | ||
|
||
bool GetFirstEntry(wxString& str, long& lIndex) const override | ||
{ | ||
return false; | ||
} | ||
|
||
bool GetNextEntry(wxString& str, long& lIndex) const override | ||
{ | ||
return false; | ||
} | ||
|
||
size_t GetNumberOfEntries(bool bRecursive = false) const override | ||
{ | ||
return 0; | ||
} | ||
|
||
size_t GetNumberOfGroups(bool bRecursive = false) const override | ||
{ | ||
return 0; | ||
} | ||
|
||
bool HasGroup(const wxString& strName) const override | ||
{ | ||
return true; | ||
} | ||
|
||
bool HasEntry(const wxString& strName) const override | ||
{ | ||
return true; | ||
} | ||
|
||
bool Flush(bool bCurrentOnly = false) override | ||
{ | ||
return false; | ||
} | ||
|
||
bool RenameEntry(const wxString& oldName, const wxString& newName) | ||
override | ||
{ | ||
return false; | ||
} | ||
|
||
bool RenameGroup(const wxString& oldName, const wxString& newName) | ||
override | ||
{ | ||
return false; | ||
} | ||
|
||
bool DeleteEntry(const wxString& key, bool bDeleteGroupIfEmpty = true) | ||
override | ||
{ | ||
return false; | ||
} | ||
|
||
bool DeleteGroup(const wxString& key) override | ||
{ | ||
return false; | ||
} | ||
|
||
bool DeleteAll() override | ||
{ | ||
return false; | ||
} | ||
|
||
bool | ||
DoReadString(const wxString& key, wxString* pStr) const override | ||
{ | ||
auto it = mStringValues.find(key); | ||
|
||
if (it == mStringValues.end()) | ||
return false; | ||
|
||
*pStr = it->second; | ||
return true; | ||
} | ||
|
||
bool DoReadLong(const wxString& key, long* pl) const override | ||
{ | ||
auto it = mLongValues.find(key); | ||
|
||
if (it == mLongValues.end()) | ||
return false; | ||
|
||
*pl = it->second; | ||
return true; | ||
} | ||
|
||
bool DoReadBinary(const wxString& key, wxMemoryBuffer* buf) const | ||
override | ||
{ | ||
auto it = mBinaryValues.find(key); | ||
|
||
if (it == mBinaryValues.end()) | ||
return false; | ||
|
||
*buf = it->second; | ||
return true; | ||
} | ||
|
||
bool DoWriteString(const wxString& key, const wxString& szValue) | ||
override | ||
{ | ||
mStringValues[key] = szValue; | ||
return true; | ||
} | ||
|
||
bool DoWriteLong(const wxString& key, long lValue) override | ||
{ | ||
mLongValues[key] = lValue; | ||
return true; | ||
} | ||
|
||
bool DoWriteBinary(const wxString& key, const wxMemoryBuffer& buf) | ||
override | ||
{ | ||
mBinaryValues[key] = buf; | ||
return true; | ||
} | ||
|
||
void Warn() override | ||
{ | ||
} | ||
|
||
private: | ||
wxString mPath; | ||
|
||
std::unordered_map<wxString, wxString> mStringValues; | ||
std::unordered_map<wxString, long> mLongValues; | ||
std::unordered_map<wxString, wxMemoryBuffer> mBinaryValues; | ||
|
||
}; | ||
|
||
MockedPrefs::MockedPrefs() | ||
: mConfig { std::make_unique<MockedFileConfig>() } | ||
{ | ||
// MockedPrefs destructor will delete this object | ||
gPrefs = mConfig.get(); | ||
} | ||
|
||
MockedPrefs::~MockedPrefs () | ||
{ | ||
gPrefs = nullptr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* SPDX-License-Identifier: GPL-2.0-or-later */ | ||
/*!******************************************************************** | ||
Audacity: A Digital Audio Editor | ||
MockedPrefs.h | ||
Dmitry Vedenko | ||
**********************************************************************/ | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
class MockedFileConfig; | ||
|
||
struct MockedPrefs final | ||
{ | ||
MockedPrefs(); | ||
~MockedPrefs(); | ||
|
||
MockedPrefs(const MockedPrefs&) = delete; | ||
MockedPrefs& operator=(const MockedPrefs&) = delete; | ||
MockedPrefs(MockedPrefs&&) = delete; | ||
MockedPrefs& operator=(MockedPrefs&&) = delete; | ||
|
||
private: | ||
std::unique_ptr<MockedFileConfig> mConfig; | ||
}; |