media/libstagefright/gtest/TestMP4Rust.cpp
author Ralph Giles <giles@mozilla.com>
Wed, 24 Jun 2015 00:23:00 -0700
changeset 250197 5ff00fe1799ed93ed6f223c72d9b0b964fd76ad6
parent 249206 5988e0ef6cef730019c7e6649865c031879b50da
child 251195 420f6d12f471604011e97db229ad94e7a791cca9
permissions -rw-r--r--
Bug 1177029 - Use stdint.h instead of cstdint. r=kinetik Clang can't find this on my MacOS X machine.

/* -*- 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 <fstream>
#include <vector>

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

using namespace mp4_demuxer;
using namespace mozilla;

TEST(rust, MP4MetadataEmpty)
{
  bool rv;
  rv = read_box_from_buffer(nullptr, 0);
  EXPECT_EQ(rv, false);

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

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

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

TEST(rust, MP4Metadata)
{
  std::ifstream f("street.mp4");
  ASSERT_TRUE(f.is_open());

  size_t len = 4096;
  std::vector<uint8_t> buf;
  buf.reserve(len);
  f.read(reinterpret_cast<char*>(buf.data()), buf.size());
  bool rv = read_box_from_buffer(buf.data(), buf.size());
  ASSERT_FALSE(rv); // Expected fail: need to trap eof.
}