mirror of
https://github.com/Sani7/remote-ui.git
synced 2026-10-26 21:51:13 +01:00
Tests for UI tabe
Adds functionality to retrieve an item from the UI table. Also adds tests for the UI table functionality, including serialization, label setting, item insertion, and item clearing.
This commit is contained in:
@@ -120,6 +120,17 @@ void UI_table::insert_item(size_t row, size_t column, std::string text)
|
||||
emit ui_changed();
|
||||
}
|
||||
|
||||
std::string UI_table::item(size_t row, size_t column) const
|
||||
{
|
||||
if (m_column_count <= column || m_row_count <= row)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
size_t index = row * m_column_count + column;
|
||||
|
||||
return m_table.at(index);
|
||||
}
|
||||
|
||||
void UI_table::empty_item(size_t row, size_t column)
|
||||
{
|
||||
size_t index = row * m_column_count + column;
|
||||
|
||||
@@ -22,6 +22,7 @@ class UI_table : public UI_item
|
||||
std::string column_label(size_t index) const;
|
||||
|
||||
void insert_item(size_t row, size_t column, std::string text);
|
||||
std::string item(size_t row, size_t column) const;
|
||||
|
||||
/**
|
||||
* @brief empty_item This function clears the item and makes it invalid
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#include "ui_table.hpp"
|
||||
#include <QSignalSpy>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(UI_table, to_from_json)
|
||||
{
|
||||
UI_table table(3, 3, {"R1", "R2", "R3"}, {"C1", "C2", "C3"});
|
||||
json j = table.to_json(0);
|
||||
UI_table table2;
|
||||
table2.from_json(j);
|
||||
EXPECT_EQ(table2.row_count(), 3);
|
||||
EXPECT_EQ(table2.column_count(), 3);
|
||||
EXPECT_EQ(table2.row_label(0), "R1");
|
||||
EXPECT_EQ(table2.row_label(1), "R2");
|
||||
EXPECT_EQ(table2.row_label(2), "R3");
|
||||
EXPECT_EQ(table2.column_label(0), "C1");
|
||||
EXPECT_EQ(table2.column_label(1), "C2");
|
||||
EXPECT_EQ(table2.column_label(2), "C3");
|
||||
}
|
||||
|
||||
TEST(UI_table, set_row_column_labels)
|
||||
{
|
||||
UI_table table(2, 2, {"R1", "R2"}, {"C1", "C2"});
|
||||
QSignalSpy spy_ui(&table, &UI_table::ui_changed);
|
||||
table.set_row_label(0, "New R1");
|
||||
EXPECT_EQ(table.row_label(0), "New R1");
|
||||
table.set_row_label(1, "New R2");
|
||||
EXPECT_EQ(table.row_label(1), "New R2");
|
||||
table.set_column_label(0, "New C1");
|
||||
EXPECT_EQ(table.column_label(0), "New C1");
|
||||
table.set_column_label(1, "New C2");
|
||||
EXPECT_EQ(table.column_label(1), "New C2");
|
||||
EXPECT_EQ(spy_ui.count(), 4);
|
||||
}
|
||||
|
||||
TEST(UI_table, insert_item)
|
||||
{
|
||||
UI_table table(3, 3, {"R1", "R2", "R3"}, {"C1", "C2", "C3"});
|
||||
QSignalSpy spy_ui(&table, &UI_table::ui_changed);
|
||||
table.insert_item(0, 0, "Item 1");
|
||||
table.insert_item(1, 1, "Item 2");
|
||||
table.insert_item(2, 2, "Item 3");
|
||||
EXPECT_EQ(spy_ui.count(), 3);
|
||||
EXPECT_EQ(table.item(0, 0), "Item 1");
|
||||
EXPECT_EQ(table.item(1, 1), "Item 2");
|
||||
EXPECT_EQ(table.item(2, 2), "Item 3");
|
||||
}
|
||||
|
||||
TEST(UI_table, empty_item)
|
||||
{
|
||||
UI_table table(2, 2, {"R1", "R2"}, {"C1", "C2"});
|
||||
QSignalSpy spy_ui(&table, &UI_table::ui_changed);
|
||||
table.insert_item(0, 0, "Item 1");
|
||||
table.insert_item(1, 1, "Item 2");
|
||||
EXPECT_EQ(spy_ui.count(), 2);
|
||||
table.empty_item(0, 0);
|
||||
EXPECT_EQ(table.item(0, 0), "");
|
||||
table.empty_item(1, 1);
|
||||
EXPECT_EQ(table.item(1, 1), "");
|
||||
EXPECT_EQ(spy_ui.count(), 4);
|
||||
}
|
||||
Reference in New Issue
Block a user