12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #include "netdutils/OperationLimiter.h"
- #include <gtest/gtest-spi.h>
- namespace android {
- namespace netdutils {
- TEST(OperationLimiter, limits) {
- OperationLimiter<int> limiter(3);
- EXPECT_TRUE(limiter.start(42));
- EXPECT_TRUE(limiter.start(42));
- EXPECT_TRUE(limiter.start(42));
-
- EXPECT_FALSE(limiter.start(42));
- EXPECT_FALSE(limiter.start(42));
- EXPECT_FALSE(limiter.start(42));
-
- limiter.finish(42);
- EXPECT_TRUE(limiter.start(42));
-
- EXPECT_FALSE(limiter.start(42));
-
- EXPECT_TRUE(limiter.start(666));
- limiter.finish(666);
-
- limiter.finish(42);
- limiter.finish(42);
- limiter.finish(42);
- }
- TEST(OperationLimiter, finishWithoutStart) {
- OperationLimiter<int> limiter(1);
-
- limiter.finish(42);
-
- EXPECT_TRUE(limiter.start(42));
- EXPECT_FALSE(limiter.start(42));
- }
- TEST(OperationLimiter, destroyWithActiveOperations) {
-
- EXPECT_DEBUG_DEATH({
- OperationLimiter<int> limiter(3);
- limiter.start(42);
- }, "" );
- }
- }
- }
|