Skip to content

Commit

Permalink
Add tests - both failing for now
Browse files Browse the repository at this point in the history
  • Loading branch information
peteGSX committed Dec 9, 2024
1 parent 65b100d commit 5a07a76
Showing 1 changed file with 51 additions and 1 deletion.
52 changes: 51 additions & 1 deletion tests/Roster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,56 @@ TEST_F(DCCEXProtocolTest, getRosterWithThreeIDs) {
EXPECT_CALL(_delegate, receivedRosterList()).Times(Exactly(1));
_dccexProtocol.check();

// Returns true since roster ist complete
// Returns true since roster is complete
EXPECT_TRUE(_dccexProtocol.receivedRoster());
}

TEST_F(DCCEXProtocolTest, createLoco) {
// Create an individual loco
Loco *loco1 = new Loco(1, LocoSource::LocoSourceEntry);
loco1->setName("Loco 1");

// Check address is 1, name is correct, and LocoSource correct
EXPECT_EQ(loco1->getAddress(), 1);
EXPECT_STREQ(loco1->getName(), "Loco 1");
EXPECT_EQ(loco1->getSource(), LocoSource::LocoSourceEntry);

// Ensure next is nullptr as this is the only loco
ASSERT_NE(loco1->getNext(), nullptr);
}

TEST_F(DCCEXProtocolTest, legacyRosterCreation) {
// Roster should start empty
EXPECT_EQ(_dccexProtocol.roster->getFirst(), nullptr);

// Add three locos
Loco *loco42 = new Loco(42, LocoSource::LocoSourceRoster);
loco42->setName("Loco42");
Loco *loco9 = new Loco(9, LocoSource::LocoSourceRoster);
loco9->setName("Loco9");
Loco *loco120 = new Loco(120, LocoSource::LocoSourceRoster);
loco120->setName("Loco120");

// Now verify the roster
Loco* firstLoco = _dccexProtocol.roster->getFirst();
ASSERT_NE(firstLoco, nullptr);

// Check first loco details
EXPECT_EQ(firstLoco->getAddress(), 42);
EXPECT_STREQ(firstLoco->getName(), "Loco42");

// Verify second loco details
Loco* secondLoco = firstLoco->getNext();
ASSERT_NE(secondLoco, nullptr);
EXPECT_EQ(secondLoco->getAddress(), 9);
EXPECT_STREQ(secondLoco->getName(), "Loco9");

// Verify third loco details
Loco *thirdLoco = secondLoco->getNext();
ASSERT_NE(thirdLoco, nullptr);
EXPECT_EQ(thirdLoco->getAddress(), 120);
EXPECT_STREQ(thirdLoco->getName(), "Loco120");

// Verify end of linked list
ASSERT_NE(thirdLoco->getNext(), nullptr);
}

0 comments on commit 5a07a76

Please sign in to comment.