(new char[length + 1]);
const size_t read_length = file->Read(buf.get(), length, handle);
file->Close(handle);
RMLUI_ASSERT(read_length > 0);
RMLUI_ASSERT(read_length <= length);
buf[read_length] = '\0';
return String(buf.get());
}
void TestViewer::ShowSource(SourceType type)
{
if (type == SourceType::None)
{
document_source->Hide();
}
else
{
const String& source_string = (type == SourceType::Test ? source_test : source_reference);
if (source_string.empty())
{
document_source->Hide();
}
else
{
const String rml_source = StringUtilities::EncodeRml(source_string);
Element* element = document_source->GetElementById("code");
RMLUI_ASSERT(element);
element->SetInnerRML(rml_source);
document_source->Show();
}
}
}
bool TestViewer::LoadTest(const Rml::String& directory, const Rml::String& filename, int test_index, int number_of_tests, int suite_index, int number_of_suites)
{
if (document_test)
{
document_test->Close();
document_test = nullptr;
}
if (document_reference)
{
document_reference->Close();
document_reference = nullptr;
}
reference_filename.clear();
source_test.clear();
source_reference.clear();
meta_handler->ClearMetaList();
link_handler->ClearLinkList();
Element* description_test_suite = document_description->GetElementById("test_suite");
RMLUI_ASSERT(description_test_suite);
description_test_suite->SetInnerRML(CreateString(64, "Test suite %d of %d", suite_index + 1, number_of_suites));
SetGoToText("");
source_test = LoadFile(directory + '/' + filename);
if (source_test.empty())
return false;
document_test = context->LoadDocumentFromMemory(source_test);
if (!document_test)
return false;
document_test->Show();
for (const LinkItem& item : link_handler->GetLinkList())
{
if (item.rel == "match")
{
reference_filename = item.href;
break;
}
}
if (!reference_filename.empty())
{
source_reference = LoadFile(directory + '/' + reference_filename);
if (!source_reference.empty())
{
document_reference = context->LoadDocumentFromMemory(source_reference);
if (document_reference)
{
document_reference->SetProperty(PropertyId::Left, Property(510.f, Property::PX));
document_reference->Show();
}
}
}
String rml_description = Rml::CreateString(512, "%s
Test %d of %d.
%s", document_test->GetTitle().c_str(), test_index + 1, number_of_tests, filename.c_str());
if (!reference_filename.empty())
{
if (document_reference)
rml_description += "
" + reference_filename;
else
rml_description += "
(X " + reference_filename + ")";
}
rml_description += "
";
const LinkList& link_list = link_handler->GetLinkList();
if(!link_list.empty())
{
rml_description += "";
for (const LinkItem& item : link_list)
{
if (item.rel == "match")
continue;
rml_description += "" + item.rel + " ";
}
rml_description += "
";
}
for (const MetaItem& item : meta_handler->GetMetaList())
{
rml_description += "" + item.name + "
";
rml_description += "" + item.content + "
";
}
Element* description_content = document_description->GetElementById("content");
RMLUI_ASSERT(description_content);
description_content->SetInnerRML(rml_description);
return true;
}
void TestViewer::SetGoToText(const Rml::String& rml)
{
Element* description_goto = document_description->GetElementById("goto");
RMLUI_ASSERT(description_goto);
description_goto->SetInnerRML(rml);
}
const Rml::String& TestViewer::GetReferenceFilename()
{
return reference_filename;
}