1 // Copyright (C) 2018 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #define DEBUG false
15 #include "Log.h"
16 
17 #include "Throttler.h"
18 
19 #include <android-base/test_utils.h>
20 #include <gmock/gmock.h>
21 #include <gtest/gtest.h>
22 
23 using namespace android::os::incidentd;
24 
TEST(ThrottlerTest,DataSizeExceeded)25 TEST(ThrottlerTest, DataSizeExceeded) {
26     Throttler t(100, 100000);
27     EXPECT_FALSE(t.shouldThrottle());
28     t.addReportSize(200);
29     EXPECT_TRUE(t.shouldThrottle());
30 }
31 
TEST(ThrottlerTest,TimeReset)32 TEST(ThrottlerTest, TimeReset) {
33     Throttler t(100, 500);
34     EXPECT_FALSE(t.shouldThrottle());
35     t.addReportSize(200);
36     EXPECT_TRUE(t.shouldThrottle());
37     sleep(1);  // sleep for 1 second to make sure throttler resets
38     EXPECT_FALSE(t.shouldThrottle());
39 }
40