Skip to content

Commit

Permalink
Formatted using Clang.
Browse files Browse the repository at this point in the history
Added test for GetMumeMonth(QString) in testclock.
  • Loading branch information
Mattias-Viklund committed Feb 3, 2024
1 parent 6e81d3a commit 06f2a9b
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 13 deletions.
3 changes: 1 addition & 2 deletions src/clock/mumeclock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,7 @@ MumeClock::DawnDusk MumeClock::getDawnDusk(const int month)
return DawnDusk{s_dawnHour.at(m), s_duskHour.at(m)};
}


const int MumeClock::getMumeMonth(const QString& monthName)
int MumeClock::getMumeMonth(const QString &monthName)
{
const int month = s_westronMonthNames.keyToValue(monthName.toLatin1().data());
if (month == static_cast<int>(WestronMonthNamesEnum::UnknownWestronMonth)) {
Expand Down
2 changes: 1 addition & 1 deletion src/clock/mumeclock.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public slots:
void setPrecision(const MumeClockPrecisionEnum state);
void setLastSyncEpoch(int64_t epoch) { m_lastSyncEpoch = epoch; }

const int getMumeMonth(const QString &monthName);
int getMumeMonth(const QString &monthName);

protected:
void parseMumeTime(const QString &mumeTime, int64_t secsSinceEpoch);
Expand Down
1 change: 0 additions & 1 deletion src/proxy/AbstractTelnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,6 @@ void AbstractTelnet::processTelnetSubnegotiation(const AppendBuffer &payload)
qDebug() << "Received MSSP message" << payload;

receiveMudServerStatus(payload);

}
break;

Expand Down
1 change: 0 additions & 1 deletion src/proxy/MudTelnet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,5 +301,4 @@ void MudTelnet::parseMudServerStatus(const QByteArray &data)

Check notice on line 301 in src/proxy/MudTelnet.cpp

View check run for this annotation

codefactor.io / CodeFactor

src/proxy/MudTelnet.cpp#L301

Redundant blank line at the end of a code block should be deleted. (whitespace/blank_line)
} catch (const std::exception &) {
} // ?

}
6 changes: 3 additions & 3 deletions src/proxy/MudTelnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public slots:
void sig_relayGmcp(const GmcpMessage &);
void sig_sendMSSPToUser(const QByteArray &);
void sig_sendGameTimeToClock(const int year,
const std::string &month,
const int day,
const int hour);
const std::string &month,
const int day,
const int hour);

private:
void virt_sendToMapper(const QByteArray &data, bool goAhead) final;
Expand Down
10 changes: 5 additions & 5 deletions src/proxy/proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ void Proxy::slot_start()
connect(mudTelnet, &MudTelnet::sig_sendToSocket, this, &Proxy::slot_onSendToMudSocket);
connect(mudTelnet, &MudTelnet::sig_relayEchoMode, userTelnet, &UserTelnet::slot_onRelayEchoMode);
connect(mudTelnet, &MudTelnet::sig_relayGmcp, userTelnet, &UserTelnet::slot_onGmcpToUser);
connect(mudTelnet, &MudTelnet::sig_sendGameTimeToClock,
connect(mudTelnet,
&MudTelnet::sig_sendGameTimeToClock,
this,
&Proxy::slot_onSendGameTimeToClock);
connect(mudTelnet,
Expand Down Expand Up @@ -575,13 +576,12 @@ bool Proxy::isGmcpModuleEnabled(const GmcpModuleTypeEnum &module) const
}

void Proxy::slot_onSendGameTimeToClock(const int year,
const std::string &monthStr,
const int day,
const int hour)
const std::string &monthStr,
const int day,
const int hour)
{
const int month = m_mumeClock.getMumeMonth(::toQStringLatin1(monthStr));
MumeMoment moment(year, month, day, hour, 0);
QString mumeTime = m_mumeClock.toMumeTime(moment);
m_mumeClock.parseMumeTime(mumeTime);

}
54 changes: 54 additions & 0 deletions tests/testclock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,60 @@ void TestClock::parseMumeTimeTest()
QCOMPARE(clock.toMumeTime(clock.getMumeMoment()), expected6);
}

void TestClock::getMumeMonthTest()
{
GameObserver observer;
MumeClock clock(observer);

int month0 = clock.getMumeMonth("Narwain");
int expected0 = 0;
QCOMPARE(month0, expected0);

int month1 = clock.getMumeMonth("Solmath");
int expected1 = 1;
QCOMPARE(month1, expected1);

int month2 = clock.getMumeMonth("Gwaeron");
int expected2 = 2;
QCOMPARE(month2, expected2);

int month3 = clock.getMumeMonth("Astron");
int expected3 = 3;
QCOMPARE(month3, expected3);

int month4 = clock.getMumeMonth("Lothron");
int expected4 = 4;
QCOMPARE(month4, expected4);

int month5 = clock.getMumeMonth("Forelithe");
int expected5 = 5;
QCOMPARE(month5, expected5);

int month6 = clock.getMumeMonth("Cerveth");
int expected6 = 6;
QCOMPARE(month6, expected6);

int month7 = clock.getMumeMonth("Wedmath");
int expected7 = 7;
QCOMPARE(month7, expected7);

int month8 = clock.getMumeMonth("Ivanneth");
int expected8 = 8;
QCOMPARE(month8, expected8);

int month9 = clock.getMumeMonth("Winterfilth");
int expected9 = 9;
QCOMPARE(month9, expected9);

int month10 = clock.getMumeMonth("Hithui");
int expected10 = 10;
QCOMPARE(month10, expected10);

int month11 = clock.getMumeMonth("Foreyule");
int expected11 = 11;
QCOMPARE(month11, expected11);
}

void TestClock::parseWeatherClockSkewTest()
{
GameObserver observer;
Expand Down
1 change: 1 addition & 0 deletions tests/testclock.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ private Q_SLOTS:
// MumeClock
void mumeClockTest();
void parseMumeTimeTest();
void getMumeMonthTest();
void parseWeatherTest();
void parseWeatherClockSkewTest();
void parseClockTimeTest();
Expand Down

0 comments on commit 06f2a9b

Please sign in to comment.