Deepak Kodihalli | 4de4d00 | 2019-11-11 02:41:43 -0600 | [diff] [blame] | 1 | #include "instance_id.hpp" |
| 2 | |
| 3 | #include <stdexcept> |
| 4 | |
| 5 | #include <gtest/gtest.h> |
| 6 | |
| 7 | using namespace pldm; |
| 8 | |
| 9 | TEST(InstanceId, testNext) |
| 10 | { |
| 11 | InstanceId id; |
| 12 | ASSERT_EQ(id.next(), 0); |
| 13 | ASSERT_EQ(id.next(), 1); |
| 14 | } |
| 15 | |
| 16 | TEST(InstanceId, testAllUsed) |
| 17 | { |
| 18 | InstanceId id; |
| 19 | for (size_t i = 0; i < maxInstanceIds; ++i) |
| 20 | { |
| 21 | ASSERT_EQ(id.next(), i); |
| 22 | } |
| 23 | EXPECT_THROW(id.next(), std::runtime_error); |
| 24 | } |
| 25 | |
| 26 | TEST(InstanceId, testMarkfree) |
| 27 | { |
| 28 | InstanceId id; |
| 29 | for (size_t i = 0; i < maxInstanceIds; ++i) |
| 30 | { |
| 31 | ASSERT_EQ(id.next(), i); |
| 32 | } |
| 33 | id.markFree(5); |
| 34 | ASSERT_EQ(id.next(), 5); |
| 35 | id.markFree(0); |
| 36 | ASSERT_EQ(id.next(), 0); |
| 37 | EXPECT_THROW(id.next(), std::runtime_error); |
| 38 | EXPECT_THROW(id.markFree(32), std::out_of_range); |
| 39 | } |