blob: 35ff146ac55b53272ef615fec91f6b88bc72cd54 [file] [log] [blame]
Deepak Kodihalli4de4d002019-11-11 02:41:43 -06001#include "instance_id.hpp"
2
3#include <stdexcept>
4
5#include <gtest/gtest.h>
6
7using namespace pldm;
8
9TEST(InstanceId, testNext)
10{
11 InstanceId id;
12 ASSERT_EQ(id.next(), 0);
13 ASSERT_EQ(id.next(), 1);
14}
15
16TEST(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
26TEST(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}