Change m_schema in Parser to a shared pointer
Shared pointers are reference counted, so this will prevent segmentation
faults in some cases.
Change-Id: Ie180cf6a639c8e73e70f395d19a6082b4fce73d4
diff --git a/tests/cd.cpp b/tests/cd.cpp
index 8fe30ad..3ba1e2f 100644
--- a/tests/cd.cpp
+++ b/tests/cd.cpp
@@ -13,16 +13,16 @@
TEST_CASE("cd")
{
- Schema schema;
- schema.addContainer("", "a");
- schema.addContainer("", "b");
- schema.addContainer("a", "a2");
- schema.addContainer("b", "b2");
- schema.addContainer("a/a2", "a3");
- schema.addContainer("b/b2", "b3");
- schema.addList("", "list", {"number"});
- schema.addContainer("list", "contInList");
- schema.addList("", "twoKeyList", {"number", "name"});
+ auto schema = std::make_shared<Schema>();
+ schema->addContainer("", "a");
+ schema->addContainer("", "b");
+ schema->addContainer("a", "a2");
+ schema->addContainer("b", "b2");
+ schema->addContainer("a/a2", "a3");
+ schema->addContainer("b/b2", "b3");
+ schema->addList("", "list", {"number"});
+ schema->addContainer("list", "contInList");
+ schema->addList("", "twoKeyList", {"number", "name"});
Parser parser(schema);
std::string input;
std::ostringstream errorStream;
diff --git a/tests/leaf_editing.cpp b/tests/leaf_editing.cpp
index 09e8504..9ae2d97 100644
--- a/tests/leaf_editing.cpp
+++ b/tests/leaf_editing.cpp
@@ -13,17 +13,17 @@
TEST_CASE("leaf editing")
{
- Schema schema;
- schema.addContainer("", "contA");
- schema.addLeaf("", "leafString", yang::LeafDataTypes::String);
- schema.addLeaf("", "leafDecimal", yang::LeafDataTypes::Decimal);
- schema.addLeaf("", "leafBool", yang::LeafDataTypes::Bool);
- schema.addLeaf("", "leafInt", yang::LeafDataTypes::Int);
- schema.addLeaf("", "leafUint", yang::LeafDataTypes::Uint);
- schema.addLeafEnum("", "leafEnum", {"lol", "data", "coze"});
- schema.addLeaf("contA", "leafInCont", yang::LeafDataTypes::String);
- schema.addList("", "list", {"number"});
- schema.addLeaf("list", "leafInList", yang::LeafDataTypes::String);
+ auto schema = std::make_shared<Schema>();
+ schema->addContainer("", "contA");
+ schema->addLeaf("", "leafString", yang::LeafDataTypes::String);
+ schema->addLeaf("", "leafDecimal", yang::LeafDataTypes::Decimal);
+ schema->addLeaf("", "leafBool", yang::LeafDataTypes::Bool);
+ schema->addLeaf("", "leafInt", yang::LeafDataTypes::Int);
+ schema->addLeaf("", "leafUint", yang::LeafDataTypes::Uint);
+ schema->addLeafEnum("", "leafEnum", {"lol", "data", "coze"});
+ schema->addLeaf("contA", "leafInCont", yang::LeafDataTypes::String);
+ schema->addList("", "list", {"number"});
+ schema->addLeaf("list", "leafInList", yang::LeafDataTypes::String);
Parser parser(schema);
std::string input;
std::ostringstream errorStream;
diff --git a/tests/presence_containers.cpp b/tests/presence_containers.cpp
index 8958627..0a678fb 100644
--- a/tests/presence_containers.cpp
+++ b/tests/presence_containers.cpp
@@ -14,14 +14,14 @@
TEST_CASE("presence containers")
{
- Schema schema;
- schema.addContainer("", "a", yang::ContainerTraits::Presence);
- schema.addContainer("", "b");
- schema.addContainer("a", "a2");
- schema.addContainer("a/a2", "a3", yang::ContainerTraits::Presence);
- schema.addContainer("b", "b2", yang::ContainerTraits::Presence);
- schema.addList("", "list", {"quote"});
- schema.addContainer("list", "contInList", yang::ContainerTraits::Presence);
+ auto schema = std::make_shared<Schema>();
+ schema->addContainer("", "a", yang::ContainerTraits::Presence);
+ schema->addContainer("", "b");
+ schema->addContainer("a", "a2");
+ schema->addContainer("a/a2", "a3", yang::ContainerTraits::Presence);
+ schema->addContainer("b", "b2", yang::ContainerTraits::Presence);
+ schema->addList("", "list", {"quote"});
+ schema->addContainer("list", "contInList", yang::ContainerTraits::Presence);
Parser parser(schema);
std::string input;
std::ostringstream errorStream;