Skip to content

Commit

Permalink
♻️ (stubs): Refactor stubs::mbed::PwmOut
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Nov 27, 2022
1 parent fb3e578 commit f918487
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
14 changes: 7 additions & 7 deletions drivers/CorePwm/tests/CorePwm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TEST(CorePwmTest, initialisation)
auto corepwm = CorePwm {NC};

ASSERT_NE(&corepwm, nullptr);
ASSERT_FALSE(spy_PwmOut_is_suspended);
ASSERT_FALSE(spy_PwmOut_isSuspended());
}

TEST(CorePwmTest, write)
Expand All @@ -23,11 +23,11 @@ TEST(CorePwmTest, write)

corepwm.write(0.5f);

ASSERT_EQ(spy_PwmOut_value, 0.5f);
ASSERT_EQ(spy_PwmOut_getValue(), 0.5f);

corepwm.write(1.0f);

ASSERT_EQ(spy_PwmOut_value, 1.0f);
ASSERT_EQ(spy_PwmOut_getValue(), 1.0f);
}

TEST(CorePwmTest, read)
Expand All @@ -36,7 +36,7 @@ TEST(CorePwmTest, read)

corepwm.write(0.5f);

ASSERT_EQ(spy_PwmOut_value, 0.5f);
ASSERT_EQ(spy_PwmOut_getValue(), 0.5f);

auto val = corepwm.read();

Expand All @@ -49,7 +49,7 @@ TEST(CorePwmTest, suspend)

corepwm.suspend();

ASSERT_TRUE(spy_PwmOut_is_suspended);
ASSERT_TRUE(spy_PwmOut_isSuspended());
}

TEST(CorePwmTest, suspendThenResume)
Expand All @@ -58,9 +58,9 @@ TEST(CorePwmTest, suspendThenResume)

corepwm.suspend();

ASSERT_TRUE(spy_PwmOut_is_suspended);
ASSERT_TRUE(spy_PwmOut_isSuspended());

corepwm.resume();

ASSERT_FALSE(spy_PwmOut_is_suspended);
ASSERT_FALSE(spy_PwmOut_isSuspended());
}
3 changes: 0 additions & 3 deletions tests/unit/stubs/stubs/mbed/PwmOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@

namespace leka {

extern float spy_PwmOut_value;
float spy_PwmOut_getValue();

extern float spy_PwmOut_period;
float spy_PwmOut_getPeriod();

extern bool spy_PwmOut_is_suspended;
bool spy_PwmOut_isSuspended();

} // namespace leka
26 changes: 13 additions & 13 deletions tests/unit/stubs/stubs/mbed/source/PwmOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,63 @@

#include "../PwmOut.h"

namespace {
float spy_PwmOut_value = -42.0f;
float spy_PwmOut_period = -42.0f;
bool spy_PwmOut_is_suspended = true;
} // namespace

namespace mbed {

PwmOut::PwmOut(PinName)
{
leka::spy_PwmOut_is_suspended = false;
spy_PwmOut_is_suspended = false;
}

PwmOut::~PwmOut()
{
leka::spy_PwmOut_is_suspended = true;
spy_PwmOut_is_suspended = true;
}

void PwmOut::write(float value)
{
leka::spy_PwmOut_value = value;
spy_PwmOut_value = value;
}

auto PwmOut::read() -> float
{
return leka::spy_PwmOut_value;
return spy_PwmOut_value;
}

void PwmOut::period(float value)
{
leka::spy_PwmOut_period = value;
spy_PwmOut_period = value;
}

void PwmOut::suspend()
{
leka::spy_PwmOut_is_suspended = true;
spy_PwmOut_is_suspended = true;
}

void PwmOut::resume()
{
leka::spy_PwmOut_is_suspended = false;
spy_PwmOut_is_suspended = false;
}

} // namespace mbed

namespace leka {

float spy_PwmOut_value = -42.0f;

float spy_PwmOut_getValue()
{
return spy_PwmOut_value;
}

float spy_PwmOut_period = -42.0f;

float spy_PwmOut_getPeriod()
{
return spy_PwmOut_period;
}

bool spy_PwmOut_is_suspended = true;

bool spy_PwmOut_isSuspended()
{
return spy_PwmOut_is_suspended;
Expand Down

0 comments on commit f918487

Please sign in to comment.