mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
initial tests
This commit is contained in:
@@ -15,6 +15,7 @@ target_compile_options(tests PRIVATE $<$<CONFIG:Debug>:
|
|||||||
>)
|
>)
|
||||||
target_link_libraries(tests
|
target_link_libraries(tests
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
UI
|
||||||
gtest
|
gtest
|
||||||
GTest::gtest_main
|
GTest::gtest_main
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
#include "gtest/gtest.h"
|
||||||
|
#include "UI.hpp"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#define UNUSED(x) (void)(x)
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#include "Test.hpp"
|
||||||
|
|
||||||
|
TEST(UI_button, to_from_json)
|
||||||
|
{
|
||||||
|
UI_button button("button_id", "button_text", Color(255, 255, 255), Color(0, 0, 0), nullptr);
|
||||||
|
json j = button.to_json();
|
||||||
|
UI_button button2(j);
|
||||||
|
EXPECT_EQ(button.id(), button2.id());
|
||||||
|
EXPECT_EQ(button.text(), button2.text());
|
||||||
|
EXPECT_EQ(button.fg_color(), button2.fg_color());
|
||||||
|
EXPECT_EQ(button.bg_color(), button2.bg_color());
|
||||||
|
|
||||||
|
std::cout << j.dump(4) << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void on_click(std::string id)
|
||||||
|
{
|
||||||
|
UNUSED(id);
|
||||||
|
EXPECT_EQ(id, "button_id");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UI_button, on_click)
|
||||||
|
{
|
||||||
|
UI_button button("button_id", "button_text", Color(255, 255, 255), Color(0, 0, 0), on_click);
|
||||||
|
button.click();
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
#include "Test.hpp"
|
||||||
|
|
||||||
|
TEST(UI_item, is_type)
|
||||||
|
{
|
||||||
|
UI_item item(std::string("item"));
|
||||||
|
json j = {{"type", "item"}};
|
||||||
|
EXPECT_TRUE(item.is_type(j));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UI_item, set_text)
|
||||||
|
{
|
||||||
|
UI_item item(std::string("item"));
|
||||||
|
item.set_text("text");
|
||||||
|
EXPECT_EQ(item.text(), "text");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UI_item, text_size)
|
||||||
|
{
|
||||||
|
UI_item item(std::string("item"));
|
||||||
|
item.set_text_size(12);
|
||||||
|
EXPECT_EQ(item.text_size(), 12);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UI_item, set_fg_color)
|
||||||
|
{
|
||||||
|
UI_item item(std::string("item"));
|
||||||
|
item.set_fg_color(Color(0, 0, 0));
|
||||||
|
EXPECT_EQ(item.fg_color(), Color(0, 0, 0));
|
||||||
|
|
||||||
|
item.set_fg_color(Color(255, 255, 255));
|
||||||
|
EXPECT_EQ(item.fg_color(), Color(255, 255, 255));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UI_item, set_bg_color)
|
||||||
|
{
|
||||||
|
UI_item item(std::string("item"));
|
||||||
|
item.set_bg_color(Color(0, 0, 0));
|
||||||
|
EXPECT_EQ(item.bg_color(), Color(0, 0, 0));
|
||||||
|
|
||||||
|
item.set_bg_color(Color(255, 255, 255));
|
||||||
|
EXPECT_EQ(item.bg_color(), Color(255, 255, 255));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UI_item, from_json)
|
||||||
|
{
|
||||||
|
UI_item item(std::string("item"));
|
||||||
|
json j;
|
||||||
|
j["type"] = "item";
|
||||||
|
j["id"] = "item_id";
|
||||||
|
j["text"] = "item_text";
|
||||||
|
j["text_size"] = 12;
|
||||||
|
j["fg_color"] = "0xFFFFFF00";
|
||||||
|
j["bg_color"] = "0x00000000";
|
||||||
|
|
||||||
|
item.from_json(j);
|
||||||
|
EXPECT_EQ(item.id(), "item_id");
|
||||||
|
EXPECT_EQ(item.text(), "item_text");
|
||||||
|
EXPECT_EQ(item.text_size(), 12);
|
||||||
|
EXPECT_EQ(item.fg_color(), Color(255, 255, 255));
|
||||||
|
EXPECT_EQ(item.bg_color(), Color(0, 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UI_item, to_json)
|
||||||
|
{
|
||||||
|
UI_item item("item_id", "item", "item_text", 12, Color(255, 255, 255), Color(0, 0, 0));
|
||||||
|
json j = item.to_json();
|
||||||
|
EXPECT_EQ(j.at("type"), "item");
|
||||||
|
EXPECT_EQ(j.at("id"), "item_id");
|
||||||
|
EXPECT_EQ(j.at("text"), "item_text");
|
||||||
|
EXPECT_EQ(j.at("text_size"), 12);
|
||||||
|
EXPECT_EQ(j.at("fg_color"), Color(255, 255, 255).to_hex());
|
||||||
|
EXPECT_EQ(j.at("bg_color"), Color(0, 0, 0).to_hex());
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#include "Test.hpp"
|
||||||
|
|
||||||
|
TEST(UI_label, to_from_json)
|
||||||
|
{
|
||||||
|
UI_label label(std::string("label"), std::string("label_text"), Color(0, 0, 0), Color(255, 255, 255));
|
||||||
|
json j = label.to_json();
|
||||||
|
EXPECT_EQ(j["type"], "UIlabel");
|
||||||
|
EXPECT_EQ(j["id"], "label");
|
||||||
|
EXPECT_EQ(j["text"], "label_text");
|
||||||
|
EXPECT_EQ(j["text_size"], 12);
|
||||||
|
EXPECT_EQ(j["fg_color"], "0x00000000");
|
||||||
|
EXPECT_EQ(j["bg_color"], "0xFFFFFF00");
|
||||||
|
|
||||||
|
UI_label label2(j);
|
||||||
|
EXPECT_EQ(label2.id(), "label");
|
||||||
|
EXPECT_EQ(label2.text(), "label_text");
|
||||||
|
EXPECT_EQ(label2.text_size(), 12);
|
||||||
|
EXPECT_EQ(label2.fg_color(), Color(0, 0, 0));
|
||||||
|
EXPECT_EQ(label2.bg_color(), Color(255, 255, 255));
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
#include "Test.hpp"
|
||||||
|
|
||||||
|
TEST(UI_slider, to_from_json)
|
||||||
|
{
|
||||||
|
UI_slider slider("slider_id", "slider_text", Color(255, 255, 255), Color(0, 0, 0), 0, 100, 50, nullptr);
|
||||||
|
json j = slider.to_json();
|
||||||
|
UI_slider slider2(j);
|
||||||
|
EXPECT_EQ(slider.id(), slider2.id());
|
||||||
|
EXPECT_EQ(slider.text(), slider2.text());
|
||||||
|
EXPECT_EQ(slider.fg_color(), slider2.fg_color());
|
||||||
|
EXPECT_EQ(slider.bg_color(), slider2.bg_color());
|
||||||
|
EXPECT_EQ(slider.value(), slider2.value());
|
||||||
|
}
|
||||||
|
|
||||||
|
static double val = 0;
|
||||||
|
void on_change(std::string id, double value)
|
||||||
|
{
|
||||||
|
EXPECT_EQ(id, "slider_id");
|
||||||
|
val = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UI_slider, set_value)
|
||||||
|
{
|
||||||
|
UI_slider slider("slider_id", "slider_text", Color(255, 255, 255), Color(0, 0, 0), 0, 100, 50, on_change);
|
||||||
|
slider.set_value(75);
|
||||||
|
EXPECT_EQ(val, 75);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(UI_slider, value)
|
||||||
|
{
|
||||||
|
UI_slider slider("slider_id", "slider_text", Color(255, 255, 255), Color(0, 0, 0), 0, 100, 50, on_change);
|
||||||
|
EXPECT_EQ(slider.value(), 50);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user