1 #include <bufferhub/BufferHubIdGenerator.h> 2 #include <gtest/gtest.h> 3 4 namespace android { 5 namespace frameworks { 6 namespace bufferhub { 7 namespace V1_0 { 8 namespace implementation { 9 10 namespace { 11 12 class BufferHubIdGeneratorTest : public testing::Test { 13 protected: 14 BufferHubIdGenerator* mIdGenerator = &BufferHubIdGenerator::getInstance(); 15 }; 16 TEST_F(BufferHubIdGeneratorTest,TestGenerateAndFreeID)17TEST_F(BufferHubIdGeneratorTest, TestGenerateAndFreeID) { 18 int id = mIdGenerator->getId(); 19 EXPECT_GE(id, 0); 20 21 mIdGenerator->freeId(id); 22 } 23 TEST_F(BufferHubIdGeneratorTest,TestGenerateUniqueIncrementalID)24TEST_F(BufferHubIdGeneratorTest, TestGenerateUniqueIncrementalID) { 25 // 10 IDs should not overflow the UniqueIdGenerator to cause a roll back to start, so the 26 // resulting IDs should still keep incresing. 27 const int kTestSize = 10; 28 int ids[kTestSize]; 29 for (int i = 0; i < kTestSize; ++i) { 30 ids[i] = mIdGenerator->getId(); 31 EXPECT_GE(ids[i], 0); 32 if (i >= 1) { 33 EXPECT_GT(ids[i], ids[i - 1]); 34 } 35 } 36 37 for (int i = 0; i < kTestSize; ++i) { 38 mIdGenerator->freeId(ids[i]); 39 } 40 } 41 42 } // namespace 43 44 } // namespace implementation 45 } // namespace V1_0 46 } // namespace bufferhub 47 } // namespace frameworks 48 } // namespace android