Skip to content

Commit

Permalink
More unit tests and fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
andy31415 committed Jun 6, 2024
1 parent 1e45ed0 commit e62aa6e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/app/codegen-interaction-model/CodegenDataModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ ConcreteCommandPath CodegenDataModel::NextGeneratedCommand(const ConcreteCommand

VerifyOrReturnValue(cluster != nullptr, kInvalidCommandPath);

std::optional<CommandId> commandId = mGeneratedCommandsIterator.Next(cluster->acceptedCommandList, before.mCommandId);
std::optional<CommandId> commandId = mGeneratedCommandsIterator.Next(cluster->generatedCommandList, before.mCommandId);
VerifyOrReturnValue(commandId.has_value(), kInvalidCommandPath);

return ConcreteCommandPath(before.mEndpointId, before.mClusterId, *commandId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const MockNodeConfig gTestNodeConfig({
}, /* attributes */
{}, /* events */
{11}, /* acceptedCommands */
{4} /* generatedCommands */
{4, 6} /* generatedCommands */
),
}),
MockEndpointConfig(kMockEndpoint3, {
Expand Down Expand Up @@ -378,7 +378,66 @@ TEST(TestCodegenModelViaMocks, IterateOverAcceptedCommands)

for (int i = 0; i < 10; i++)
{
entry = model.NextAcceptedCommand(ConcreteCommandPath(kMockEndpoint2, MockClusterId(3), 11));
entry = model.NextAcceptedCommand(ConcreteCommandPath(kMockEndpoint2, MockClusterId(3), 10));
EXPECT_FALSE(entry.path.HasValidIds());
}
}

TEST(TestCodegenModelViaMocks, IterateOverGeneratedCommands)
{
UseMockNodeConfig config(gTestNodeConfig);
chip::app::CodegenDataModel model;

// invalid paths should return in "no more data"
ASSERT_FALSE(model.FirstGeneratedCommand(ConcreteClusterPath(kEndpointIdThatIsMissing, MockClusterId(1))).HasValidIds());
ASSERT_FALSE(model.FirstGeneratedCommand(ConcreteClusterPath(kInvalidEndpointId, MockClusterId(1))).HasValidIds());
ASSERT_FALSE(model.FirstGeneratedCommand(ConcreteClusterPath(kMockEndpoint1, MockClusterId(10))).HasValidIds());
ASSERT_FALSE(model.FirstGeneratedCommand(ConcreteClusterPath(kMockEndpoint1, kInvalidClusterId)).HasValidIds());

// should be able to iterate over valid paths
ConcreteCommandPath path = model.FirstGeneratedCommand(ConcreteClusterPath(kMockEndpoint2, MockClusterId(2)));
ASSERT_TRUE(path.HasValidIds());
EXPECT_EQ(path.mEndpointId, kMockEndpoint2);
EXPECT_EQ(path.mClusterId, MockClusterId(2));
EXPECT_EQ(path.mCommandId, 2u);

path = model.NextGeneratedCommand(path);
ASSERT_TRUE(path.HasValidIds());
EXPECT_EQ(path.mEndpointId, kMockEndpoint2);
EXPECT_EQ(path.mClusterId, MockClusterId(2));
EXPECT_EQ(path.mCommandId, 10u);

path = model.NextGeneratedCommand(path);
ASSERT_FALSE(path.HasValidIds());

// attempt some out-of-order requests as well
path = model.FirstGeneratedCommand(ConcreteClusterPath(kMockEndpoint2, MockClusterId(3)));
ASSERT_TRUE(path.HasValidIds());
EXPECT_EQ(path.mEndpointId, kMockEndpoint2);
EXPECT_EQ(path.mClusterId, MockClusterId(3));
EXPECT_EQ(path.mCommandId, 4u);

for (int i = 0; i < 10; i++)
{
path = model.NextGeneratedCommand(ConcreteCommandPath(kMockEndpoint2, MockClusterId(2), 2));
ASSERT_TRUE(path.HasValidIds());
EXPECT_EQ(path.mEndpointId, kMockEndpoint2);
EXPECT_EQ(path.mClusterId, MockClusterId(2));
EXPECT_EQ(path.mCommandId, 10u);
}

for (int i = 0; i < 10; i++)
{
path = model.NextGeneratedCommand(ConcreteCommandPath(kMockEndpoint2, MockClusterId(3), 4));
ASSERT_TRUE(path.HasValidIds());
EXPECT_EQ(path.mEndpointId, kMockEndpoint2);
EXPECT_EQ(path.mClusterId, MockClusterId(3));
EXPECT_EQ(path.mCommandId, 6u);
}

for (int i = 0; i < 10; i++)
{
path = model.NextGeneratedCommand(ConcreteCommandPath(kMockEndpoint2, MockClusterId(3), 6));
EXPECT_FALSE(path.HasValidIds());
}
}

0 comments on commit e62aa6e

Please sign in to comment.