2015-08-16 22:29:54 +00:00
|
|
|
#include "BaseTestCase.h"
|
|
|
|
|
|
|
|
#include "DiffManager.h"
|
|
|
|
#include "DefinitionNode.h"
|
|
|
|
#include "FloatNode.h"
|
|
|
|
|
2015-08-17 16:18:31 +00:00
|
|
|
TEST(DiffManager, undoRedo)
|
2015-08-16 22:29:54 +00:00
|
|
|
{
|
|
|
|
DefinitionNode root(NULL, "root");
|
|
|
|
DiffManager *diffs = root.getDiffManager();
|
|
|
|
|
2015-08-17 16:18:31 +00:00
|
|
|
FloatNode leaf(&root, "value", 2.6);
|
2015-08-16 22:29:54 +00:00
|
|
|
EXPECT_DOUBLE_EQ(2.6, leaf.getValue());
|
|
|
|
|
|
|
|
leaf.setValue(4.3);
|
|
|
|
EXPECT_DOUBLE_EQ(4.3, leaf.getValue());
|
|
|
|
|
|
|
|
leaf.setValue(-2.1);
|
|
|
|
EXPECT_DOUBLE_EQ(-2.1, leaf.getValue());
|
|
|
|
|
|
|
|
diffs->undo();
|
|
|
|
EXPECT_DOUBLE_EQ(4.3, leaf.getValue());
|
|
|
|
|
|
|
|
diffs->undo();
|
|
|
|
EXPECT_DOUBLE_EQ(2.6, leaf.getValue());
|
|
|
|
|
|
|
|
diffs->redo();
|
|
|
|
EXPECT_DOUBLE_EQ(4.3, leaf.getValue());
|
|
|
|
|
|
|
|
diffs->redo();
|
|
|
|
EXPECT_DOUBLE_EQ(-2.1, leaf.getValue());
|
|
|
|
}
|
2015-08-17 16:18:31 +00:00
|
|
|
|
|
|
|
TEST(DiffManager, undoTooMuch)
|
|
|
|
{
|
|
|
|
DefinitionNode root(NULL, "root");
|
|
|
|
DiffManager *diffs = root.getDiffManager();
|
|
|
|
|
|
|
|
FloatNode leaf(&root, "value", 1.1);
|
|
|
|
EXPECT_DOUBLE_EQ(1.1, leaf.getValue());
|
|
|
|
|
|
|
|
leaf.setValue(2.2);
|
|
|
|
EXPECT_DOUBLE_EQ(2.2, leaf.getValue());
|
|
|
|
|
|
|
|
diffs->undo();
|
|
|
|
EXPECT_DOUBLE_EQ(1.1, leaf.getValue());
|
|
|
|
|
|
|
|
diffs->undo();
|
|
|
|
EXPECT_DOUBLE_EQ(1.1, leaf.getValue());
|
|
|
|
|
|
|
|
diffs->redo();
|
|
|
|
EXPECT_DOUBLE_EQ(2.2, leaf.getValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DiffManager, redoTooMuch)
|
|
|
|
{
|
|
|
|
DefinitionNode root(NULL, "root");
|
|
|
|
DiffManager *diffs = root.getDiffManager();
|
|
|
|
|
|
|
|
FloatNode leaf(&root, "value", 1.1);
|
|
|
|
EXPECT_DOUBLE_EQ(1.1, leaf.getValue());
|
|
|
|
|
|
|
|
leaf.setValue(2.2);
|
|
|
|
EXPECT_DOUBLE_EQ(2.2, leaf.getValue());
|
|
|
|
|
|
|
|
diffs->undo();
|
|
|
|
EXPECT_DOUBLE_EQ(1.1, leaf.getValue());
|
|
|
|
|
|
|
|
diffs->redo();
|
|
|
|
EXPECT_DOUBLE_EQ(2.2, leaf.getValue());
|
|
|
|
|
|
|
|
diffs->redo();
|
|
|
|
EXPECT_DOUBLE_EQ(2.2, leaf.getValue());
|
|
|
|
|
|
|
|
diffs->undo();
|
|
|
|
EXPECT_DOUBLE_EQ(1.1, leaf.getValue());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(DiffManager, undoBranch)
|
|
|
|
{
|
|
|
|
DefinitionNode root(NULL, "root");
|
|
|
|
DiffManager *diffs = root.getDiffManager();
|
|
|
|
|
|
|
|
FloatNode leaf(&root, "value", 1.1);
|
|
|
|
EXPECT_DOUBLE_EQ(1.1, leaf.getValue());
|
|
|
|
|
|
|
|
leaf.setValue(2.2);
|
|
|
|
EXPECT_DOUBLE_EQ(2.2, leaf.getValue());
|
|
|
|
|
|
|
|
leaf.setValue(3.3);
|
|
|
|
EXPECT_DOUBLE_EQ(3.3, leaf.getValue());
|
|
|
|
|
|
|
|
diffs->undo();
|
|
|
|
EXPECT_DOUBLE_EQ(2.2, leaf.getValue());
|
|
|
|
|
|
|
|
leaf.setValue(4.4);
|
|
|
|
EXPECT_DOUBLE_EQ(4.4, leaf.getValue());
|
|
|
|
|
|
|
|
diffs->undo();
|
|
|
|
EXPECT_DOUBLE_EQ(2.2, leaf.getValue());
|
|
|
|
|
|
|
|
diffs->undo();
|
|
|
|
EXPECT_DOUBLE_EQ(1.1, leaf.getValue());
|
|
|
|
|
|
|
|
diffs->redo();
|
|
|
|
EXPECT_DOUBLE_EQ(2.2, leaf.getValue());
|
|
|
|
|
|
|
|
diffs->redo();
|
|
|
|
EXPECT_DOUBLE_EQ(4.4, leaf.getValue());
|
|
|
|
|
|
|
|
diffs->redo();
|
|
|
|
EXPECT_DOUBLE_EQ(4.4, leaf.getValue());
|
|
|
|
}
|