henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 The WebRTC Project Authors. All rights reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Sebastian Jansson | f9c5cf6 | 2018-02-28 16:04:26 +0100 | [diff] [blame] | 11 | #include "rtc_base/data_rate_limiter.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 12 | |
| 13 | #include "test/gtest.h" |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 14 | |
| 15 | namespace rtc { |
| 16 | |
| 17 | TEST(RateLimiterTest, TestCanUse) { |
| 18 | // Diet: Can eat 2,000 calories per day. |
Sebastian Jansson | f9c5cf6 | 2018-02-28 16:04:26 +0100 | [diff] [blame] | 19 | DataRateLimiter limiter = DataRateLimiter(2000, 1.0); |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 20 | |
| 21 | double monday = 1.0; |
| 22 | double tuesday = 2.0; |
| 23 | double thursday = 4.0; |
| 24 | |
| 25 | EXPECT_TRUE(limiter.CanUse(0, monday)); |
| 26 | EXPECT_TRUE(limiter.CanUse(1000, monday)); |
| 27 | EXPECT_TRUE(limiter.CanUse(1999, monday)); |
| 28 | EXPECT_TRUE(limiter.CanUse(2000, monday)); |
| 29 | EXPECT_FALSE(limiter.CanUse(2001, monday)); |
| 30 | |
| 31 | limiter.Use(1000, monday); |
| 32 | |
| 33 | EXPECT_TRUE(limiter.CanUse(0, monday)); |
| 34 | EXPECT_TRUE(limiter.CanUse(999, monday)); |
| 35 | EXPECT_TRUE(limiter.CanUse(1000, monday)); |
| 36 | EXPECT_FALSE(limiter.CanUse(1001, monday)); |
| 37 | |
| 38 | limiter.Use(1000, monday); |
| 39 | |
| 40 | EXPECT_TRUE(limiter.CanUse(0, monday)); |
| 41 | EXPECT_FALSE(limiter.CanUse(1, monday)); |
| 42 | |
| 43 | EXPECT_TRUE(limiter.CanUse(0, tuesday)); |
| 44 | EXPECT_TRUE(limiter.CanUse(1, tuesday)); |
| 45 | EXPECT_TRUE(limiter.CanUse(1999, tuesday)); |
| 46 | EXPECT_TRUE(limiter.CanUse(2000, tuesday)); |
| 47 | EXPECT_FALSE(limiter.CanUse(2001, tuesday)); |
| 48 | |
| 49 | limiter.Use(1000, tuesday); |
| 50 | |
| 51 | EXPECT_TRUE(limiter.CanUse(1000, tuesday)); |
| 52 | EXPECT_FALSE(limiter.CanUse(1001, tuesday)); |
| 53 | |
| 54 | limiter.Use(1000, thursday); |
| 55 | |
| 56 | EXPECT_TRUE(limiter.CanUse(1000, tuesday)); |
| 57 | EXPECT_FALSE(limiter.CanUse(1001, tuesday)); |
| 58 | } |
| 59 | |
| 60 | } // namespace rtc |