blob: 585edfdedc86e47394713c80ac1a7e68605cf9b7 [file] [log] [blame]
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "garnet/lib/ui/scenic/tests/scenic_test.h"
namespace scenic_impl {
namespace test {
std::unique_ptr<component::StartupContext> ScenicTest::app_context_;
void ScenicTest::SetUp() {
// TODO(SCN-720): Wrap CreateFromStartupInfo using ::gtest::Environment
// instead of this hack. This code has the chance to break non-ScenicTests.
if (app_context_ == nullptr) {
app_context_ = component::StartupContext::CreateFromStartupInfo();
}
scenic_ =
std::make_unique<Scenic>(app_context_.get(), [this] { QuitLoop(); });
InitializeScenic(scenic_.get());
}
void ScenicTest::TearDown() {
reported_errors_.clear();
events_.clear();
scenic_.reset();
}
void ScenicTest::InitializeScenic(Scenic* scenic) {}
void ScenicTest::ReportError(fxl::LogSeverity severity,
std::string error_string) {
// Typically, we don't want to log expected errors when running the tests.
// However, it is useful to print these errors while writing the tests.
#if 0
switch (severity) {
case ::fxl::LOG_INFO:
FXL_LOG(INFO) << error_string;
break;
case ::fxl::LOG_WARNING:
FXL_LOG(WARNING) << error_string;
break;
case ::fxl::LOG_ERROR:
FXL_LOG(ERROR) << error_string;
break;
case ::fxl::LOG_FATAL:
FXL_LOG(FATAL) << error_string;
break;
}
#endif
reported_errors_.push_back(error_string);
}
void ScenicTest::EnqueueEvent(fuchsia::ui::gfx::Event event) {
fuchsia::ui::scenic::Event scenic_event;
scenic_event.set_gfx(std::move(event));
events_.push_back(std::move(scenic_event));
}
void ScenicTest::EnqueueEvent(fuchsia::ui::input::InputEvent event) {
fuchsia::ui::scenic::Event scenic_event;
scenic_event.set_input(std::move(event));
events_.push_back(std::move(scenic_event));
}
void ScenicTest::EnqueueEvent(fuchsia::ui::scenic::Command event) {
fuchsia::ui::scenic::Event scenic_event;
scenic_event.set_unhandled(std::move(event));
events_.push_back(std::move(scenic_event));
}
} // namespace test
} // namespace scenic_impl