media/libstagefright/gtest/TestMP4Rust.cpp
author Ralph Giles <giles@mozilla.com>
Fri, 16 Oct 2015 14:07:22 -0700
changeset 268443 db739c4c8f9797a80689b2f658e785af9f007e55
parent 268425 ebad4f2326b0743115142e8105f0878000d0f410
child 268924 2d19d26df5128c2694ce34ac1b6a86681a64da15
permissions -rw-r--r--
Bug 1215696 - Update tests for mp4parse v0.1.1. r=kinetik Now that this is returning the correct number of tracks for the test file we can un-XFAIL.

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "gtest/gtest.h"
#include "mp4_demuxer/MP4Metadata.h"

#include <stdint.h>
#include <stdio.h>
#include <vector>

extern "C" int32_t read_box_from_buffer(uint8_t *buffer, size_t size);

using namespace mp4_demuxer;
using namespace mozilla;

TEST(rust, MP4MetadataEmpty)
{
  int32_t rv;
  rv = read_box_from_buffer(nullptr, 0);
  EXPECT_EQ(rv, -1);

  size_t len = 4097;
  rv = read_box_from_buffer(nullptr, len);
  EXPECT_EQ(rv, -1);

  std::vector<uint8_t> buf;
  rv = read_box_from_buffer(buf.data(), buf.size());
  EXPECT_EQ(rv, -1);

  buf.reserve(len);
  rv = read_box_from_buffer(buf.data(), buf.size());
  EXPECT_EQ(rv, -1);
}

TEST(rust, MP4Metadata)
{
  FILE* f = fopen("street.mp4", "rb");
  ASSERT_TRUE(f != nullptr);

  size_t len = 4096;
  std::vector<uint8_t> buf(len);
  size_t read = fread(buf.data(), sizeof(decltype(buf)::value_type), buf.size(), f);
  buf.resize(read);
  fclose(f);

  int32_t rv = read_box_from_buffer(buf.data(), buf.size());
  EXPECT_EQ(rv, 2);
}