Skip to content

Commit a29ae90

Browse files
committed
More tests pass
1 parent fe441f0 commit a29ae90

File tree

1 file changed

+22
-81
lines changed

1 file changed

+22
-81
lines changed

src/data-model-providers/codegen/tests/TestCodegenModelViaMocks.cpp

+22-81
Original file line numberDiff line numberDiff line change
@@ -1267,63 +1267,17 @@ TEST_F(TestCodegenModelViaMocks, IterateOverAcceptedCommands)
12671267
CodegenDataModelProviderWithContext model;
12681268

12691269
// invalid paths should return in "no more data"
1270-
ASSERT_FALSE(model.FirstAcceptedCommand(ConcreteClusterPath(kEndpointIdThatIsMissing, MockClusterId(1))).path.HasValidIds());
1271-
ASSERT_FALSE(model.FirstAcceptedCommand(ConcreteClusterPath(kInvalidEndpointId, MockClusterId(1))).path.HasValidIds());
1272-
ASSERT_FALSE(model.FirstAcceptedCommand(ConcreteClusterPath(kMockEndpoint1, MockClusterId(10))).path.HasValidIds());
1273-
ASSERT_FALSE(model.FirstAcceptedCommand(ConcreteClusterPath(kMockEndpoint1, kInvalidClusterId)).path.HasValidIds());
1270+
ASSERT_TRUE(model.AcceptedCommands(ConcreteClusterPath(kEndpointIdThatIsMissing, MockClusterId(1))).empty());
1271+
ASSERT_TRUE(model.AcceptedCommands(ConcreteClusterPath(kInvalidEndpointId, MockClusterId(1))).empty());
1272+
ASSERT_TRUE(model.AcceptedCommands(ConcreteClusterPath(kMockEndpoint1, MockClusterId(10))).empty());
1273+
ASSERT_TRUE(model.AcceptedCommands(ConcreteClusterPath(kMockEndpoint1, kInvalidClusterId)).empty());
12741274

1275-
// should be able to iterate over valid paths
1276-
CommandEntry entry = model.FirstAcceptedCommand(ConcreteClusterPath(kMockEndpoint2, MockClusterId(2)));
1277-
ASSERT_TRUE(entry.path.HasValidIds());
1278-
EXPECT_EQ(entry.path.mEndpointId, kMockEndpoint2);
1279-
EXPECT_EQ(entry.path.mClusterId, MockClusterId(2));
1280-
EXPECT_EQ(entry.path.mCommandId, 1u);
1281-
1282-
entry = model.NextAcceptedCommand(entry.path);
1283-
ASSERT_TRUE(entry.path.HasValidIds());
1284-
EXPECT_EQ(entry.path.mEndpointId, kMockEndpoint2);
1285-
EXPECT_EQ(entry.path.mClusterId, MockClusterId(2));
1286-
EXPECT_EQ(entry.path.mCommandId, 2u);
1287-
1288-
entry = model.NextAcceptedCommand(entry.path);
1289-
ASSERT_TRUE(entry.path.HasValidIds());
1290-
EXPECT_EQ(entry.path.mEndpointId, kMockEndpoint2);
1291-
EXPECT_EQ(entry.path.mClusterId, MockClusterId(2));
1292-
EXPECT_EQ(entry.path.mCommandId, 23u);
1293-
1294-
entry = model.NextAcceptedCommand(entry.path);
1295-
ASSERT_FALSE(entry.path.HasValidIds());
1296-
1297-
// attempt some out-of-order requests as well
1298-
entry = model.FirstAcceptedCommand(ConcreteClusterPath(kMockEndpoint2, MockClusterId(3)));
1299-
ASSERT_TRUE(entry.path.HasValidIds());
1300-
EXPECT_EQ(entry.path.mEndpointId, kMockEndpoint2);
1301-
EXPECT_EQ(entry.path.mClusterId, MockClusterId(3));
1302-
EXPECT_EQ(entry.path.mCommandId, 11u);
1303-
1304-
for (int i = 0; i < 10; i++)
1305-
{
1306-
entry = model.NextAcceptedCommand(ConcreteCommandPath(kMockEndpoint2, MockClusterId(2), 2));
1307-
ASSERT_TRUE(entry.path.HasValidIds());
1308-
EXPECT_EQ(entry.path.mEndpointId, kMockEndpoint2);
1309-
EXPECT_EQ(entry.path.mClusterId, MockClusterId(2));
1310-
EXPECT_EQ(entry.path.mCommandId, 23u);
1311-
}
1312-
1313-
for (int i = 0; i < 10; i++)
1314-
{
1315-
entry = model.NextAcceptedCommand(ConcreteCommandPath(kMockEndpoint2, MockClusterId(2), 1));
1316-
ASSERT_TRUE(entry.path.HasValidIds());
1317-
EXPECT_EQ(entry.path.mEndpointId, kMockEndpoint2);
1318-
EXPECT_EQ(entry.path.mClusterId, MockClusterId(2));
1319-
EXPECT_EQ(entry.path.mCommandId, 2u);
1320-
}
1321-
1322-
for (int i = 0; i < 10; i++)
1323-
{
1324-
entry = model.NextAcceptedCommand(ConcreteCommandPath(kMockEndpoint2, MockClusterId(3), 10));
1325-
EXPECT_FALSE(entry.path.HasValidIds());
1326-
}
1275+
MetadataList<DataModel::AcceptedCommandEntry> cmds =
1276+
model.AcceptedCommands(ConcreteClusterPath(kMockEndpoint2, MockClusterId(2)));
1277+
ASSERT_EQ(cmds.size(), 3u);
1278+
ASSERT_EQ(cmds[0].commandId, 1u);
1279+
ASSERT_EQ(cmds[1].commandId, 2u);
1280+
ASSERT_EQ(cmds[2].commandId, 23u);
13271281
}
13281282

