From d3c52cffd9267701d9eeaf0ab6200d6d28d99f68 Mon Sep 17 00:00:00 2001 From: Rintaro Kuroiwa Date: Mon, 16 Nov 2015 16:06:17 -0800 Subject: [PATCH] Use alias template for ScopedXmlPtr - Also renamed to scoped_xml_ptr to match other smart pointers. Change-Id: Idb998aa3252d4f3a50068a09e26a05f124e94a2f --- packager/mpd/base/mpd_builder.cc | 28 +++++----- packager/mpd/base/mpd_builder.h | 8 +-- packager/mpd/base/mpd_builder_unittest.cc | 58 ++++++++++---------- packager/mpd/base/mpd_utils.cc | 2 +- packager/mpd/base/xml/scoped_xml_ptr.h | 7 +-- packager/mpd/base/xml/xml_node.cc | 4 +- packager/mpd/base/xml/xml_node.h | 6 +- packager/mpd/base/xml/xml_node_unittest.cc | 8 +-- packager/mpd/test/mpd_builder_test_helper.cc | 10 ++-- packager/mpd/test/xml_compare.cc | 16 +++--- 10 files changed, 71 insertions(+), 76 deletions(-) diff --git a/packager/mpd/base/mpd_builder.cc b/packager/mpd/base/mpd_builder.cc index 4ae15d98ff..13f031c21e 100644 --- a/packager/mpd/base/mpd_builder.cc +++ b/packager/mpd/base/mpd_builder.cc @@ -427,7 +427,7 @@ template bool MpdBuilder::WriteMpdToOutput(OutputType* output) { static LibXmlInitializer lib_xml_initializer; - xml::ScopedXmlPtr::type doc(GenerateMpd()); + xml::scoped_xml_ptr doc(GenerateMpd()); if (!doc.get()) return false; @@ -448,7 +448,7 @@ bool MpdBuilder::WriteMpdToOutput(OutputType* output) { xmlDocPtr MpdBuilder::GenerateMpd() { // Setup nodes. static const char kXmlVersion[] = "1.0"; - xml::ScopedXmlPtr::type doc(xmlNewDoc(BAD_CAST kXmlVersion)); + xml::scoped_xml_ptr doc(xmlNewDoc(BAD_CAST kXmlVersion)); XmlNode mpd("MPD"); // Iterate thru AdaptationSets and add them to one big Period element. @@ -456,7 +456,7 @@ xmlDocPtr MpdBuilder::GenerateMpd() { std::list::iterator adaptation_sets_it = adaptation_sets_.begin(); for (; adaptation_sets_it != adaptation_sets_.end(); ++adaptation_sets_it) { - xml::ScopedXmlPtr::type child((*adaptation_sets_it)->GetXml()); + xml::scoped_xml_ptr child((*adaptation_sets_it)->GetXml()); if (!child.get() || !period.AddChild(child.Pass())) return NULL; } @@ -725,12 +725,12 @@ void AdaptationSet::AddRole(Role role) { // Creates a copy of xml element, iterate thru all the // (child) elements and add them to the copy. -xml::ScopedXmlPtr::type AdaptationSet::GetXml() { +xml::scoped_xml_ptr AdaptationSet::GetXml() { AdaptationSetXmlNode adaptation_set; if (!adaptation_set.AddContentProtectionElements( content_protection_elements_)) { - return xml::ScopedXmlPtr::type(); + return xml::scoped_xml_ptr(); } for (std::set::const_iterator role_it = roles_.begin(); role_it != roles_.end(); ++role_it) { @@ -742,9 +742,9 @@ xml::ScopedXmlPtr::type AdaptationSet::GetXml() { representations_.begin(); for (; representation_it != representations_.end(); ++representation_it) { - xml::ScopedXmlPtr::type child((*representation_it)->GetXml()); + xml::scoped_xml_ptr child((*representation_it)->GetXml()); if (!child || !adaptation_set.AddChild(child.Pass())) - return xml::ScopedXmlPtr::type(); + return xml::scoped_xml_ptr(); } adaptation_set.SetId(id_); @@ -1101,10 +1101,10 @@ void Representation::SetSampleDuration(uint32_t sample_duration) { // AddVideoInfo() (possibly adds FramePacking elements), AddAudioInfo() (Adds // AudioChannelConfig elements), AddContentProtectionElements*(), and // AddVODOnlyInfo() (Adds segment info). -xml::ScopedXmlPtr::type Representation::GetXml() { +xml::scoped_xml_ptr Representation::GetXml() { if (!HasRequiredMediaInfoFields()) { LOG(ERROR) << "MediaInfo missing required fields."; - return xml::ScopedXmlPtr::type(); + return xml::scoped_xml_ptr(); } const uint64_t bandwidth = media_info_.has_bandwidth() @@ -1127,31 +1127,31 @@ xml::ScopedXmlPtr::type Representation::GetXml() { if (has_video_info && !representation.AddVideoInfo(media_info_.video_info())) { LOG(ERROR) << "Failed to add video info to Representation XML."; - return xml::ScopedXmlPtr::type(); + return xml::scoped_xml_ptr(); } if (has_audio_info && !representation.AddAudioInfo(media_info_.audio_info())) { LOG(ERROR) << "Failed to add audio info to Representation XML."; - return xml::ScopedXmlPtr::type(); + return xml::scoped_xml_ptr(); } if (!representation.AddContentProtectionElements( content_protection_elements_)) { - return xml::ScopedXmlPtr::type(); + return xml::scoped_xml_ptr(); } if (HasVODOnlyFields(media_info_) && !representation.AddVODOnlyInfo(media_info_)) { LOG(ERROR) << "Failed to add VOD segment info."; - return xml::ScopedXmlPtr::type(); + return xml::scoped_xml_ptr(); } if (HasLiveOnlyFields(media_info_) && !representation.AddLiveOnlyInfo(media_info_, segment_infos_, start_number_)) { LOG(ERROR) << "Failed to add Live info."; - return xml::ScopedXmlPtr::type(); + return xml::scoped_xml_ptr(); } // TODO(rkuroiwa): It is likely that all representations have the exact same // SegmentTemplate. Optimize and propagate the tag up to AdaptationSet level. diff --git a/packager/mpd/base/mpd_builder.h b/packager/mpd/base/mpd_builder.h index 0ab972e095..033230fe61 100644 --- a/packager/mpd/base/mpd_builder.h +++ b/packager/mpd/base/mpd_builder.h @@ -210,9 +210,9 @@ class AdaptationSet { /// Makes a copy of AdaptationSet xml element with its child Representation /// and ContentProtection elements. - /// @return On success returns a non-NULL ScopedXmlPtr. Otherwise returns a - /// NULL ScopedXmlPtr. - xml::ScopedXmlPtr::type GetXml(); + /// @return On success returns a non-NULL scoped_xml_ptr. Otherwise returns a + /// NULL scoped_xml_ptr. + xml::scoped_xml_ptr GetXml(); /// Forces the (sub)segmentAlignment field to be set to @a segment_alignment. /// Use this if you are certain that the (sub)segments are alinged/unaligned @@ -468,7 +468,7 @@ class Representation { virtual void SetSampleDuration(uint32_t sample_duration); /// @return Copy of . - xml::ScopedXmlPtr::type GetXml(); + xml::scoped_xml_ptr GetXml(); /// @return ID number for . uint32_t id() const { return id_; } diff --git a/packager/mpd/base/mpd_builder_unittest.cc b/packager/mpd/base/mpd_builder_unittest.cc index b4f0d7a740..4feb25a083 100644 --- a/packager/mpd/base/mpd_builder_unittest.cc +++ b/packager/mpd/base/mpd_builder_unittest.cc @@ -41,7 +41,7 @@ const int kDefaultStartNumber = 1; // number. void ExpectXmlElementIdEqual(xmlNodePtr node, uint32_t id) { const char kId[] = "id"; - xml::ScopedXmlPtr::type id_attribute_xml_str( + xml::scoped_xml_ptr id_attribute_xml_str( xmlGetProp(node, BAD_CAST kId)); ASSERT_TRUE(id_attribute_xml_str); @@ -59,14 +59,14 @@ void CheckIdEqual(uint32_t expected_id, T* node) { ASSERT_EQ(expected_id, node->id()); // Also check if the XML generated by libxml2 has the correct id attribute. - xml::ScopedXmlPtr::type node_xml(node->GetXml()); + xml::scoped_xml_ptr node_xml(node->GetXml()); ASSERT_NO_FATAL_FAILURE(ExpectXmlElementIdEqual(node_xml.get(), expected_id)); } void ExpectAttributeEqString(base::StringPiece attribute, base::StringPiece expected_value, xmlNodePtr node) { - xml::ScopedXmlPtr::type attribute_xml_str( + xml::scoped_xml_ptr attribute_xml_str( xmlGetProp(node, BAD_CAST attribute.data())); ASSERT_TRUE(attribute_xml_str); EXPECT_STREQ(expected_value.data(), @@ -75,7 +75,7 @@ void ExpectAttributeEqString(base::StringPiece attribute, // |attribute| should not be set in |node|. void ExpectAttributeNotSet(base::StringPiece attribute, xmlNodePtr node) { - xml::ScopedXmlPtr::type attribute_xml_str( + xml::scoped_xml_ptr attribute_xml_str( xmlGetProp(node, BAD_CAST attribute.data())); ASSERT_FALSE(attribute_xml_str); } @@ -382,13 +382,13 @@ TEST_F(CommonMpdBuilderTest, SetAdaptationSetGroup) { MpdBuilder::kStatic, &sequence_counter); adaptation_set->SetGroup(1); - xml::ScopedXmlPtr::type xml_with_group(adaptation_set->GetXml()); + xml::scoped_xml_ptr xml_with_group(adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE( ExpectAttributeEqString("group", "1", xml_with_group.get())); // Unset by passing a negative value. adaptation_set->SetGroup(-1); - xml::ScopedXmlPtr::type xml_without_group(adaptation_set->GetXml()); + xml::scoped_xml_ptr xml_without_group(adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE( ExpectAttributeNotSet("group", xml_without_group.get())); } @@ -486,7 +486,7 @@ TEST_F(CommonMpdBuilderTest, CheckVideoInfoReflectedInXml) { CreateRepresentation(ConvertToMediaInfo(kTestMediaInfo), MpdOptions(), kAnyRepresentationId, NoListener()); EXPECT_TRUE(representation->Init()); - xml::ScopedXmlPtr::type node_xml(representation->GetXml()); + xml::scoped_xml_ptr node_xml(representation->GetXml()); EXPECT_NO_FATAL_FAILURE( ExpectAttributeEqString("codecs", "avc1", node_xml.get())); EXPECT_NO_FATAL_FAILURE( @@ -687,7 +687,7 @@ TEST_F(CommonMpdBuilderTest, CheckLanguageAttributeSet) { MpdBuilder::kStatic, &sequence_counter); adaptation_set->AddRepresentation(ConvertToMediaInfo(kTextMediaInfo)); - xml::ScopedXmlPtr::type node_xml(adaptation_set->GetXml()); + xml::scoped_xml_ptr node_xml(adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE( ExpectAttributeEqString("lang", "en", node_xml.get())); } @@ -707,7 +707,7 @@ TEST_F(CommonMpdBuilderTest, AdaptationAddRoleElementMain) { AdaptationSet* adaptation_set = mpd_builder.AddAdaptationSet(""); adaptation_set->AddRole(AdaptationSet::kRoleMain); - xml::ScopedXmlPtr::type adaptation_set_xml(adaptation_set->GetXml()); + xml::scoped_xml_ptr adaptation_set_xml(adaptation_set->GetXml()); // The empty contentType is sort of a side effect of being able to generate an // MPD without adding any Representations. const char kExpectedOutput[] = @@ -752,7 +752,7 @@ TEST_F(CommonMpdBuilderTest, CheckContentProtectionRoleRepresentationOrder) { "container_type: 1\n"; adaptation_set->AddRepresentation(ConvertToMediaInfo(kAudioMediaInfo)); - xml::ScopedXmlPtr::type adaptation_set_xml(adaptation_set->GetXml()); + xml::scoped_xml_ptr adaptation_set_xml(adaptation_set->GetXml()); const char kExpectedOutput[] = "\n" "AddRepresentation( ConvertToMediaInfo(kVideoMediaInfo2))); - xml::ScopedXmlPtr::type adaptation_set_xml( + xml::scoped_xml_ptr adaptation_set_xml( video_adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE( ExpectAttributeEqString("frameRate", "10/3", adaptation_set_xml.get())); @@ -849,7 +849,7 @@ TEST_F(CommonMpdBuilderTest, AdapatationSetMaxFrameRate) { ASSERT_TRUE(video_adaptation_set->AddRepresentation( ConvertToMediaInfo(kVideoMediaInfo15fps))); - xml::ScopedXmlPtr::type adaptation_set_xml( + xml::scoped_xml_ptr adaptation_set_xml( video_adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE(ExpectAttributeEqString("maxFrameRate", "3000/100", adaptation_set_xml.get())); @@ -898,7 +898,7 @@ TEST_F(CommonMpdBuilderTest, // First, make sure that maxFrameRate nor frameRate are set because // frame durations were not provided in the MediaInfo. - xml::ScopedXmlPtr::type no_frame_rate(adaptation_set->GetXml()); + xml::scoped_xml_ptr no_frame_rate(adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE( ExpectAttributeNotSet("maxFrameRate", no_frame_rate.get())); EXPECT_NO_FATAL_FAILURE( @@ -910,7 +910,7 @@ TEST_F(CommonMpdBuilderTest, representation_480p->SetSampleDuration(kSameFrameDuration); representation_360p->SetSampleDuration(kSameFrameDuration); - xml::ScopedXmlPtr::type same_frame_rate(adaptation_set->GetXml()); + xml::scoped_xml_ptr same_frame_rate(adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE( ExpectAttributeNotSet("maxFrameRate", same_frame_rate.get())); EXPECT_NO_FATAL_FAILURE( @@ -922,7 +922,7 @@ TEST_F(CommonMpdBuilderTest, frame_duration_must_be_shorter_for_max_frame_rate); representation_480p->SetSampleDuration(k5FPSFrameDuration); - xml::ScopedXmlPtr::type max_frame_rate(adaptation_set->GetXml()); + xml::scoped_xml_ptr max_frame_rate(adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE( ExpectAttributeEqString("maxFrameRate", "10/2", max_frame_rate.get())); EXPECT_NO_FATAL_FAILURE( @@ -991,7 +991,7 @@ TEST_F(CommonMpdBuilderTest, AdaptationSetParAllSame) { ASSERT_TRUE(video_adaptation_set->AddRepresentation( ConvertToMediaInfo(k360pVideoInfo))); - xml::ScopedXmlPtr::type adaptation_set_xml( + xml::scoped_xml_ptr adaptation_set_xml( video_adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE(ExpectAttributeEqString("par", "16:9", adaptation_set_xml.get())); @@ -1031,7 +1031,7 @@ TEST_F(CommonMpdBuilderTest, AdaptationSetParDifferent) { ASSERT_TRUE(video_adaptation_set->AddRepresentation( ConvertToMediaInfo(k2by1VideoInfo))); - xml::ScopedXmlPtr::type adaptation_set_xml( + xml::scoped_xml_ptr adaptation_set_xml( video_adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE( ExpectAttributeNotSet("par", adaptation_set_xml.get())); @@ -1055,7 +1055,7 @@ TEST_F(CommonMpdBuilderTest, AdaptationSetParUnknown) { ASSERT_TRUE(video_adaptation_set->AddRepresentation( ConvertToMediaInfo(kUknownPixelWidthAndHeight))); - xml::ScopedXmlPtr::type adaptation_set_xml( + xml::scoped_xml_ptr adaptation_set_xml( video_adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE( ExpectAttributeNotSet("par", adaptation_set_xml.get())); @@ -1093,7 +1093,7 @@ TEST_F(CommonMpdBuilderTest, ASSERT_TRUE(video_adaptation_set->AddRepresentation( ConvertToMediaInfo(kVideoMediaInfo2))); - xml::ScopedXmlPtr::type adaptation_set_xml( + xml::scoped_xml_ptr adaptation_set_xml( video_adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE(ExpectAttributeEqString("maxFrameRate", "11/3", adaptation_set_xml.get())); @@ -1149,13 +1149,13 @@ TEST_F(StaticMpdBuilderTest, SubSegmentAlignment) { adaptation_set->AddRepresentation(ConvertToMediaInfo(k360pMediaInfo)); representation_360p->AddNewSegment(kStartTime, kDuration, kAnySize); - xml::ScopedXmlPtr::type aligned(adaptation_set->GetXml()); + xml::scoped_xml_ptr aligned(adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE( ExpectAttributeEqString("subSegmentAlignment", "true", aligned.get())); // Unknown because 480p has an extra subsegments. representation_480p->AddNewSegment(11, 20, kAnySize); - xml::ScopedXmlPtr::type alignment_unknown(adaptation_set->GetXml()); + xml::scoped_xml_ptr alignment_unknown(adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE( ExpectAttributeNotSet("subSegmentAlignment", alignment_unknown.get())); @@ -1163,7 +1163,7 @@ TEST_F(StaticMpdBuilderTest, SubSegmentAlignment) { representation_360p->AddNewSegment(10, 1, kAnySize); representation_360p->AddNewSegment(11, 19, kAnySize); - xml::ScopedXmlPtr::type unaligned(adaptation_set->GetXml()); + xml::scoped_xml_ptr unaligned(adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE( ExpectAttributeNotSet("subSegmentAlignment", unaligned.get())); } @@ -1209,13 +1209,13 @@ TEST_F(StaticMpdBuilderTest, ForceSetSubSegmentAlignment) { const uint64_t kAnySize = 19834u; representation_480p->AddNewSegment(kStartTime1, kDuration, kAnySize); representation_360p->AddNewSegment(kStartTime2, kDuration, kAnySize); - xml::ScopedXmlPtr::type unaligned(adaptation_set->GetXml()); + xml::scoped_xml_ptr unaligned(adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE( ExpectAttributeNotSet("subSegmentAlignment", unaligned.get())); // Then force set the segment alignment attribute to true. adaptation_set->ForceSetSegmentAlignment(true); - xml::ScopedXmlPtr::type aligned(adaptation_set->GetXml()); + xml::scoped_xml_ptr aligned(adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE( ExpectAttributeEqString("subSegmentAlignment", "true", aligned.get())); } @@ -1261,7 +1261,7 @@ TEST_F(DynamicMpdBuilderTest, SegmentAlignment) { const uint64_t kAnySize = 19834u; representation_480p->AddNewSegment(kStartTime, kDuration, kAnySize); representation_360p->AddNewSegment(kStartTime, kDuration, kAnySize); - xml::ScopedXmlPtr::type aligned(adaptation_set->GetXml()); + xml::scoped_xml_ptr aligned(adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE( ExpectAttributeEqString("segmentAlignment", "true", aligned.get())); @@ -1270,7 +1270,7 @@ TEST_F(DynamicMpdBuilderTest, SegmentAlignment) { representation_360p->AddNewSegment(10, 1, kAnySize); representation_360p->AddNewSegment(11, 19, kAnySize); - xml::ScopedXmlPtr::type unaligned(adaptation_set->GetXml()); + xml::scoped_xml_ptr unaligned(adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE( ExpectAttributeNotSet("subSegmentAlignment", unaligned.get())); } @@ -1304,7 +1304,7 @@ TEST_F(StaticMpdBuilderTest, AdapatationSetWidthAndHeight) { ASSERT_TRUE(video_adaptation_set->AddRepresentation( ConvertToMediaInfo(kVideoMediaInfo2))); - xml::ScopedXmlPtr::type adaptation_set_xml( + xml::scoped_xml_ptr adaptation_set_xml( video_adaptation_set->GetXml()); ASSERT_NO_FATAL_FAILURE( ExpectAttributeEqString("width", "1280", adaptation_set_xml.get())); @@ -1344,7 +1344,7 @@ TEST_F(StaticMpdBuilderTest, AdapatationSetMaxWidthAndMaxHeight) { ASSERT_TRUE(video_adaptation_set->AddRepresentation( ConvertToMediaInfo(kVideoMediaInfo720p))); - xml::ScopedXmlPtr::type adaptation_set_xml( + xml::scoped_xml_ptr adaptation_set_xml( video_adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE( ExpectAttributeEqString("maxWidth", "1920", adaptation_set_xml.get())); @@ -1390,7 +1390,7 @@ TEST_F(CommonMpdBuilderTest, SetSampleDuration) { adaptation_set->AddRepresentation(video_media_info); EXPECT_TRUE(representation->Init()); - xml::ScopedXmlPtr::type adaptation_set_xml(adaptation_set->GetXml()); + xml::scoped_xml_ptr adaptation_set_xml(adaptation_set->GetXml()); EXPECT_NO_FATAL_FAILURE( ExpectAttributeNotSet("frameRate", adaptation_set_xml.get())); diff --git a/packager/mpd/base/mpd_utils.cc b/packager/mpd/base/mpd_utils.cc index ce1e6e14a2..bc1049588c 100644 --- a/packager/mpd/base/mpd_utils.cc +++ b/packager/mpd/base/mpd_utils.cc @@ -82,7 +82,7 @@ bool GetDurationAttribute(xmlNodePtr node, float* duration) { DCHECK(node); DCHECK(duration); static const char kDuration[] = "duration"; - xml::ScopedXmlPtr::type duration_value( + xml::scoped_xml_ptr duration_value( xmlGetProp(node, BAD_CAST kDuration)); if (!duration_value) diff --git a/packager/mpd/base/xml/scoped_xml_ptr.h b/packager/mpd/base/xml/scoped_xml_ptr.h index 931373ba32..e8989c8c92 100644 --- a/packager/mpd/base/xml/scoped_xml_ptr.h +++ b/packager/mpd/base/xml/scoped_xml_ptr.h @@ -34,13 +34,8 @@ struct XmlDeleter { inline void operator()(xmlChar* ptr) const { xmlFree(ptr); } }; -// C++11 allows template alias but standards before it do not. This struct is -// for aliasing scoped_ptr with libxml2 object deleter. -/// scoped_ptr for libxml2 resources. template -struct ScopedXmlPtr { - typedef scoped_ptr type; -}; +using scoped_xml_ptr = scoped_ptr; } // namespace xml } // namespace edash_packager diff --git a/packager/mpd/base/xml/xml_node.cc b/packager/mpd/base/xml/xml_node.cc index 533d8571be..6480259b47 100644 --- a/packager/mpd/base/xml/xml_node.cc +++ b/packager/mpd/base/xml/xml_node.cc @@ -61,7 +61,7 @@ XmlNode::XmlNode(const char* name) : node_(xmlNewNode(NULL, BAD_CAST name)) { XmlNode::~XmlNode() {} -bool XmlNode::AddChild(ScopedXmlPtr::type child) { +bool XmlNode::AddChild(scoped_xml_ptr child) { DCHECK(node_); DCHECK(child); if (!xmlAddChild(node_.get(), child.get())) @@ -136,7 +136,7 @@ void XmlNode::SetContent(const std::string& content) { xmlNodeSetContent(node_.get(), BAD_CAST content.c_str()); } -ScopedXmlPtr::type XmlNode::PassScopedPtr() { +scoped_xml_ptr XmlNode::PassScopedPtr() { DVLOG(2) << "Passing node_."; DCHECK(node_); return node_.Pass(); diff --git a/packager/mpd/base/xml/xml_node.h b/packager/mpd/base/xml/xml_node.h index 59952fcf4e..39c7266169 100644 --- a/packager/mpd/base/xml/xml_node.h +++ b/packager/mpd/base/xml/xml_node.h @@ -39,7 +39,7 @@ class XmlNode { /// @param child is a xmlNode to add as a child for this element. Ownership /// of the child node is transferred. /// @return true on success, false otherwise. - bool AddChild(ScopedXmlPtr::type child); + bool AddChild(scoped_xml_ptr child); /// Adds Elements to this node using the Element struct. bool AddElements(const std::vector& elements); @@ -75,7 +75,7 @@ class XmlNode { /// Transfer the ownership of the xmlNodePtr. After calling this method, the /// behavior of any methods, except the destructor, is undefined. /// @return The resource of this object. - ScopedXmlPtr::type PassScopedPtr(); + scoped_xml_ptr PassScopedPtr(); /// Release the xmlNodePtr of this object. After calling this method, the /// behavior of any methods, except the destructor, is undefined. @@ -85,7 +85,7 @@ class XmlNode { xmlNodePtr GetRawPtr(); private: - ScopedXmlPtr::type node_; + scoped_xml_ptr node_; DISALLOW_COPY_AND_ASSIGN(XmlNode); }; diff --git a/packager/mpd/base/xml/xml_node_unittest.cc b/packager/mpd/base/xml/xml_node_unittest.cc index 84c206f7b6..c3bb49b491 100644 --- a/packager/mpd/base/xml/xml_node_unittest.cc +++ b/packager/mpd/base/xml/xml_node_unittest.cc @@ -44,8 +44,8 @@ std::string GetDocAsFlatString(xmlDocPtr doc) { return output; } -ScopedXmlPtr::type MakeDoc(ScopedXmlPtr::type node) { - xml::ScopedXmlPtr::type doc(xmlNewDoc(BAD_CAST "")); +scoped_xml_ptr MakeDoc(scoped_xml_ptr node) { + xml::scoped_xml_ptr doc(xmlNewDoc(BAD_CAST "")); xmlDocSetRootElement(doc.get(), node.release()); return doc.Pass(); } @@ -61,7 +61,7 @@ class RepresentationTest : public ::testing::Test { // |node|. Returns |node| in string format. // You should not call this function multiple times. std::string GetStringFormat() { - xml::ScopedXmlPtr::type doc(xmlNewDoc(BAD_CAST "")); + xml::scoped_xml_ptr doc(xmlNewDoc(BAD_CAST "")); // Because you cannot easily get the string format of a xmlNodePtr, it gets // attached to a temporary xml doc. @@ -202,7 +202,7 @@ TEST_F(RepresentationTest, AddContentProtectionElements) { content_protections.push_back(content_protection_clearkey); representation_.AddContentProtectionElements(content_protections); - ScopedXmlPtr::type doc(MakeDoc(representation_.PassScopedPtr())); + scoped_xml_ptr doc(MakeDoc(representation_.PassScopedPtr())); ASSERT_TRUE(XmlEqual( "\n" " ::type doc( + xml::scoped_xml_ptr doc( xmlParseMemory(mpd.data(), mpd.size())); if (!doc) { LOG(ERROR) << "Failed to parse mpd into an xml doc."; @@ -75,22 +75,22 @@ bool ValidateMpdSchema(const std::string& mpd) { // First, I need to load the schema as a xmlDoc so that I can pass the path of // the DASH-MPD.xsd. Then it can resolve the relative path included from the // XSD when creating xmlSchemaParserCtxt. - xml::ScopedXmlPtr::type schema_as_doc( + xml::scoped_xml_ptr schema_as_doc( xmlReadMemory(schema_str.data(), schema_str.size(), schema_path.value().c_str(), NULL, 0)); DCHECK(schema_as_doc); - xml::ScopedXmlPtr::type + xml::scoped_xml_ptr schema_parser_ctxt(xmlSchemaNewDocParserCtxt(schema_as_doc.get())); DCHECK(schema_parser_ctxt); - xml::ScopedXmlPtr::type schema( + xml::scoped_xml_ptr schema( xmlSchemaParse(schema_parser_ctxt.get())); DCHECK(schema); - xml::ScopedXmlPtr::type valid_ctxt( + xml::scoped_xml_ptr valid_ctxt( xmlSchemaNewValidCtxt(schema.get())); DCHECK(valid_ctxt); int validation_result = diff --git a/packager/mpd/test/xml_compare.cc b/packager/mpd/test/xml_compare.cc index 989b17a8b9..c2a37739f7 100644 --- a/packager/mpd/test/xml_compare.cc +++ b/packager/mpd/test/xml_compare.cc @@ -15,8 +15,8 @@ namespace edash_packager { namespace { -xml::ScopedXmlPtr::type GetDocFromString(const std::string& xml_str) { - xml::ScopedXmlPtr::type schema_as_doc(xmlReadMemory( +xml::scoped_xml_ptr GetDocFromString(const std::string& xml_str) { + xml::scoped_xml_ptr schema_as_doc(xmlReadMemory( xml_str.data(), xml_str.size(), NULL, NULL, 0)); return schema_as_doc.Pass(); } @@ -30,7 +30,7 @@ std::map GetMapOfAttributes(xmlNodePtr node) { attribute && attribute->name && attribute->children; attribute = attribute->next) { const char* name = reinterpret_cast(attribute->name); - xml::ScopedXmlPtr::type value( + xml::scoped_xml_ptr value( xmlNodeListGetString(node->doc, attribute->children, 1)); attribute_map[name] = reinterpret_cast(value.get()); @@ -76,8 +76,8 @@ bool CompareNames(xmlNodePtr node1, xmlNodePtr node2) { } bool CompareContents(xmlNodePtr node1, xmlNodePtr node2) { - xml::ScopedXmlPtr::type node1_content_ptr(xmlNodeGetContent(node1)); - xml::ScopedXmlPtr::type node2_content_ptr(xmlNodeGetContent(node2)); + xml::scoped_xml_ptr node1_content_ptr(xmlNodeGetContent(node1)); + xml::scoped_xml_ptr node2_content_ptr(xmlNodeGetContent(node2)); std::string node1_content = reinterpret_cast(node1_content_ptr.get()); std::string node2_content = @@ -144,13 +144,13 @@ bool CompareNodes(xmlNodePtr node1, xmlNodePtr node2) { } // namespace bool XmlEqual(const std::string& xml1, const std::string& xml2) { - xml::ScopedXmlPtr::type xml1_doc(GetDocFromString(xml1)); - xml::ScopedXmlPtr::type xml2_doc(GetDocFromString(xml2)); + xml::scoped_xml_ptr xml1_doc(GetDocFromString(xml1)); + xml::scoped_xml_ptr xml2_doc(GetDocFromString(xml2)); return XmlEqual(xml1_doc.get(), xml2_doc.get()); } bool XmlEqual(const std::string& xml1, xmlDocPtr xml2) { - xml::ScopedXmlPtr::type xml1_doc(GetDocFromString(xml1)); + xml::scoped_xml_ptr xml1_doc(GetDocFromString(xml1)); return XmlEqual(xml1_doc.get(), xml2); }