[gnome-commander/googletest] Adds iv_inputmodes tests to googletest framework



commit 74bb95696e1c75097d70c22a4a9633c3fa0655e5
Author: Uwe Scholz <uwescholz src gnome org>
Date:   Wed Nov 25 21:13:12 2015 +0100

    Adds iv_inputmodes tests to googletest framework

 tests/Makefile.am           |    2 +-
 tests/iv_inputmodes_test.cc |  173 ++++++++++---------------------------------
 2 files changed, 39 insertions(+), 136 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index afda0cd..156ef5d 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -34,7 +34,7 @@ iv_imagerenderer_SOURCES = iv_imagerenderer_test.cc gcmd_tests_main.cc
 iv_imagerenderer_CXXFLAGS = $(INTVLIBS)
 iv_imagerenderer_LDFLAGS = $(INTVLIBS) -lgtest
 
-iv_inputmodes_SOURCES = iv_inputmodes_test.cc
+iv_inputmodes_SOURCES = iv_inputmodes_test.cc gcmd_tests_main.cc
 iv_inputmodes_CXXFLAGS = $(INTVLIBS)
 iv_inputmodes_LDFLAGS = $(INTVLIBS) -lgtest
 
diff --git a/tests/iv_inputmodes_test.cc b/tests/iv_inputmodes_test.cc
index f581a41..8511b5b 100644
--- a/tests/iv_inputmodes_test.cc
+++ b/tests/iv_inputmodes_test.cc
@@ -1,145 +1,48 @@
-/*
-  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
-
-  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, write to the Free Software
-  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
-
-   Author: Assaf Gordon  <agordon88 gmail com>
-*/
-
-#include <glib.h>
-#include <stdio.h>
-#include <stdlib.h>
+/**
+ * @file iv_inputmodes_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 the input mode module in libgviewer.
+ * Possible values: ASCII, CP437, UTF8 and all other encodings readable
+ * by the iconv library. Currently you will find only a very simple,
+ * nearly meaningless test. Many other tests of this module are missing.
+ *
+ * @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>
-#include <intviewer/gvtypes.h>
-#include <intviewer/fileops.h>
-#include <intviewer/inputmodes.h>
-
-static offset_type start;
-static offset_type end;
-static gchar *filename = NULL;
-static gchar *input_mode = NULL;
-static ViewerFileOps *fops = NULL;
-static GVInputModesData *imd = NULL;
-
-void usage()
-{
-    fprintf(stderr,"This program tests the input mode module in 'libgviewer'.\n\n");
-
-    fprintf(stderr,"Usage: test-inputmodes mode filename [start_offset] [end_offset]\n");
-    fprintf(stderr,"\t'filename' will be printed to STDOUT, always in UTF-8 encoding.\n");
-    fprintf(stderr,"\t'start_offset' and 'end_offset' are optinal.\n\n");
-    fprintf(stderr,"\tmode = input mode. possible values:\n");
-    fprintf(stderr,"\tASCII\n\tCP437\n\tUTF8\n\tAnd all other encodings readable by Iconv library.\n");
-    exit(0);
-}
-
-void parse_command_line(int argc, char *argv[])
-{
-    if (argc<3)
-        usage();
 
-    input_mode = g_strdup(argv[1]);
-    filename = g_strdup(argv[2]);
+class ViewerInputModeTest : public ::testing::TestWithParam<const char *> {};
 
-    if (argc>3)
-        start = atol(argv[3]);
-    else
-        start = 0;
-
-    if (argc>4)
-        end = atol(argv[4]);
-    else
-        end = -1;
-}
+INSTANTIATE_TEST_CASE_P(InstantiationScaleFactor,
+                        ViewerInputModeTest,
+                        ::testing::Values("ASCII", "UTF8", "CP437", "CP1251"));
 
-int init()
+TEST_P(ViewerInputModeTest, gv_set_input_mode_test)
 {
-    fops = gv_fileops_new();
-
-    if (gv_file_open(fops, filename)==-1) {
-        fprintf(stderr,"Failed to open \"%s\"\n", filename);
-        return -1;
-    }
-
-    if (end==-1)
-        end = gv_file_get_max_offset(fops);
-
+    GVInputModesData *imd = NULL;
     imd = gv_input_modes_new();
-    gv_init_input_modes(imd, (get_byte_proc)gv_file_get_byte, fops);
 
-    gv_set_input_mode(imd,input_mode);
+    gv_set_input_mode(imd, GetParam());
+    ASSERT_STREQ(GetParam(), gv_get_input_mode(imd));
 
-    return 0;
-}
-
-void cleanup()
-{
-    g_free(filename);
-    g_free(input_mode);
-
-    if (fops)
-        gv_file_free(fops);
-    g_free(fops);
-
-    if (imd)
-        gv_free_input_modes(imd);
+    gv_free_input_modes(imd);
     g_free(imd);
 }
-
-int main(int argc, char *argv[])
-{
-    offset_type current;
-    char_type value;
-
-    parse_command_line(argc,argv);
-
-    if (init()==-1)
-        goto error;
-
-
-    current = start;
-    while (current < end) {
-        /* Read a UTF8 character from the input file.
-           The "inputmode" module is responsible for converting the file into UTF8 */
-        value = gv_input_mode_get_utf8_char(imd, current);
-        if (value==INVALID_CHAR)
-            break;
-
-        // move to the next character's offset
-        current = gv_input_get_next_char_offset(imd,current);
-
-        // value is UTF-8 character, packed into 32bits
-        printf("%c", GV_FIRST_BYTE(value));
-        if (GV_SECOND_BYTE(value)) {
-            printf("%c", GV_SECOND_BYTE(value));
-
-            if (GV_THIRD_BYTE(value)) {
-                printf("%c", GV_THIRD_BYTE(value));
-
-                if (GV_FOURTH_BYTE(value)) {
-                    printf("%c", GV_FOURTH_BYTE(value));
-                }
-            }
-        }
-    }
-
-
-error:
-    cleanup();
-    return 0;
-}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]