blob: 4a1f9f67a5ea1d3dea774a3829a4b93d7b360268 [file] [log] [blame]
Deepak Kodihalli1521f6d2020-06-16 08:51:02 -05001#include "pldmd/instance_id.hpp"
Deepak Kodihalli4de4d002019-11-11 02:41:43 -06002
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}