Bug 1175322 - Add gtests for rust mp4 metadata parser. r=k17e
authorRalph Giles <giles@mozilla.com>
Tue, 16 Jun 2015 15:52:00 -0700
changeset 280037 5988e0ef6cef730019c7e6649865c031879b50da
parent 280036 758e4197540257606a0d817855a1d294d53316a0
child 280038 df1354cdd7fb80f0d014e27bfa026057a2855375
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-beta@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersk17e
bugs1175322
milestone41.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1175322 - Add gtests for rust mp4 metadata parser. r=k17e Add a null buffer test. Add a street.mp4 test. We have trouble parsing gizmo.mp4, and the dom/media/gtest already exposes the file, which is confusing since we apparently can't have duplicates in TEST_HARNESS_FILES. The street.mp4 test always fails because we don't catch the eof in the rust code.
media/libstagefright/gtest/TestMP4Rust.cpp
media/libstagefright/gtest/moz.build
new file mode 100644
--- /dev/null
+++ b/media/libstagefright/gtest/TestMP4Rust.cpp
@@ -0,0 +1,48 @@
+/* -*- 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 <cstdint>
+#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.
+}
--- a/media/libstagefright/gtest/moz.build
+++ b/media/libstagefright/gtest/moz.build
@@ -5,11 +5,17 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 Library('stagefright_gtest')
 
 SOURCES += [
     'TestInterval.cpp',
 ]
 
+if CONFIG['MOZ_RUST']:
+    UNIFIED_SOURCES += ['TestMP4Rust.cpp',]
+    TEST_HARNESS_FILES.gtest += [
+        '../../../dom/media/test/street.mp4',
+    ]
+
 FINAL_LIBRARY = 'xul-gtest'
 
 FAIL_ON_WARNINGS = True