13291283
TEST_F(TestCodegenModelViaMocks, AcceptedCommandInfo)
@@ -1370,12 +1324,11 @@ TEST_F(TestCodegenModelViaMocks, IterateOverGeneratedCommands)
13701324
ASSERT_TRUE(model.GeneratedCommands(ConcreteClusterPath(kMockEndpoint1, kInvalidClusterId)).empty());
13711325

13721326
// should be able to iterate over valid paths
1373-
1374-
MetadataList<CommandId> cmds = model.GeneratedCommands(ConcreteClusterPath(kMockEndpoint2, MockClusterId(2)));
1327+
MetadataList<CommandId> cmds = model.GeneratedCommands(ConcreteClusterPath(kMockEndpoint2, MockClusterId(2)));
13751328
const CommandId expectedCommands2[] = { 2, 10 };
13761329
ASSERT_TRUE(cmds.GetSpanValidForLifetime().data_equal(Span<const CommandId>(expectedCommands2)));
13771330

1378-
cmds = model.GeneratedCommands(ConcreteClusterPath(kMockEndpoint2, MockClusterId(3)));
1331+
cmds = model.GeneratedCommands(ConcreteClusterPath(kMockEndpoint2, MockClusterId(3)));
13791332
const CommandId expectedCommands3[] = { 4, 6 };
13801333
ASSERT_TRUE(cmds.GetSpanValidForLifetime().data_equal(Span<const CommandId>(expectedCommands3)));
13811334
}
@@ -1392,43 +1345,31 @@ TEST_F(TestCodegenModelViaMocks, CommandHandlerInterfaceAcceptedCommands)
13921345

13931346
// At this point, without overrides, there should be no accepted/generated commands
13941347
ASSERT_TRUE(model.GeneratedCommands(ConcreteClusterPath(kMockEndpoint1, MockClusterId(1))).empty());
1395-
EXPECT_FALSE(model.FirstAcceptedCommand(ConcreteClusterPath(kMockEndpoint1, MockClusterId(1))).IsValid());
1396-
EXPECT_FALSE(model.GetAcceptedCommandInfo(ConcreteCommandPath(kMockEndpoint1, MockClusterId(1), 1234)).has_value());
1348+
ASSERT_TRUE(model.AcceptedCommands(ConcreteClusterPath(kMockEndpoint1, MockClusterId(1))).empty());
13971349

