Add tests that check the 'id' attributes.

Change-Id: I487ec7c658fd5a3a8bae03800e23b37cc44066f4
This commit is contained in:
Rintaro Kuroiwa 2014-02-05 10:55:37 -08:00
parent b0e26ff297
commit beaea71946
1 changed files with 47 additions and 0 deletions

View File

@ -6,12 +6,59 @@
#include "base/file_util.h" #include "base/file_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "mpd/base/mpd_builder.h" #include "mpd/base/mpd_builder.h"
#include "mpd/test/mpd_builder_test_helper.h" #include "mpd/test/mpd_builder_test_helper.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/libxml/src/include/libxml/xmlstring.h"
namespace dash_packager { namespace dash_packager {
namespace {
// Get 'id' attribute from |node|, convert it to std::string and convert it to a
// number.
void ExpectXmlElementIdEqual(xmlNodePtr node, uint32 id) {
const char kId[] = "id";
xml::ScopedXmlPtr<xmlChar>::type id_attribute_xml_str(
xmlGetProp(node, BAD_CAST kId));
ASSERT_TRUE(id_attribute_xml_str);
unsigned id_attribute_unsigned = 0;
std::string id_attribute_str =
reinterpret_cast<const char*>(id_attribute_xml_str.get());
ASSERT_TRUE(base::StringToUint(id_attribute_str, &id_attribute_unsigned));
ASSERT_EQ(id, id_attribute_unsigned);
}
// Using template to support both AdaptationSet and Representation.
template <typename T>
void CheckIdEqual(uint32 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<xmlNode>::type node_xml(node->GetXml());
ASSERT_NO_FATAL_FAILURE(ExpectXmlElementIdEqual(node_xml.get(), expected_id));
}
} // namespace
TEST(AdaptationSetTest, CheckId) {
base::AtomicSequenceNumber sequence_counter;
const uint32 kAdaptationSetId = 42;
AdaptationSet adaptation_set(kAdaptationSetId, &sequence_counter);
ASSERT_NO_FATAL_FAILURE(CheckIdEqual(kAdaptationSetId, &adaptation_set));
}
TEST(RepresentationTest, CheckId) {
const MediaInfo video_media_info = GetTestMediaInfo(kFileNameVideoMediaInfo1);
const uint32 kRepresentationId = 1;
Representation representation(video_media_info, kRepresentationId);
EXPECT_TRUE(representation.Init());
ASSERT_NO_FATAL_FAILURE(CheckIdEqual(kRepresentationId, &representation));
}
class StaticMpdBuilderTest : public ::testing::Test { class StaticMpdBuilderTest : public ::testing::Test {
public: public:
StaticMpdBuilderTest() : mpd_(MpdBuilder::kStatic) {} StaticMpdBuilderTest() : mpd_(MpdBuilder::kStatic) {}