Skip to content

Commit

Permalink
[test-tree-container.cpp] some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherlam committed Aug 19, 2023
1 parent c63a776 commit 90cfc55
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 1 deletion.
20 changes: 19 additions & 1 deletion gnucash/gnome-utils/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,31 @@ set(test_autoclear_LIBS
gtest
)

set(test_tree_container_SOURCES
test-tree-container.cpp
)

set(test_tree_container_INCLUDE_DIRS
)

set(test_tree_container_LIBS
gnc-gnome-utils
gtest
)

gnc_add_test(test-autoclear "${test_autoclear_SOURCES}"
test_autoclear_INCLUDE_DIRS
test_autoclear_LIBS
)

gnc_add_test(test-tree-container "${test_tree_container_SOURCES}"
test_tree_container_INCLUDE_DIRS
test_tree_container_LIBS
)

gnc_add_scheme_tests(test-load-gnome-utils-module.scm)


set_dist_list(test_gnome_utils_DIST CMakeLists.txt test-gnc-recurrence.c test-load-gnome-utils-module.scm
${test_autoclear_SOURCES})
${test_autoclear_SOURCES}
${test_tree_container_SOURCES})
73 changes: 73 additions & 0 deletions gnucash/gnome-utils/test/test-tree-container.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/********************************************************************
* test-assistant-stock-transaction.cpp: *
* Copyright 2023 Christopher Lam *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, you can retrieve it from *
* https://www.gnu.org/licenses/old-licenses/gpl-2.0.html *
* or contact: *
* *
* Free Software Foundation Voice: +1-617-542-5942 *
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
* Boston, MA 02110-1301, USA [email protected] *
********************************************************************/
#include "config.h"
#include <glib.h>
#include <gtk/gtk.h>
#include "../gnc-tree-container.hpp"
#include <gtest/gtest.h>
#include <string>

enum {
COLUMN_STRING,
COLUMN_INT,
COLUMN_BOOLEAN,
N_COLUMNS
};

TEST(GncTreeContainer, Basic) {
if (!gtk_init_check (nullptr, nullptr))
std::cout << "no display present!" << std::endl;

std::cout << "Init successful" << '\n';

auto store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN);
GncTreeContainer container{GTK_TREE_MODEL(store)};

// test empty
EXPECT_TRUE (container.empty());

for (size_t i = 0; i < 10; i++)
{
auto str = std::string("string ") + std::to_string(i);
auto iter = container.append ();
gtk_list_store_set (store, &iter->get_iter(),
COLUMN_STRING, str.c_str(),
COLUMN_INT, i,
COLUMN_BOOLEAN, false,
-1);
}

// test non-empty
EXPECT_EQ(false, container.empty());

EXPECT_TRUE (10 == container.size());

auto is_five = [](auto it){ return it.get_int(COLUMN_INT) == 5; };
auto iter = std::find_if (container.begin(), container.end(), is_five);
EXPECT_FALSE (iter == container.end());
EXPECT_EQ ("string 5", iter->get_string (COLUMN_STRING));

g_object_unref (store);
std::cout << "Tests complete" << '\n';
}

0 comments on commit 90cfc55

Please sign in to comment.