/*
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 "TestManaged.hpp"
namespace ousia {
TEST(Managed, data)
{
Manager mgr{1};
Rooted n{new Managed{mgr}};
Rooted m1{new Managed{mgr}};
n->storeData("info", m1);
ASSERT_TRUE(n->hasDataKey("info"));
ASSERT_FALSE(n->hasDataKey("test"));
Rooted m2{new Managed{mgr}};
n->storeData("test", m2);
ASSERT_TRUE(n->hasDataKey("info"));
ASSERT_TRUE(n->hasDataKey("test"));
ASSERT_TRUE(n->deleteData("info"));
ASSERT_FALSE(n->deleteData("info"));
ASSERT_FALSE(n->hasDataKey("info"));
ASSERT_TRUE(n->hasDataKey("test"));
n->storeData("info2", m1);
std::map> m = n->readData();
ASSERT_TRUE(m.find("info2") != m.end());
ASSERT_TRUE(m.find("test") != m.end());
ASSERT_EQ(m1, m.find("info2")->second);
ASSERT_EQ(m2, m.find("test")->second);
}
class TypeTestManaged1 : public Managed {
using Managed::Managed;
};
class TypeTestManaged2 : public Managed {
using Managed::Managed;
};
class TypeTestManaged3 : public Managed {
using Managed::Managed;
};
class TypeTestManaged4 : public Managed {
using Managed::Managed;
};
class TypeTestManaged5 : public Managed {
using Managed::Managed;
};
ManagedType Type1("Type1", typeid(TypeTestManaged1));
ManagedType Type2("Type2", typeid(TypeTestManaged2));
ManagedType Type3("Type3", typeid(TypeTestManaged3), {&Type1});
ManagedType Type4("Type2", typeid(TypeTestManaged4), {&Type3, &Type2});
TEST(ManagedType, isa)
{
ASSERT_TRUE(Type1.isa(Type1));
ASSERT_FALSE(Type1.isa(Type2));
ASSERT_FALSE(Type1.isa(Type3));
ASSERT_FALSE(Type1.isa(Type4));
ASSERT_FALSE(Type2.isa(Type1));
ASSERT_TRUE(Type2.isa(Type2));
ASSERT_FALSE(Type2.isa(Type3));
ASSERT_FALSE(Type2.isa(Type4));
ASSERT_TRUE(Type3.isa(Type1));
ASSERT_FALSE(Type3.isa(Type2));
ASSERT_TRUE(Type3.isa(Type3));
ASSERT_FALSE(Type3.isa(Type4));
ASSERT_TRUE(Type4.isa(Type1));
ASSERT_TRUE(Type4.isa(Type2));
ASSERT_TRUE(Type4.isa(Type3));
ASSERT_TRUE(Type4.isa(Type4));
}
TEST(Managed, type)
{
Manager mgr(1);
Rooted m1{new TypeTestManaged1(mgr)};
Rooted m2{new TypeTestManaged2(mgr)};
Rooted m3{new TypeTestManaged3(mgr)};
Rooted m4{new TypeTestManaged4(mgr)};
Rooted m5{new TypeTestManaged5(mgr)};
ASSERT_EQ(&Type1, &m1->type());
ASSERT_EQ(&Type2, &m2->type());
ASSERT_EQ(&Type3, &m3->type());
ASSERT_EQ(&Type4, &m4->type());
ASSERT_EQ(&ManagedType::None, &m5->type());
}
}