Skip to content

Commit

Permalink
Merge "Add test cases for bool in ifmap_identity_property_test.cc"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed May 27, 2015
2 parents c05b017 + b1b2a6b commit 6857252
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/schema/test/ifmap_identity_property.xsd
Expand Up @@ -14,6 +14,7 @@
<xsd:all>
<xsd:element name="attr1" type="xsd:integer"/>
<xsd:element name="attr2" type="xsd:string"/>
<xsd:element name="attr3" type="xsd:boolean"/>
</xsd:all>
</xsd:complexType>

Expand Down Expand Up @@ -42,4 +43,7 @@
<xsd:element name='long-value' type='xsd:unsignedLong'/>
<!-- #IFMAP-SEMANTICS-IDL Property('long-value', 'foo') -->

<xsd:element name='bool-value' type='xsd:boolean'/>
<!-- #IFMAP-SEMANTICS-IDL Property('bool-value', 'foo') -->

</xsd:schema>
64 changes: 60 additions & 4 deletions src/schema/test/ifmap_identity_property_test.cc
Expand Up @@ -79,7 +79,7 @@ TEST_F(IdentityPropertyTest, Parse) {

IFMapServerParser::RequestList requests;
xparser_->ParseResults(xdoc_, &requests);
EXPECT_EQ(5, requests.size());
EXPECT_EQ(7, requests.size());
DBRequest *req = requests.front();
IFMapServerTable::RequestData *data =
static_cast<IFMapServerTable::RequestData *>(req->data.get());
Expand All @@ -89,17 +89,19 @@ TEST_F(IdentityPropertyTest, Parse) {
ASSERT_TRUE(attr);
EXPECT_EQ(10, attr->attr1);
EXPECT_EQ("baz", attr->attr2);
EXPECT_EQ(true, attr->attr3);
STLDeleteValues(&requests);
}

TEST_F(IdentityPropertyTest, EncodeDecode) {
pugi::xml_parse_result result =
xdoc_.load_file("controller/src/schema/testdata/ifmap_identity_property_1.xml");
xdoc_.load_file(
"controller/src/schema/testdata/ifmap_identity_property_1.xml");
EXPECT_TRUE(result);

IFMapServerParser::RequestList requests;
xparser_->ParseResults(xdoc_, &requests);
EXPECT_EQ(5, requests.size());
EXPECT_EQ(7, requests.size());

IFMapServerTable *table = static_cast<IFMapServerTable *>(
IFMapTable::FindTable(&db_, "foo"));
Expand All @@ -115,7 +117,7 @@ TEST_F(IdentityPropertyTest, EncodeDecode) {
pugi::xml_node config = xmsg.append_child("config");
pugi::xml_node update = config.append_child("update");

const char *objs[] = {"a", "b", "c", "d"};
const char *objs[] = {"a", "b", "c", "d", "e"};
BOOST_FOREACH(const char *name, objs) {
IFMapNode *node = table->FindNode(name);
Foo *foo = static_cast<Foo *>(node->GetObject());
Expand All @@ -126,6 +128,18 @@ TEST_F(IdentityPropertyTest, EncodeDecode) {
EXPECT_EQ(2, foo->complex_list().size());
} else if (node->name() == "d") {
EXPECT_EQ(3, foo->value().size());
} else if (node->name() == "e") {
EXPECT_EQ(5, foo->complex_list().size());
// Check default value for bool is false.
autogen::AttributeType attr = foo->complex_list().at(0);
EXPECT_FALSE(attr.attr3);
// Check explicitly setting true works correctly.
attr = foo->complex_list().at(1);
EXPECT_TRUE(attr.attr3);
// Check explicitly setting false works correctly.
attr = foo->complex_list().at(4);
EXPECT_FALSE(attr.attr3);
EXPECT_EQ(true, foo->bool_value());
}
node->EncodeNodeDetail(&update);
}
Expand All @@ -149,6 +163,18 @@ TEST_F(IdentityPropertyTest, EncodeDecode) {
} else if (id_name == "d") {
EXPECT_EQ(1, obj->complex_list().size());
EXPECT_EQ(3, obj->value().size());
} else if (id_name == "e") {
EXPECT_EQ(5, obj->complex_list().size());
// Check default value for bool is false.
autogen::AttributeType attr = obj->complex_list().at(0);
EXPECT_FALSE(attr.attr3);
// Check explicitly setting true works correctly.
attr = obj->complex_list().at(1);
EXPECT_TRUE(attr.attr3);
// Check explicitly setting false works correctly.
attr = obj->complex_list().at(4);
EXPECT_FALSE(attr.attr3);
EXPECT_EQ(true, obj->bool_value());
}
node = node.next_sibling();
}
Expand Down Expand Up @@ -184,6 +210,36 @@ TEST_F(IdentityPropertyTest, UnsignedLong) {
EXPECT_EQ(prop.data, result->long_value());
}

TEST_F(IdentityPropertyTest, Bool) {
IFMapServerTable *table = static_cast<IFMapServerTable *>(
IFMapTable::FindTable(&db_, "foo"));
IFMapTable::RequestKey key;
key.id_name = "a";
auto_ptr<IFMapNode> node_ptr(static_cast<IFMapNode *>(
table->AllocEntry(&key).release()));
Foo *obj = static_cast<Foo *>(table->AllocObject());
node_ptr->Insert(obj);
Foo::OolProperty bool_prop;
bool_prop.data = true;
obj->SetProperty("bool-value", &bool_prop);
EXPECT_EQ(bool_prop.data, obj->bool_value());

pugi::xml_document xmsg;
pugi::xml_node config = xmsg.append_child("config");
pugi::xml_node update = config.append_child("update");
node_ptr->EncodeNodeDetail(&update);

string filename = CreateTmpFilename("bool.xml");
xmsg.save_file(filename.c_str());
pugi::xml_node node = update.first_child();
EXPECT_TRUE(node);

auto_ptr<Foo> result(static_cast<Foo *>(table->AllocObject()));
string id_name;
EXPECT_TRUE(Foo::Decode(node, &id_name, result.get()));
EXPECT_EQ(bool_prop.data, result->bool_value());
}

int main(int argc, char **argv) {
LoggingInit();
::testing::InitGoogleTest(&argc, argv);
Expand Down
14 changes: 14 additions & 0 deletions src/schema/testdata/ifmap_identity_property_1.xml
Expand Up @@ -13,6 +13,7 @@
<contrail:foo-property>
<attr1>10</attr1>
<attr2>baz</attr2>
<attr3>true</attr3>
</contrail:foo-property>
</meta:metadata>
</resultItem>
Expand Down Expand Up @@ -43,6 +44,19 @@
<contrail:value>bar</contrail:value>
</metadata>
</resultItem>
<resultItem>
<identity name="contrail:foo:e" type="other"/>
<metadata>
<contrail:complex-list>
<attr><attr1>1</attr1></attr>
<attr><attr3>true</attr3></attr>
<attr><attr1>2</attr1><attr3>true</attr3></attr>
<attr><attr2>three</attr2><attr3>false</attr3></attr>
<attr><attr3>false</attr3></attr>
</contrail:complex-list>
<contrail:bool-value>true</contrail:bool-value>
</metadata>
</resultItem>
</searchResult>
</ifmap:response>
</env:Body>
Expand Down

0 comments on commit 6857252

Please sign in to comment.