/*
Ousía
Copyright (C) 2014, 2015 Benjamin Paaßen, Andreas Stöckel
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
#include
#include
#include
#include "TestDocument.hpp"
#include "TestDomain.hpp"
namespace ousia {
namespace model {
TEST(Document, testDocumentConstruction)
{
// Construct Manager
Logger logger;
Manager mgr{1};
Rooted sys{new SystemTypesystem(mgr)};
// Get the domain.
Rooted domain = constructBookDomain(mgr, sys, logger);
// Construct the document.
Rooted doc = constructBookDocument(mgr, domain);
// Check the document content.
ASSERT_FALSE(doc.isNull());
// get root node.
Rooted root = doc->getRoot();
ASSERT_FALSE(root.isNull());
ASSERT_EQ("book", root->getDescriptor()->getName());
ASSERT_TRUE(root->hasField());
ASSERT_EQ(2, root->getField().size());
// get foreword (paragraph)
{
Rooted foreword = root->getField()[0];
ASSERT_FALSE(foreword.isNull());
ASSERT_EQ("paragraph", foreword->getDescriptor()->getName());
// it should contain one text node
ASSERT_TRUE(foreword->hasField());
ASSERT_EQ(1, foreword->getField().size());
// which in turn should have a primitive content field containing the
// right text.
{
Rooted text = foreword->getField()[0];
ASSERT_FALSE(text.isNull());
ASSERT_EQ("text", text->getDescriptor()->getName());
ASSERT_TRUE(text->hasField());
ASSERT_EQ(1, text->getField().size());
ASSERT_TRUE(text->getField()[0]->isa(typeOf()));
Variant content =
text->getField()[0].cast()->getContent();
ASSERT_EQ("Some introductory text", content.asString());
}
}
// get section
{
Rooted section = root->getField()[1];
ASSERT_FALSE(section.isNull());
ASSERT_EQ("section", section->getDescriptor()->getName());
// it should contain one paragraph
ASSERT_TRUE(section->hasField());
ASSERT_EQ(1, section->getField().size());
{
Rooted par = section->getField()[0];
ASSERT_FALSE(par.isNull());
ASSERT_EQ("paragraph", par->getDescriptor()->getName());
// it should contain one text node
ASSERT_TRUE(par->hasField());
ASSERT_EQ(1, par->getField().size());
// which in turn should have a primitive content field containing
// the
// right text.
{
Rooted text = par->getField()[0];
ASSERT_FALSE(text.isNull());
ASSERT_EQ("text", text->getDescriptor()->getName());
ASSERT_TRUE(text->hasField());
ASSERT_EQ(1, text->getField().size());
ASSERT_TRUE(
text->getField()[0]->isa(typeOf()));
Variant content =
text->getField()[0].cast()->getContent();
ASSERT_EQ("Some actual text", content.asString());
}
}
}
}
}
}