[gnome-commander/googletest] Adds iv_textrenderer tests to googletest framework
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander/googletest] Adds iv_textrenderer tests to googletest framework
- Date: Fri, 27 Nov 2015 22:37:54 +0000 (UTC)
commit c96f89f7b86053818c9bbd35a9db6d56e3ac3228
Author: Uwe Scholz <uwescholz src gnome org>
Date: Fri Nov 27 23:17:35 2015 +0100
Adds iv_textrenderer tests to googletest framework
tests/Makefile.am | 2 +-
tests/iv_textrenderer_test.cc | 241 ++++++++++++++++-------------------------
2 files changed, 97 insertions(+), 146 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 156ef5d..2264def 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -38,7 +38,7 @@ iv_inputmodes_SOURCES = iv_inputmodes_test.cc gcmd_tests_main.cc
iv_inputmodes_CXXFLAGS = $(INTVLIBS)
iv_inputmodes_LDFLAGS = $(INTVLIBS) -lgtest
-iv_textrenderer_SOURCES = iv_textrenderer_test.cc
+iv_textrenderer_SOURCES = iv_textrenderer_test.cc gcmd_tests_main.cc
iv_textrenderer_CXXFLAGS = $(INTVLIBS)
iv_textrenderer_LDFLAGS = $(INTVLIBS) -lgtest
diff --git a/tests/iv_textrenderer_test.cc b/tests/iv_textrenderer_test.cc
index 2f96061..687b08c 100644
--- a/tests/iv_textrenderer_test.cc
+++ b/tests/iv_textrenderer_test.cc
@@ -1,171 +1,122 @@
-/*
- GNOME Commander - A GNOME based file manager
- Copyright (C) 2001-2006 Marcus Bjurman
- Copyright (C) 2007-2012 Piotr Eljasiak
- Copyright (C) 2013-2015 Uwe Scholz
+/**
+ * @file iv_textrenderer_test.cc
+ * @brief Part of GNOME Commander - A GNOME based file manager
+ *
+ * @copyright (C) 2006 Assaf Gordon\n
+ * @copyright (C) 2007-2012 Piotr Eljasiak\n
+ * @copyright (C) 2013-2015 Uwe Scholz\n
+ *
+ * @details This module tests gviewer widget setter functions in libgviewer
+ * for text:
+ * @li Enconding: ASCII, UTF8, CP437, CP1251
+ * @li Display Mode: Text, Binary, Hex, Image
+ * @li Wrapping: TRUE, FALSE
+ * @li Fixed_limit: Sets number of Bytes per line
+ * @li Tab size: Set number of space per TAB character
+ *
+ * @copyright 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.
+ *
+ * @copyright 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.
+ *
+ * @copyright You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "gtest/gtest.h"
+#include <intviewer/libgviewer.h>
- 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.
+const gchar *filename = "../INSTALL";
- 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, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
+class TextRendererDisplayModeTest : public ::testing::TestWithParam<TextRender::DISPLAYMODE> {};
- Author: Assaf Gordon <agordon88 gmail com>
-*/
+INSTANTIATE_TEST_CASE_P(InstantiationScaleFactor,
+ TextRendererDisplayModeTest,
+ ::testing::Values(TextRender::DISPLAYMODE_TEXT,
+ TextRender::DISPLAYMODE_BINARY,
+ TextRender::DISPLAYMODE_HEXDUMP));
-#include <glib.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
+TEST_P(TextRendererDisplayModeTest, text_render_set_display_mode_test)
+{
+ GtkWidget *textr;
+ textr = text_render_new();
+ text_render_load_file(TEXT_RENDER(textr), filename);
+ text_render_set_display_mode(TEXT_RENDER(textr), GetParam());
+ ASSERT_EQ(GetParam(), text_render_get_display_mode(TEXT_RENDER(textr)));
+}
-#include <glib.h>
-#include <gtk/gtk.h>
+////////////////////////////////////////////////////////////////////////
-#include <intviewer/libgviewer.h>
+class TextRendererTabSizeTest : public ::testing::TestWithParam<int> {};
-static gchar *filename = NULL;
-static gchar *encoding = NULL;
-static TextRender::DISPLAYMODE dispmode = TextRender::DISPLAYMODE_TEXT;
-static guint tab_size;
-static guint fixed_limit;
-static gboolean wrap_mode;
+INSTANTIATE_TEST_CASE_P(InstantiationScaleFactor,
+ TextRendererTabSizeTest,
+ ::testing::Range(1,10));
-void usage()
+TEST_P(TextRendererTabSizeTest, text_render_set_tab_size)
{
- fprintf(stderr,"This program tests the text-render widget in 'libgviewer'.\n\n");
+ GtkWidget *textr;
+ textr = text_render_new();
+ text_render_load_file(TEXT_RENDER(textr), filename);
+ text_render_set_tab_size(TEXT_RENDER(textr), GetParam());
+ ASSERT_EQ(GetParam(), text_render_get_tab_size(TEXT_RENDER(textr)));
+}
- fprintf(stderr,"Usage: test-textrenderer [-e encoding] [-d dispmode] [-w] [-f fixed_limit] [-t tab_size]
filename\n\n");
+////////////////////////////////////////////////////////////////////////
- fprintf(stderr,"\t-e enconding: ASCII, UTF8, CP437, CP1251, etc\n");
- fprintf(stderr,"\t-d Display Mode:\n\t Fixed(text)\n\t Binary\n\t Hex\n");
- fprintf(stderr,"\t-w In fixed/variable text displays, turns on wrapping.\n");
- fprintf(stderr,"\t-f fixed_limit: In Binary display mode, sets number of Bytes per line.\n");
- fprintf(stderr,"\t-t tab size: In fixed/variable text displays, set number of space per TAB
character.\n");
- fprintf(stderr,"\tfilename: The file to display.\n");
- exit(0);
-}
+class TextRendererWrapModeTest : public ::testing::TestWithParam<bool> {};
-void parse_command_line(int argc, char *argv[])
-{
- extern char *optarg;
- extern int optind, opterr, optopt;
- int c;
-
- tab_size = 8;
- fixed_limit = 40;
- dispmode = TextRender::DISPLAYMODE_TEXT;
- encoding = g_strdup("ASCII");
- wrap_mode = FALSE;
-
- while ((c=getopt(argc,argv,"d:e:f:t:w")) != -1)
- {
- switch(c)
- {
- case 'w':
- wrap_mode = TRUE;
- break;
-
- case 'e':
- g_free(encoding);
- encoding = g_strdup(optarg);
- break;
-
- case 'd':
- if (g_ascii_strcasecmp(optarg,"fixed")==0)
- dispmode = TextRender::DISPLAYMODE_TEXT;
- else if (g_ascii_strcasecmp(optarg,"binary")==0)
- dispmode = TextRender::DISPLAYMODE_BINARY;
- else if (g_ascii_strcasecmp(optarg,"hex")==0)
- dispmode = TextRender::DISPLAYMODE_HEXDUMP;
- else
- {
- g_warning("Invalid display mode \"%s\".\n", optarg);
- usage();
- }
- break;
-
- case 't':
- tab_size = atoi(optarg);
- if (tab_size <=0)
- {
- g_warning("Invalid tab size \"%s\".\n", optarg);
- usage();
- }
- break;
-
- case 'f':
- fixed_limit = atoi(optarg);
- if (fixed_limit<=0) {
- g_warning("Invalid fixed limit \"%s\".\n", optarg);
- usage();
- }
- break;
-
- default:
- usage();
- break;
- }
- }
-
- if (optind == argc)
- {
- g_warning("Need file name to work with...\n");
- usage();
- }
- filename = g_strdup(argv[optind++]);
-}
+INSTANTIATE_TEST_CASE_P(InstantiationScaleFactor,
+ TextRendererWrapModeTest,
+ ::testing::Bool());
-int main(int argc, char *argv[])
+TEST_P(TextRendererWrapModeTest, gviewer_set_wrap_mode_test)
{
- GtkWidget *window;
- GtkWidget *scrollbox;
GtkWidget *textr;
+ textr = text_render_new();
+ text_render_load_file(TEXT_RENDER(textr), filename);
+ text_render_set_wrap_mode(TEXT_RENDER(textr), GetParam());
+ ASSERT_EQ(GetParam(), text_render_get_wrap_mode(TEXT_RENDER(textr)));
+}
- gtk_init(&argc,&argv);
-
- parse_command_line(argc,argv);
+////////////////////////////////////////////////////////////////////////
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_window_set_position(GTK_WINDOW(window),GTK_WIN_POS_CENTER);
- gtk_widget_set_size_request(window,600,400);
+class TextRendererFixedLimitTest : public ::testing::TestWithParam<int> {};
- scrollbox = scroll_box_new();
+INSTANTIATE_TEST_CASE_P(InstantiationScaleFactor,
+ TextRendererFixedLimitTest,
+ ::testing::Values(1,10));
+TEST_P(TextRendererFixedLimitTest, gviewer_set_set_fixed_limit)
+{
+ GtkWidget *textr;
textr = text_render_new();
+ text_render_load_file(TEXT_RENDER(textr), filename);
+ text_render_set_fixed_limit(TEXT_RENDER(textr), GetParam());
+ ASSERT_EQ(GetParam(), text_render_get_fixed_limit(TEXT_RENDER(textr)));
+}
+
+////////////////////////////////////////////////////////////////////////
- text_render_set_v_adjustment(TEXT_RENDER(textr),
- scroll_box_get_v_adjustment(SCROLL_BOX(scrollbox)));
+class TextRendererSetEncodingTest : public ::testing::TestWithParam<const char *> {};
- text_render_set_h_adjustment(TEXT_RENDER(textr),
- scroll_box_get_h_adjustment(SCROLL_BOX(scrollbox)));
+INSTANTIATE_TEST_CASE_P(InstantiationScaleFactor,
+ TextRendererSetEncodingTest,
+ ::testing::Values("ASCII", "UTF8", "CP437", "CP1251"));
+TEST_P(TextRendererSetEncodingTest, gviewer_set_encoding_test)
+{
+ GtkWidget *textr;
+ textr = text_render_new();
text_render_load_file(TEXT_RENDER(textr), filename);
- text_render_set_display_mode(TEXT_RENDER(textr), dispmode);
- text_render_set_tab_size(TEXT_RENDER(textr), tab_size);
- text_render_set_wrap_mode(TEXT_RENDER(textr), wrap_mode);
- text_render_set_fixed_limit(TEXT_RENDER(textr), fixed_limit);
- text_render_set_encoding(TEXT_RENDER(textr), encoding);
-
- scroll_box_set_client(SCROLL_BOX(scrollbox),textr);
-
- gtk_container_add(GTK_CONTAINER(window), scrollbox);
-
- gtk_widget_show(textr);
- gtk_widget_show(scrollbox);
- gtk_widget_show(window);
-
- while (g_main_context_pending(NULL))
- {
- g_main_context_iteration(NULL, FALSE);
- }
- gtk_widget_destroy (window);
- return 0;
+ text_render_set_encoding(TEXT_RENDER(textr), GetParam());
+ ASSERT_STREQ(GetParam(), text_render_get_encoding(TEXT_RENDER(textr)));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]