Bug 1179885 - Update rust mp4parser gtest. r=k17e
authorRalph Giles <giles@mozilla.com>
Thu, 02 Jul 2015 11:21:42 -0700
changeset 251195 420f6d12f471604011e97db229ad94e7a791cca9
parent 251194 011c518c9d23e14b94bd8323de1bc52f60196081
child 251196 85c8317aeb3742ded4e8d445e7d71299bd94ceed
push id61791
push userrgiles@mozilla.com
push dateThu, 02 Jul 2015 21:14:20 +0000
treeherdermozilla-inbound@420f6d12f471 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersk17e
bugs1179885
milestone42.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 1179885 - Update rust mp4parser gtest. r=k17e Switch to stdio for reading the file snippet. I can't figure out how to cleanly read a minimum subset into a vector with ifstream. Previously we were asking it to read zero bytes, so the argument validation in read_box_from_buffer() was rejecting the data without trying to parse it. With this and the v0.0.9 changes to catch eof, we can remove the expected fail on the street.mp4 test.
media/libstagefright/gtest/TestMP4Rust.cpp
--- a/media/libstagefright/gtest/TestMP4Rust.cpp
+++ b/media/libstagefright/gtest/TestMP4Rust.cpp
@@ -2,17 +2,17 @@
 /* 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 <stdio.h>
 #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)
@@ -31,18 +31,20 @@ TEST(rust, MP4MetadataEmpty)
 
   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());
+  FILE* f = fopen("street.mp4", "rb");
+  ASSERT_TRUE(f != nullptr);
 
   size_t len = 4096;
-  std::vector<uint8_t> buf;
-  buf.reserve(len);
-  f.read(reinterpret_cast<char*>(buf.data()), buf.size());
+  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);
+
   bool rv = read_box_from_buffer(buf.data(), buf.size());
-  ASSERT_FALSE(rv); // Expected fail: need to trap eof.
+  EXPECT_EQ(rv, true);
 }