mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-10 04:50:31 -04:00
refactor: make os_access and file_access settable in test_iolayer
This commit is contained in:
parent
9274f7e461
commit
709c6bb01d
@ -180,12 +180,12 @@ class test_file_access : public file_access {
|
|||||||
class test_iolayer {
|
class test_iolayer {
|
||||||
public:
|
public:
|
||||||
test_iolayer();
|
test_iolayer();
|
||||||
test_iolayer(std::shared_ptr<os_access_mock> os);
|
test_iolayer(std::shared_ptr<os_access const> os);
|
||||||
test_iolayer(std::shared_ptr<os_access_mock> os,
|
test_iolayer(std::shared_ptr<os_access const> os,
|
||||||
std::shared_ptr<file_access const> fa);
|
std::shared_ptr<file_access const> fa);
|
||||||
~test_iolayer();
|
~test_iolayer();
|
||||||
|
|
||||||
iolayer const& get() const;
|
iolayer const& get();
|
||||||
|
|
||||||
std::string out() const;
|
std::string out() const;
|
||||||
std::string err() const;
|
std::string err() const;
|
||||||
@ -194,8 +194,11 @@ class test_iolayer {
|
|||||||
void set_terminal_fancy(bool fancy);
|
void set_terminal_fancy(bool fancy);
|
||||||
void set_terminal_width(size_t width);
|
void set_terminal_width(size_t width);
|
||||||
|
|
||||||
|
void set_os_access(std::shared_ptr<os_access_mock> os);
|
||||||
|
void set_file_access(std::shared_ptr<file_access const> fa);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<os_access_mock> os_;
|
std::shared_ptr<os_access const> os_;
|
||||||
std::shared_ptr<test_terminal> term_;
|
std::shared_ptr<test_terminal> term_;
|
||||||
std::shared_ptr<file_access const> fa_;
|
std::shared_ptr<file_access const> fa_;
|
||||||
std::istringstream in_;
|
std::istringstream in_;
|
||||||
|
@ -202,26 +202,30 @@ std::string test_terminal::colored(std::string text, termcolor color,
|
|||||||
test_iolayer::test_iolayer()
|
test_iolayer::test_iolayer()
|
||||||
: test_iolayer{os_access_mock::create_test_instance()} {}
|
: test_iolayer{os_access_mock::create_test_instance()} {}
|
||||||
|
|
||||||
test_iolayer::test_iolayer(std::shared_ptr<os_access_mock> os)
|
test_iolayer::test_iolayer(std::shared_ptr<os_access const> os)
|
||||||
: test_iolayer{std::move(os), create_file_access_generic()} {}
|
: test_iolayer{std::move(os), create_file_access_generic()} {}
|
||||||
|
|
||||||
test_iolayer::test_iolayer(std::shared_ptr<os_access_mock> os,
|
test_iolayer::test_iolayer(std::shared_ptr<os_access const> os,
|
||||||
std::shared_ptr<file_access const> fa)
|
std::shared_ptr<file_access const> fa)
|
||||||
: os_{std::move(os)}
|
: os_{std::move(os)}
|
||||||
, term_{std::make_shared<test_terminal>(out_, err_)}
|
, term_{std::make_shared<test_terminal>(out_, err_)}
|
||||||
, fa_{std::move(fa)}
|
, fa_{std::move(fa)} {}
|
||||||
, iol_{std::make_unique<iolayer>(iolayer{
|
|
||||||
|
test_iolayer::~test_iolayer() = default;
|
||||||
|
|
||||||
|
iolayer const& test_iolayer::get() {
|
||||||
|
if (!iol_) {
|
||||||
|
iol_ = std::make_unique<iolayer>(iolayer{
|
||||||
.os = os_,
|
.os = os_,
|
||||||
.term = term_,
|
.term = term_,
|
||||||
.file = fa_,
|
.file = fa_,
|
||||||
.in = in_,
|
.in = in_,
|
||||||
.out = out_,
|
.out = out_,
|
||||||
.err = err_,
|
.err = err_,
|
||||||
})} {}
|
});
|
||||||
|
}
|
||||||
test_iolayer::~test_iolayer() = default;
|
return *iol_;
|
||||||
|
}
|
||||||
iolayer const& test_iolayer::get() const { return *iol_; }
|
|
||||||
|
|
||||||
void test_iolayer::set_terminal_fancy(bool fancy) { term_->set_fancy(fancy); }
|
void test_iolayer::set_terminal_fancy(bool fancy) { term_->set_fancy(fancy); }
|
||||||
void test_iolayer::set_terminal_width(size_t width) { term_->set_width(width); }
|
void test_iolayer::set_terminal_width(size_t width) { term_->set_width(width); }
|
||||||
@ -230,4 +234,18 @@ void test_iolayer::set_in(std::string in) { in_.str(std::move(in)); }
|
|||||||
std::string test_iolayer::out() const { return out_.str(); }
|
std::string test_iolayer::out() const { return out_.str(); }
|
||||||
std::string test_iolayer::err() const { return err_.str(); }
|
std::string test_iolayer::err() const { return err_.str(); }
|
||||||
|
|
||||||
|
void test_iolayer::set_os_access(std::shared_ptr<os_access_mock> os) {
|
||||||
|
if (iol_) {
|
||||||
|
throw std::runtime_error("iolayer already created");
|
||||||
|
}
|
||||||
|
os_ = std::move(os);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_iolayer::set_file_access(std::shared_ptr<file_access const> fa) {
|
||||||
|
if (iol_) {
|
||||||
|
throw std::runtime_error("iolayer already created");
|
||||||
|
}
|
||||||
|
fa_ = std::move(fa);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace dwarfs::test
|
} // namespace dwarfs::test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user