move test::EnvFixture to core library from iface
This commit is contained in:
parent
bd1373e415
commit
5750fff6a4
@ -55,6 +55,7 @@ target_sources(nf7_core_test
|
||||
uv/file_test.cc
|
||||
uv/parallelism_test.cc
|
||||
clock_test.cc
|
||||
env_test.hh
|
||||
meta_env_test.cc
|
||||
)
|
||||
target_link_libraries(nf7_core_test
|
||||
|
@ -18,8 +18,10 @@
|
||||
#include "iface/subsys/concurrency.hh"
|
||||
#include "iface/subsys/parallelism.hh"
|
||||
|
||||
#include "core/clock.hh"
|
||||
|
||||
namespace nf7::test {
|
||||
|
||||
namespace nf7::core::test {
|
||||
|
||||
class EnvFixture : public ::testing::Test {
|
||||
public:
|
||||
@ -93,7 +95,7 @@ class EnvFixtureWithTasking : public EnvFixture {
|
||||
explicit SyncDriver(EnvFixtureWithTasking& parent) noexcept
|
||||
: parent_(parent) { }
|
||||
|
||||
void BeginBusy() noexcept { }
|
||||
void BeginBusy() noexcept { parent_.clock_->Tick(); }
|
||||
void EndBusy() noexcept { }
|
||||
void Drive(SyncTask&& task) noexcept {
|
||||
try {
|
||||
@ -106,8 +108,7 @@ class EnvFixtureWithTasking : public EnvFixture {
|
||||
}
|
||||
}
|
||||
SyncTask::Time tick() const noexcept {
|
||||
const auto now = std::chrono::system_clock::now();
|
||||
return std::chrono::time_point_cast<SyncTask::Time::duration>(now);
|
||||
return parent_.clock_->now();
|
||||
}
|
||||
bool nextIdleInterruption() const noexcept {
|
||||
return 0 == parent_.sq_->size();
|
||||
@ -122,9 +123,11 @@ class EnvFixtureWithTasking : public EnvFixture {
|
||||
public:
|
||||
explicit EnvFixtureWithTasking(SimpleEnv::FactoryMap&& fmap = {})
|
||||
: EnvFixture(std::move(fmap)),
|
||||
clock_(std::make_shared<Clock>()),
|
||||
sq_(std::make_shared<SimpleTaskQueue<SyncTask>>()),
|
||||
aq_(std::make_shared<SimpleTaskQueue<AsyncTask>>()),
|
||||
ad_(*this) {
|
||||
Install<subsys::Clock>(clock_);
|
||||
Install<subsys::Concurrency>(
|
||||
std::make_shared<WrappedTaskQueue<subsys::Concurrency>>(sq_));
|
||||
Install<subsys::Parallelism>(
|
||||
@ -166,6 +169,7 @@ class EnvFixtureWithTasking : public EnvFixture {
|
||||
}
|
||||
|
||||
private:
|
||||
std::shared_ptr<Clock> clock_;
|
||||
std::shared_ptr<SimpleTaskQueue<SyncTask>> sq_;
|
||||
std::shared_ptr<SimpleTaskQueue<AsyncTask>> aq_;
|
||||
|
||||
@ -174,4 +178,4 @@ class EnvFixtureWithTasking : public EnvFixture {
|
||||
AsyncDriver ad_;
|
||||
};
|
||||
|
||||
} // namespace nf7::test
|
||||
} // namespace nf7::core::test
|
@ -7,13 +7,13 @@
|
||||
|
||||
#include "iface/subsys/concurrency.hh"
|
||||
|
||||
#include "iface/env_test.hh"
|
||||
#include "core/env_test.hh"
|
||||
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
|
||||
class Gl3Context : public nf7::test::EnvFixtureWithTasking {
|
||||
class Gl3Context : public nf7::core::test::EnvFixtureWithTasking {
|
||||
public:
|
||||
Gl3Context() noexcept : skip_(nullptr == std::getenv("NF7_TEST_GL3")) { }
|
||||
|
||||
@ -22,12 +22,12 @@ class Gl3Context : public nf7::test::EnvFixtureWithTasking {
|
||||
if (skip_) {
|
||||
GTEST_SKIP();
|
||||
} else {
|
||||
nf7::test::EnvFixtureWithTasking::SetUp();
|
||||
nf7::core::test::EnvFixtureWithTasking::SetUp();
|
||||
}
|
||||
}
|
||||
void TearDown() override {
|
||||
if (!skip_) {
|
||||
nf7::test::EnvFixtureWithTasking::TearDown();
|
||||
nf7::core::test::EnvFixtureWithTasking::TearDown();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,12 +18,12 @@
|
||||
#include "iface/subsys/parallelism.hh"
|
||||
#include "iface/env.hh"
|
||||
|
||||
#include "iface/env_test.hh"
|
||||
#include "core/env_test.hh"
|
||||
|
||||
namespace nf7::core::luajit::test {
|
||||
|
||||
class ContextFixture :
|
||||
public nf7::test::EnvFixtureWithTasking,
|
||||
public nf7::core::test::EnvFixtureWithTasking,
|
||||
public ::testing::WithParamInterface<Context::Kind> {
|
||||
public:
|
||||
ContextFixture() noexcept
|
||||
|
@ -173,13 +173,6 @@ TEST_P(LuaJIT_Lambda, CtxSleep) {
|
||||
EXPECT_GE(end-begin, 100ms);
|
||||
}
|
||||
|
||||
TEST_P(LuaJIT_Lambda, CtxSleepWithoutClock) {
|
||||
Expect(
|
||||
"local ctx = ...\nctx:sleep(100)",
|
||||
{nf7::Value {}},
|
||||
0, 1);
|
||||
}
|
||||
|
||||
TEST_P(LuaJIT_Lambda, CtxLogging) {
|
||||
const auto logger = std::make_shared<nf7::subsys::test::LoggerMock>();
|
||||
|
||||
|
@ -8,15 +8,15 @@
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
|
||||
#include "iface/env_test.hh"
|
||||
#include "core/env_test.hh"
|
||||
|
||||
|
||||
namespace nf7::core::sqlite::test {
|
||||
|
||||
class DatabaseFixture : public nf7::test::EnvFixtureWithTasking {
|
||||
class DatabaseFixture : public nf7::core::test::EnvFixtureWithTasking {
|
||||
public:
|
||||
DatabaseFixture()
|
||||
: nf7::test::EnvFixtureWithTasking({
|
||||
: nf7::core::test::EnvFixtureWithTasking({
|
||||
{typeid(nf7::subsys::Database), [](auto& env) {
|
||||
return std::make_shared<Database>(env, ":memory:");
|
||||
}},
|
||||
|
@ -13,15 +13,15 @@
|
||||
|
||||
#include "core/uv/clock.hh"
|
||||
|
||||
#include "iface/env_test.hh"
|
||||
#include "core/env_test.hh"
|
||||
|
||||
|
||||
namespace nf7::core::uv::test {
|
||||
|
||||
class ContextFixture : public nf7::test::EnvFixture {
|
||||
class ContextFixture : public nf7::core::test::EnvFixture {
|
||||
public:
|
||||
ContextFixture() noexcept
|
||||
: nf7::test::EnvFixture({
|
||||
: nf7::core::test::EnvFixture({
|
||||
SimpleEnv::MakePair<Context, MainContext>(),
|
||||
SimpleEnv::MakePair<subsys::Clock, Clock>(),
|
||||
}) {
|
||||
@ -29,12 +29,12 @@ class ContextFixture : public nf7::test::EnvFixture {
|
||||
|
||||
protected:
|
||||
void SetUp() override {
|
||||
nf7::test::EnvFixture::SetUp();
|
||||
nf7::core::test::EnvFixture::SetUp();
|
||||
ctx_ = std::dynamic_pointer_cast<MainContext>(env().Get<Context>());
|
||||
}
|
||||
void TearDown() override {
|
||||
ctx_->RunAndClose();
|
||||
nf7::test::EnvFixture::TearDown();
|
||||
nf7::core::test::EnvFixture::TearDown();
|
||||
ctx_ = nullptr;
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,6 @@ target_sources(nf7_iface_test
|
||||
common/task_test.hh
|
||||
common/value_test.cc
|
||||
subsys/logger_test.hh
|
||||
env_test.hh
|
||||
)
|
||||
target_link_libraries(nf7_iface_test
|
||||
PRIVATE
|
||||
|
Loading…
x
Reference in New Issue
Block a user