[gnome-commander/CppUnit] Use CppUnit for the internal viewer fileops test



commit 17af58d9f323b605cafb17057b795c36f1c61414
Author: Uwe Scholz <uwescholz src gnome org>
Date:   Tue Oct 6 22:19:01 2015 +0200

    Use CppUnit for the internal viewer fileops test

 tests/Makefile.am                             |   23 +++++++---
 tests/{intviewer/fileops.cc => iv_fileops.cc} |   35 ++++++++-------
 tests/{intviewer/fileops.cc => iv_fileops.h}  |   61 ++++++++++---------------
 3 files changed, 59 insertions(+), 60 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 2b65c7b..8c99e8f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,13 +1,22 @@
 ## Process this file with automake to produce Makefile.in
 
-SUBDIRS = intviewer
+AM_CPPFLAGS = \
+       $(CC_WARNINGS) \
+       $(GLIB_CFLAGS) \
+       $(GTK_CFLAGS) \
+       $(GNOMEUI_CFLAGS) \
+       -I$(top_builddir)/src
 
--include $(top_srcdir)/git.mk
+INTVLIBS = $(GLIB_LIBS) $(GTK_LIBS) $(GNOMEUI_LIBS) $(top_builddir)/src/intviewer/libgviewer.a
 
 # Rules for the test code (use `make check` to execute)
-TESTS = gcmd_tests
+TESTS = \
+       intviewer_fileops
+
 check_PROGRAMS = $(TESTS)
-gcmd_tests_SOURCES = \
-       gcmd_tests_main.cc
-gcmd_tests_CXXFLAGS = $(CPPUNIT_CFLAGS)
-gcmd_tests_LDFLAGS = $(CPPUNIT_LIBS) -ldl
+
+intviewer_fileops_SOURCES = iv_fileops.cc gcmd_tests_main.cc
+intviewer_fileops_CXXFLAGS = $(INTVLIBS) $(CPPUNIT_CFLAGS)
+intviewer_fileops_LDFLAGS = $(INTVLIBS) $(CPPUNIT_LIBS) -ldl
+
+-include $(top_srcdir)/git.mk
diff --git a/tests/intviewer/fileops.cc b/tests/iv_fileops.cc
similarity index 78%
copy from tests/intviewer/fileops.cc
copy to tests/iv_fileops.cc
index 0ae6685..8d5557a 100644
--- a/tests/intviewer/fileops.cc
+++ b/tests/iv_fileops.cc
@@ -19,14 +19,21 @@
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 */
 
-#include <glib.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <intviewer/libgviewer.h>
-#include <intviewer/gvtypes.h>
-#include <intviewer/fileops.h>
-
-int main(int argc, char *argv[])
+#include "iv_fileops.h"
+
+CPPUNIT_TEST_SUITE_REGISTRATION (fileops);
+
+using namespace std;
+
+void fileops :: setUp (void)
+{
+}
+
+void fileops :: tearDown (void) 
+{
+}
+
+void fileops :: gv_file_get_byte_test (void)
 {
     ViewerFileOps *fops;
     offset_type start = 0;
@@ -36,9 +43,11 @@ int main(int argc, char *argv[])
 
     fops = gv_fileops_new();
 
-    if (gv_file_open(fops, "../../INSTALL") == -1)
+    if (gv_file_open(fops, "../INSTALL") == -1)
         result = 1;
 
+    CPPUNIT_ASSERT (result == 0);
+
     if (!result)
     {
         int value;
@@ -48,16 +57,10 @@ int main(int argc, char *argv[])
         for (current = start; current < end; current++)
         {
             value = gv_file_get_byte(fops, current);
-
-            if (value == -1)
-            {
-                result = value;
-                break;
-            }
+            CPPUNIT_ASSERT (0 <= value && value <= 255 );
         }
     }
 
     gv_file_free(fops);
     g_free(fops);
-    return result;
 }
diff --git a/tests/intviewer/fileops.cc b/tests/iv_fileops.h
similarity index 57%
rename from tests/intviewer/fileops.cc
rename to tests/iv_fileops.h
index 0ae6685..7fe5612 100644
--- a/tests/intviewer/fileops.cc
+++ b/tests/iv_fileops.h
@@ -19,45 +19,32 @@
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 */
 
-#include <glib.h>
-#include <stdio.h>
-#include <stdlib.h>
+#ifndef FILEOPS_TEST_H
+#define FILEOPS_TEST_H
+
+//#include <glib.h>
+//#include <stdio.h>
+//#include <stdlib.h>
 #include <intviewer/libgviewer.h>
 #include <intviewer/gvtypes.h>
 #include <intviewer/fileops.h>
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+using namespace std;
 
-int main(int argc, char *argv[])
+class fileops : public CPPUNIT_NS :: TestFixture
 {
-    ViewerFileOps *fops;
-    offset_type start = 0;
-    offset_type end = 0;
-    offset_type current;
-    int result = 0;
-
-    fops = gv_fileops_new();
-
-    if (gv_file_open(fops, "../../INSTALL") == -1)
-        result = 1;
-
-    if (!result)
-    {
-        int value;
-        start = 0;
-        end = gv_file_get_max_offset(fops);
-
-        for (current = start; current < end; current++)
-        {
-            value = gv_file_get_byte(fops, current);
-
-            if (value == -1)
-            {
-                result = value;
-                break;
-            }
-        }
-    }
-
-    gv_file_free(fops);
-    g_free(fops);
-    return result;
-}
+    CPPUNIT_TEST_SUITE (fileops);
+    CPPUNIT_TEST (gv_file_get_byte_test);
+    CPPUNIT_TEST_SUITE_END ();
+
+    public:
+        void setUp (void);
+        void tearDown (void);
+
+    protected:
+        void gv_file_get_byte_test (void);
+};
+
+#endif


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