Esempio n. 1
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());
}
Esempio n. 2
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);
}
Esempio n. 3
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(new TestNodes::BinaryNode());
	root->setRight( new 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());
}
Esempio n. 4
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 );
}
Esempio n. 5
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);
}