blob: efd472889cb5c551d13edf70a4955be7b73c131a [file] [log] [blame]
henrike@webrtc.orgf0488722014-05-13 18:00:26 +00001/*
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 Janssonf9c5cf62018-02-28 16:04:26 +010011#include "rtc_base/data_rate_limiter.h"
Yves Gerey3e707812018-11-28 16:47:49 +010012
13#include "test/gtest.h"
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000014
15namespace rtc {
16
17TEST(RateLimiterTest, TestCanUse) {
18 // Diet: Can eat 2,000 calories per day.
Sebastian Janssonf9c5cf62018-02-28 16:04:26 +010019 DataRateLimiter limiter = DataRateLimiter(2000, 1.0);
henrike@webrtc.orgf0488722014-05-13 18:00:26 +000020
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