Ejemplo n.º 1
0
TEST(ModelBase, PersistenceSave)
{
	Model model;
	PersistentStoreMock store;

	TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.createRoot("BinaryNode"));

	model.setName("root");
	model.save(&store);

	CHECK_STR_EQUAL("BinaryNode,root,full,Text,name,full,,Integer,_ext_PositionExtension_x,full,0,Integer,_ext_PositionExtension_y,full,0,", store.getSaved());

	model.beginModification(root, "make tree");
	root->setLeft<TestNodes::BinaryNode>();
	root->setRight<TestNodes::BinaryNode>();
	root->name()->set("Troot");
	root->left()->name()->set("Tleft");
	root->right()->name()->set("Tright");
	model.endModification();

	store.clear();
	model.save();

	CHECK_STR_EQUAL("BinaryNode,root,full,Text,name,full,Troot,BinaryNode,left,full,Text,name,full,Tleft,Integer,_ext_PositionExtension_x,full,0,Integer,_ext_PositionExtension_y,full,0,BinaryNode,right,full,Text,name,full,Tright,Integer,_ext_PositionExtension_x,full,0,Integer,_ext_PositionExtension_y,full,0,Integer,_ext_PositionExtension_x,full,0,Integer,_ext_PositionExtension_y,full,0,", store.getSaved());
}
Ejemplo n.º 2
0
TEST(ModelBase, SimpleModelCreation)
{
	Model model;
	CHECK_CONDITION( model.root() == nullptr );

	TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.createRoot("BinaryNode"));
	CHECK_CONDITION( model.root() == root );

	CHECK_CONDITION( root->model() == &model );

	CHECK_CONDITION( root->name()->model() == &model );
}
Ejemplo n.º 3
0
TEST(FilePersistence, SaveMultipleUnits)
{
	QString testDir = QDir::tempPath() + QDir::toNativeSeparators("/Envision/FilePersistence/tests");
	Model::Model model;
	FileStore store;
	store.setBaseFolder(testDir);

	TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.createRoot("BinaryNode"));

	model.beginModification(root, "set title");
	root->name()->set("Root");
	TestNodes::BinaryNode* left = root->setLeft<TestNodes::BinaryNodePersistenceUnit>();
	TestNodes::BinaryNode* right = root->setRight<TestNodes::BinaryNode>();

	left->name()->set("Left child");
	TestNodes::BinaryNode* leftleft = left->setLeft<TestNodes::BinaryNode>();
	leftleft->name()->set("in a new unit");
	right->name()->set("Right child");
	model.endModification();

	model.setName("units");
	model.save(&store);
	CHECK_TEXT_FILES_EQUAL(":/FilePersistence/test/persisted/units/units", testDir + "/units/units");
	CHECK_TEXT_FILES_EQUAL(":/FilePersistence/test/persisted/units/2", testDir + "/units/2");
}
Ejemplo n.º 4
0
TEST(FilePersistence, LoadRootOnly)
{
	QString testDir = ":/FilePersistence/test/persisted";
	Model::Model model;
	FileStore store;
	store.setBaseFolder(testDir);

	model.load(&store, "rootOnly");
	TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.root());

	CHECK_CONDITION(root);
	CHECK_STR_EQUAL("BinaryNode", root->typeName() );
	CHECK_STR_EQUAL("Title", root->name()->get() );
	CHECK_CONDITION(root->left() == nullptr);
	CHECK_CONDITION(root->right() == nullptr);
}
Ejemplo n.º 5
0
TEST(FilePersistence, SaveRootOnly)
{
	QString testDir = QDir::tempPath() + "/Envision/FilePersistence/tests";
	Model::Model model;
	FileStore store;
	store.setBaseFolder(testDir);

	TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.createRoot("BinaryNode"));

	model.beginModification(root->name(), "set title");
	root->name()->set("Title");
	model.endModification();

	model.setName("rootOnly");
	model.save(&store);

	CHECK_TEXT_FILES_EQUAL(":/FilePersistence/test/persisted/rootOnly/rootOnly", testDir + "/rootOnly/rootOnly");
}
Ejemplo n.º 6
0
TEST(VisualizationBase, ExtendableTest)
{
	Model::Model* model = new Model::Model();
	Model::List* list = static_cast<Model::List*> (model->createRoot("List"));

	model->beginModification(list, "set");
	TestNodes::BinaryNode* first = new TestNodes::BinaryNode();
	list->append(first);
	TestNodes::BinaryNode* second = new TestNodes::BinaryNode();
	list->append(second);
	Model::Text* third = new Model::Text();
	list->append(third);

	first->name()->set("First node");
	TestNodes::BinaryNode* left = new TestNodes::BinaryNode();
	first->setLeft(left);
	TestNodes::BinaryNode* right = new TestNodes::BinaryNode();
	first->setRight(right);
	left->name()->set("left node");
	right->name()->set("right node");

	second->name()->set("Empty node");

	third->set("Some independent text");

	list->append(new TestBoxNode("someText"));
	list->append(new TestBoxNode("stretch", true));

	model->endModification();

	auto top = new RootItem(list);
	auto scene = VisualizationManager::instance().mainScene();
	scene->addTopLevelItem( top );
	QApplication::processEvents();

	VList* l = dynamic_cast<VList*> (top->item());
	l->itemAt<VExtendable>(1)->setExpanded(false);
	scene->scheduleUpdate();
	scene->listenToModel(model);

	CHECK_CONDITION(scene);
}
Ejemplo n.º 7
0
TEST(InteractionBase, TextSelect)
{
	Scene* scene = new Scene();

	Model::Model* model = new Model::Model();
	Model::List* list = static_cast<Model::List*> (model->createRoot("List"));

	model->beginModification(list, "set");
	TestNodes::BinaryNode* first = new TestNodes::BinaryNode();
	list->append(first);
	TestNodes::BinaryNode* second = new TestNodes::BinaryNode();
	list->append(second);
	Model::Text* third = new Model::Text();
	list->append(third);

	first->name()->set("First node");
	TestNodes::BinaryNode* left = new TestNodes::BinaryNode();
	first->setLeft(left);
	TestNodes::BinaryNode* right = new TestNodes::BinaryNode();
	first->setRight(right);
	left->name()->set("left node");
	right->name()->set("right node");

	second->name()->set("Empty node");

	third->set("Some independent text");
	model->endModification();

	VList* l = dynamic_cast<VList*> (scene->renderer()->render(nullptr, list));
	scene->addTopLevelItem(l);
	scene->scheduleUpdate();
	QApplication::processEvents();

	l->at<VExtendable>(0)->setExpanded();
	scene->scheduleUpdate();
	scene->listenToModel(model);

	// Create view
	MainView* view = new MainView(scene);
	CHECK_CONDITION(view != nullptr);
}
Ejemplo n.º 8
0
TEST(ModelBase, ProperRegistration)
{
	Model model;
	TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.createRoot("BinaryNode"));
	CHECK_CONDITION(root->typeId() >= 0);

	Model model2;
	Text* t = dynamic_cast<Text*> (model2.createRoot("Text"));
	CHECK_CONDITION(t->typeId() >= 0);
	CHECK_CONDITION(t->typeId() != root->typeId());

	Model model3;
	Integer* i = dynamic_cast<Integer*> (model3.createRoot("Integer"));
	CHECK_CONDITION(i->typeId() >= 0);
	CHECK_CONDITION(i->typeId() != root->typeId());
	CHECK_CONDITION(i->typeId() != t->typeId());

	Model model4;
	Reference* r = dynamic_cast<Reference*> (model4.createRoot("Reference"));
	CHECK_CONDITION(r->typeId() >= 0);
	CHECK_CONDITION(r->typeId() != root->typeId());
	CHECK_CONDITION(r->typeId() != t->typeId());
	CHECK_CONDITION(r->typeId() != i->typeId());
}
Ejemplo n.º 9
0
TEST(ModelBase, ChildNodeRetrieval)
{
	Model model;
	TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.createRoot("BinaryNode"));

	model.beginModification(root, "Making nodes");
	TestNodes::BinaryNode* left = new TestNodes::BinaryNode();
	root->setLeft(left);
	TestNodes::BinaryNode* right = new TestNodes::BinaryNode();
	root->setRight(right);
	model.endModification();

	CHECK_CONDITION(root->hasAttribute("name"));
	CHECK_CONDITION(root->hasAttribute("left"));
	CHECK_CONDITION(root->hasAttribute("right"));

	CHECK_CONDITION(root->hasAttribute("another") == false);

	CHECK_CONDITION(root->get("name") == root->name());
	CHECK_CONDITION(root->get("left") == left);
	CHECK_CONDITION(root->get("right") == right);
}
Ejemplo n.º 10
0
TEST(ModelBase, RemoveOptional)
{
	Model model;
	TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.createRoot("BinaryNode"));

	model.beginModification(root, "Making left node");
	TestNodes::BinaryNode* left = new TestNodes::BinaryNode();
	root->setLeft(left);
	model.endModification();
	CHECK_CONDITION( root->left() == left );
	CHECK_CONDITION( root->left() != nullptr );

	model.beginModification(root, "Removing left node");
	root->removeLeftNode();
	model.endModification();
	CHECK_CONDITION( root->left() == nullptr);

	model.beginModification(root, "Making left node");
	root->setLeft(new TestNodes::BinaryNode());
	model.endModification();
	CHECK_CONDITION( root->left() != left );
	CHECK_CONDITION( root->left() != nullptr );
}
Ejemplo n.º 11
0
TEST(FilePersistence, LoadMultipleUnits)
{
	QString testDir = ":/FilePersistence/test/persisted";
	Model::Model model;
	FileStore store;
	store.setBaseFolder(testDir);

	model.load(&store, "units");
	TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.root());

	CHECK_STR_EQUAL("BinaryNode", root->typeName() );
	CHECK_STR_EQUAL("Root", root->name()->get() );
	CHECK_CONDITION(root->left() != nullptr);
	CHECK_CONDITION(root->right() != nullptr);
	CHECK_STR_EQUAL("BinaryNodePersistenceUnit", root->left()->typeName() );
	CHECK_STR_EQUAL("Left child", root->left()->name()->get() );
	CHECK_CONDITION(root->left()->left() != nullptr);
	CHECK_CONDITION(root->left()->right() == nullptr);
	CHECK_STR_EQUAL("BinaryNode", root->left()->left()->typeName() );
	CHECK_STR_EQUAL("in a new unit", root->left()->left()->name()->get() );
	CHECK_CONDITION(root->left()->left()->left() == nullptr);
	CHECK_CONDITION(root->left()->left()->right() == nullptr);
	CHECK_STR_EQUAL("BinaryNode", root->right()->typeName() );
	CHECK_STR_EQUAL("Right child", root->right()->name()->get() );
	CHECK_CONDITION(root->right()->left() == nullptr);
	CHECK_CONDITION(root->right()->right() == nullptr);
}
Ejemplo n.º 12
0
TEST(ModelBase, ModificationNotificationTests)
{
	Model model;
	NotificationListener nl(model);

	CHECK_CONDITION(nl.root == nullptr);
	CHECK_INT_EQUAL(0, nl.modifiedNodes.size());

	TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.createRoot("BinaryNode"));

	CHECK_CONDITION(root == nl.root);

	model.beginModification(root, "make tree");
	TestNodes::BinaryNode* left = new TestNodes::BinaryNode();
	TestNodes::BinaryNode* right = new TestNodes::BinaryNode();
	root->setLeft(left);
	root->setRight(right);
	model.endModification();

	CHECK_INT_EQUAL(1, nl.modifiedNodes.size());
	CHECK_CONDITION(nl.modifiedNodes[0] == root);

	model.beginModification(left, "modify");
	left->name()->set("Left text");
	model.changeModificationTarget(right);
	right->name()->set("Right text");
	model.endModification();

	CHECK_INT_EQUAL(4, nl.modifiedNodes.size());
	CHECK_CONDITION(nl.modifiedNodes[0] == left);
	CHECK_CONDITION(nl.modifiedNodes[1] == left->name());
	CHECK_CONDITION(nl.modifiedNodes[2] == right);
	CHECK_CONDITION(nl.modifiedNodes[3] == right->name());

	nl.modifiedNodes.clear();
	model.beginModification(nullptr);
	model.undo();
	model.undo();
	model.endModification();

	CHECK_INT_EQUAL(5, nl.modifiedNodes.size());
	CHECK_CONDITION(nl.modifiedNodes[0] == right);
	CHECK_CONDITION(nl.modifiedNodes[1] == right->name());
	CHECK_CONDITION(nl.modifiedNodes[2] == left);
	CHECK_CONDITION(nl.modifiedNodes[3] == left->name());
	CHECK_CONDITION(nl.modifiedNodes[4] == root);
}
Ejemplo n.º 13
0
TEST(ModelBase, SingleWriteUnitCheck)
{
	Model model;

	TestNodes::BinaryNode* root = dynamic_cast<TestNodes::BinaryNode*> (model.createRoot("BinaryNode"));

	model.beginModification(root, "make tree");
	TestNodes::BinaryNode* left = root->setLeft<TestNodes::BinaryNode>();
	TestNodes::BinaryNode* right = root->setRight<TestNodes::BinaryNodeAccessUnit>();
	TestNodes::BinaryNode* one = root->left()->setLeft<TestNodes::BinaryNodeAccessUnit>();
	TestNodes::BinaryNode* two = root->left()->setRight<TestNodes::BinaryNodeAccessUnit>();
	model.endModification();

	CHECK_STR_EQUAL(QString(), root->name()->get());
	CHECK_STR_EQUAL(QString(), left->name()->get());
	CHECK_STR_EQUAL(QString(), right->name()->get());
	CHECK_STR_EQUAL(QString(), one->name()->get());
	CHECK_STR_EQUAL(QString(), two->name()->get());

	model.beginModification(root, "Modify root");

	root->name()->set("This is ok");
	CHECK_STR_EQUAL("This is ok", root->name()->get());

	CHECK_FOR_EXCEPTION(ModelException, one->name()->set("This should fail"));
	CHECK_STR_EQUAL(QString(), one->name()->get());

	model.changeModificationTarget(one);
	CHECK_FOR_EXCEPTION(ModelException, root->name()->set("This should fail"));
	CHECK_STR_EQUAL("This is ok", root->name()->get());

	one->name()->set("one set");
	CHECK_STR_EQUAL("one set", one->name()->get());

	model.endModification();

	model.beginModification(nullptr);
	model.undo();
	model.endModification();

	CHECK_STR_EQUAL(QString(), root->name()->get());
	CHECK_STR_EQUAL(QString(), left->name()->get());
	CHECK_STR_EQUAL(QString(), right->name()->get());
	CHECK_STR_EQUAL(QString(), one->name()->get());
	CHECK_STR_EQUAL(QString(), two->name()->get());

	model.beginModification(nullptr);
	model.redo();
	model.endModification();

	CHECK_STR_EQUAL("This is ok", root->name()->get());
	CHECK_STR_EQUAL(QString(), left->name()->get());
	CHECK_STR_EQUAL(QString(), right->name()->get());
	CHECK_STR_EQUAL("one set", one->name()->get());
	CHECK_STR_EQUAL(QString(), two->name()->get());
}