1 // Copyright (c) 2016 The WebM project authors. All Rights Reserved. 2 // 3 // Use of this source code is governed by a BSD-style license 4 // that can be found in the LICENSE file in the root of the source 5 // tree. An additional intellectual property rights grant can be found 6 // in the file PATENTS. All contributing project authors may 7 // be found in the AUTHORS file in the root of the source tree. 8 #ifndef LIBWEBM_TESTING_TEST_UTIL_H_ 9 #define LIBWEBM_TESTING_TEST_UTIL_H_ 10 11 #include <cstddef> 12 #include <cstdint> 13 #include <string> 14 15 namespace mkvparser { 16 class IMkvReader; 17 class MkvReader; 18 class Segment; 19 } // namespace mkvparser 20 21 namespace test { 22 23 // constants for muxer and parser tests 24 const char kAppString[] = "mkvmuxer_unit_tests"; 25 const char kOpusCodecId[] = "A_OPUS"; 26 const char kVorbisCodecId[] = "A_VORBIS"; 27 const int kAudioTrackNumber = 2; 28 const int kBitDepth = 2; 29 const int kChannels = 2; 30 const double kDuration = 2.345; 31 const int kFrameLength = 10; 32 const int kHeight = 180; 33 const int kInvalidTrackNumber = 100; 34 const std::uint64_t kOpusCodecDelay = 6500000; 35 const std::size_t kOpusPrivateDataSizeMinimum = 19; 36 const std::uint64_t kOpusSeekPreroll = 80000000; 37 const char kMetadataCodecId[] = "D_WEBVTT/METADATA"; 38 const int kMetadataTrackNumber = 3; 39 const int kMetadataTrackType = 0x21; 40 const int kSampleRate = 30; 41 const int kTimeCodeScale = 1000; 42 const char kTrackName[] = "unit_test"; 43 const char kVP8CodecId[] = "V_VP8"; 44 const char kVP9CodecId[] = "V_VP9"; 45 const double kVideoFrameRate = 0.5; 46 const int kVideoTrackNumber = 1; 47 const int kWidth = 320; 48 49 // Returns the path to the test data directory by reading and returning the 50 // contents the LIBWEBM_TESTDATA_DIR environment variable. 51 std::string GetTestDataDir(); 52 53 // Returns the absolute path to the file of |name| in LIBWEBM_TESTDATA_DIR. 54 std::string GetTestFilePath(const std::string& name); 55 56 // Byte-wise comparison of two files |file1| and |file2|. Returns true if the 57 // files match exactly, false otherwise. 58 bool CompareFiles(const std::string& file1, const std::string& file2); 59 60 // Returns true and sets |cues_offset| to the cues location within the MKV file 61 // parsed by |segment| when the MKV file has cue points. 62 bool HasCuePoints(const mkvparser::Segment* segment, std::int64_t* cues_offset); 63 64 // Validates cue points. Assumes caller has already called Load() on |segment|. 65 // Returns true when: 66 // All cue points point at clusters, OR 67 // Data parsed by |segment| has no cue points. 68 bool ValidateCues(mkvparser::Segment* segment, mkvparser::IMkvReader* reader); 69 70 // Parses |webm_file| using mkvparser and returns true when file parses 71 // successfully (all clusters and blocks can be successfully walked). Second 72 // variant allows further interaction with the parsed file via transferring 73 // ownership of the mkvparser Segment and MkvReader to the caller via 74 // |parser_out|. 75 struct MkvParser { 76 MkvParser() = default; 77 ~MkvParser(); 78 mkvparser::Segment* segment = nullptr; 79 mkvparser::MkvReader* reader = nullptr; 80 }; 81 bool ParseMkvFile(const std::string& webm_file); 82 bool ParseMkvFileReleaseParser(const std::string& webm_file, 83 MkvParser* parser_out); 84 85 } // namespace test 86 87 #endif // LIBWEBM_TESTING_TEST_UTIL_H_ 88