13981350
handler.SetOverrideAccepted(true);
13991351
handler.SetOverrideGenerated(true);
14001352

14011353
// with overrides, the list is still empty ...
1402-
EXPECT_FALSE(model.FirstAcceptedCommand(ConcreteClusterPath(kMockEndpoint1, MockClusterId(1))).IsValid());
1403-
EXPECT_FALSE(model.GetAcceptedCommandInfo(ConcreteCommandPath(kMockEndpoint1, MockClusterId(1), 1234)).has_value());
1354+
ASSERT_TRUE(model.GeneratedCommands(ConcreteClusterPath(kMockEndpoint1, MockClusterId(1))).empty());
1355+
ASSERT_TRUE(model.AcceptedCommands(ConcreteClusterPath(kMockEndpoint1, MockClusterId(1))).empty());
14041356

14051357
// set some overrides
14061358
handler.AcceptedVec().push_back(1234);
14071359
handler.AcceptedVec().push_back(999);
14081360

14091361
handler.GeneratedVec().push_back(33);
14101362

1411-
DataModel::CommandEntry entry;
1412-
1413-
entry = model.FirstAcceptedCommand(ConcreteClusterPath(kMockEndpoint1, MockClusterId(1)));
1414-
EXPECT_TRUE(entry.IsValid());
1415-
EXPECT_EQ(entry.path, ConcreteCommandPath(kMockEndpoint1, MockClusterId(1), 1234));
1363+
MetadataList<DataModel::AcceptedCommandEntry> acceptedCommands =
1364+
model.AcceptedCommands(ConcreteClusterPath(kMockEndpoint1, MockClusterId(1)));
14161365

1417-
entry = model.NextAcceptedCommand(entry.path);
1418-
EXPECT_TRUE(entry.IsValid());
1419-
EXPECT_EQ(entry.path, ConcreteCommandPath(kMockEndpoint1, MockClusterId(1), 999));
1366+
ASSERT_EQ(acceptedCommands.size(), 2u);
1367+
ASSERT_EQ(acceptedCommands[0].commandId, 1234u);
1368+
ASSERT_EQ(acceptedCommands[1].commandId, 999u);
14201369

1421-
entry = model.NextAcceptedCommand(entry.path);
1422-
EXPECT_FALSE(entry.IsValid());
1423-
1424-
MetadataList<CommandId> generatedCommands = model.GeneratedCommands(ConcreteClusterPath(kMockEndpoint1, MockClusterId(1)));
1425-
const CommandId expectedGeneratedCommands[] = { 33};
1370+
MetadataList<CommandId> generatedCommands = model.GeneratedCommands(ConcreteClusterPath(kMockEndpoint1, MockClusterId(1)));
1371+
const CommandId expectedGeneratedCommands[] = { 33 };
14261372
ASSERT_TRUE(generatedCommands.GetSpanValidForLifetime().data_equal(Span<const CommandId>(expectedGeneratedCommands)));
1427-
1428-
// Command finding should work
1429-
EXPECT_TRUE(model.GetAcceptedCommandInfo(ConcreteCommandPath(kMockEndpoint1, MockClusterId(1), 1234)).has_value());
1430-
EXPECT_FALSE(model.GetAcceptedCommandInfo(ConcreteCommandPath(kMockEndpoint1, MockClusterId(1), 88)).has_value());
1431-
EXPECT_FALSE(model.GetAcceptedCommandInfo(ConcreteCommandPath(kMockEndpoint1, MockClusterId(1), 33)).has_value());
14321373
}
14331374

14341375
TEST_F(TestCodegenModelViaMocks, ReadForInvalidGlobalAttributePath)

0 commit comments

Comments
 (0)