Commit 7bf79ce2 authored by Adrien Oliva's avatar Adrien Oliva

Add tests for all kind of clicks

parent a788ba72
Pipeline #121 passed with stages
in 1 minute and 13 seconds
......@@ -57,13 +57,13 @@ TEST(initial_setup, other_pin_mode)
f.set_expected_call("pinMode", 1);
};
static void single_click_stub(void *pcounter)
static void click_stub(void *pcounter)
{
int *counter = static_cast<int *>(pcounter);
(*counter)++;
}
TEST_GROUP(single_click_button)
TEST_GROUP(click_button)
{
void setup()
{
......@@ -71,11 +71,17 @@ TEST_GROUP(single_click_button)
f.set_millis(0);
f.set_actual_digital_value(1, HIGH);
expected_counter = 0;
counter = 0;
expected_single_counter = 0;
single_counter = 0;
expected_long_counter = 0;
long_counter = 0;
expected_double_counter = 0;
double_counter = 0;
b = new button_t(1);
b->on_single_click(single_click_stub, &counter);
b->on_single_click(click_stub, &single_counter);
b->on_long_click(click_stub, &long_counter);
b->on_double_click(click_stub, &double_counter);
}
void teardown()
......@@ -84,16 +90,22 @@ TEST_GROUP(single_click_button)
delete b;
LONGS_EQUAL(expected_counter, counter);
LONGS_EQUAL(expected_single_counter, single_counter);
LONGS_EQUAL(expected_long_counter, long_counter);
LONGS_EQUAL(expected_double_counter, double_counter);
}
fixtures f;
button_t *b;
int counter;
int expected_counter;
int long_counter;
int single_counter;
int double_counter;
int expected_long_counter;
int expected_single_counter;
int expected_double_counter;
};
TEST(single_click_button, no_press)
TEST(click_button, no_press)
{
for (int i = 0; i < 10001; i+= 100) {
f.set_micros(i);
......@@ -101,7 +113,7 @@ TEST(single_click_button, no_press)
}
}
TEST(single_click_button, one_click)
TEST(click_button, one_click)
{
b->loop();
f.set_millis(100);
......@@ -115,10 +127,10 @@ TEST(single_click_button, one_click)
f.set_millis(600);
b->loop();
expected_counter = 1;
expected_single_counter = 1;
}
TEST(single_click_button, long_click)
TEST(click_button, long_click)
{
b->loop();
f.set_millis(100);
......@@ -131,9 +143,11 @@ TEST(single_click_button, long_click)
b->loop();
f.set_millis(2900);
b->loop();
expected_long_counter = 1;
}
TEST(single_click_button, double_click)
TEST(click_button, double_click)
{
b->loop();
f.set_millis(100);
......@@ -152,9 +166,11 @@ TEST(single_click_button, double_click)
b->loop();
f.set_millis(1000);
b->loop();
expected_double_counter = 1;
}
TEST(single_click_button, ten_click_every_seconds)
TEST(click_button, ten_click_every_seconds)
{
b->loop();
for (int i = 0; i < 10; i++) {
......@@ -168,11 +184,56 @@ TEST(single_click_button, ten_click_every_seconds)
b->loop();
f.set_millis(i * 1000 + 600);
b->loop();
LONGS_EQUAL(i + 1, counter);
LONGS_EQUAL(i + 1, single_counter);
}
expected_single_counter = 10;
}
TEST(click_button, ten_long_click_every_ten_seconds)
{
b->loop();
for (int i = 0; i < 10; i++) {
f.set_millis(i * 10000 + 100);
f.set_actual_digital_value(1, LOW);
b->loop();
f.set_millis(i * 10000 + 2500);
f.set_actual_digital_value(1, HIGH);
b->loop();
f.set_millis(i * 10000 + 4000);
b->loop();
f.set_millis(i * 10000 + 6000);
b->loop();
LONGS_EQUAL(i + 1, long_counter);
}
expected_counter = 10;
expected_long_counter = 10;
}
TEST(click_button, ten_double_click_every_second)
{
b->loop();
for (int i = 0; i < 10; i++) {
f.set_millis(i * 1000 + 100);
f.set_actual_digital_value(1, LOW);
b->loop();
f.set_millis(i * 1000 + 200);
f.set_actual_digital_value(1, HIGH);
b->loop();
f.set_millis(i * 1000 + 400);
f.set_actual_digital_value(1, LOW);
b->loop();
f.set_millis(i * 1000 + 600);
f.set_actual_digital_value(1, HIGH);
b->loop();
f.set_millis(i * 1000 + 800);
b->loop();
f.set_millis(i * 1000 + 1000);
b->loop();
LONGS_EQUAL(i + 1, double_counter);
}
expected_double_counter = 10;
}
#endif /* end of include guard: UT_BUTTON_H_VPZWRLC7 */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment