2014-05-22 02:16:17 +00:00
|
|
|
// Copyright 2014 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file or at
|
|
|
|
// https://developers.google.com/open-source/licenses/bsd
|
|
|
|
|
2014-10-01 22:10:21 +00:00
|
|
|
#include "packager/mpd/base/bandwidth_estimator.h"
|
2014-05-22 02:16:17 +00:00
|
|
|
|
2018-06-22 23:19:30 +00:00
|
|
|
#include <gtest/gtest.h>
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
namespace shaka {
|
2014-05-22 02:16:17 +00:00
|
|
|
|
|
|
|
namespace {
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint64_t kBitsInByte = 8;
|
2014-05-22 02:16:17 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST(BandwidthEstimatorTest, AllBlocks) {
|
2018-06-22 23:19:30 +00:00
|
|
|
BandwidthEstimator be;
|
2014-09-30 21:52:21 +00:00
|
|
|
const uint64_t kNumBlocksToAdd = 100;
|
2014-05-22 02:16:17 +00:00
|
|
|
const double kDuration = 1.0;
|
2018-06-22 23:19:30 +00:00
|
|
|
uint64_t total_bytes = 0;
|
|
|
|
for (uint64_t i = 1; i <= kNumBlocksToAdd; ++i) {
|
2014-05-22 02:16:17 +00:00
|
|
|
be.AddBlock(i, kDuration);
|
2018-06-22 23:19:30 +00:00
|
|
|
total_bytes += i;
|
|
|
|
}
|
2014-05-22 02:16:17 +00:00
|
|
|
|
2018-06-22 23:19:30 +00:00
|
|
|
const uint64_t kExptectedEstimate =
|
|
|
|
total_bytes * kBitsInByte / kNumBlocksToAdd;
|
2014-05-22 02:16:17 +00:00
|
|
|
EXPECT_EQ(kExptectedEstimate, be.Estimate());
|
2018-06-22 23:19:30 +00:00
|
|
|
const uint64_t kMax = kNumBlocksToAdd * kBitsInByte;
|
2018-04-13 18:48:11 +00:00
|
|
|
EXPECT_EQ(kMax, be.Max());
|
2014-05-22 02:16:17 +00:00
|
|
|
}
|
|
|
|
|
2016-05-20 21:19:33 +00:00
|
|
|
} // namespace shaka
|