[gnome-commander/googletest] Adds a first simple unit test for googletest framework
- From: Uwe Scholz <uwescholz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-commander/googletest] Adds a first simple unit test for googletest framework
- Date: Mon, 12 Oct 2015 20:17:12 +0000 (UTC)
commit 6f82fb179089e7bb7108a5f50b8f2ca58aae0ed0
Author: Uwe Scholz <uwescholz src gnome org>
Date: Mon Oct 12 21:53:14 2015 +0200
Adds a first simple unit test for googletest framework
tests/Makefile.am | 9 +++--
tests/gcmd_tests_main.cc | 6 +++
tests/{gviewer/fileops.c => iv_fileops.cc} | 53 +++++++---------------------
tests/iv_fileops.h | 36 +++++++++++++++++++
4 files changed, 60 insertions(+), 44 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 40c8e98..157a9fc 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -15,10 +15,11 @@ INTVLIBS = \
$(top_builddir)/src/intviewer/libgviewer.a
TESTS = \
- func_test
+ intviewer_fileops
+check_PROGRAMS = $(TESTS)
-func_test_SOURCES = run_tests.cpp fileops.cpp
-func_test_CXXFLAGS = $(INTVLIBS)
-func_test_LDFLAGS = $(INTVLIBS) -lgtest
+intviewer_fileops_SOURCES = iv_fileops.cc gcmd_tests_main.cc
+intviewer_fileops_CXXFLAGS = $(INTVLIBS)
+intviewer_fileops_LDFLAGS = $(INTVLIBS) -lgtest
-include $(top_srcdir)/git.mk
diff --git a/tests/gcmd_tests_main.cc b/tests/gcmd_tests_main.cc
new file mode 100644
index 0000000..4483c91
--- /dev/null
+++ b/tests/gcmd_tests_main.cc
@@ -0,0 +1,6 @@
+#include "gtest/gtest.h"
+
+int main(int argc, char **argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}
diff --git a/tests/gviewer/fileops.c b/tests/iv_fileops.cc
similarity index 50%
rename from tests/gviewer/fileops.c
rename to tests/iv_fileops.cc
index 1839c09..d2e77e9 100644
--- a/tests/gviewer/fileops.c
+++ b/tests/iv_fileops.cc
@@ -17,62 +17,35 @@
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>
-#include <libgviewer/libgviewer.h>
-#include <libgviewer/gvtypes.h>
-#include <libgviewer/fileops.h>
-
-void usage()
-{
- fprintf(stderr,"This program tests the file operations module in 'libgviewer'.\n\n");
+#include "gtest/gtest.h"
+#include <iv_fileops.h>
- fprintf(stderr,"Usage: test-fileops filename [start_offset] [end_offset]\n");
- fprintf(stderr,"\t'filename' will be printed to STDOUT.\n");
- fprintf(stderr,"\t'start_offset' and 'end_offset' are optimal.\n\n");
- exit(0);
-}
+FileOpsTest::FileOpsTest() {}
+FileOpsTest::~FileOpsTest() {}
-int main(int argc, char *argv[])
-{
+TEST_F(FileOpsTest, gv_file_get_byte_does_read) {
+ const char *file_path = "../INSTALL";
ViewerFileOps *fops;
- offset_type start = 0;
- offset_type end = 0;
+ offset_type end;
offset_type current;
int value;
- if (argc<=1)
- usage();
-
fops = gv_fileops_new();
- if (gv_file_open(fops, argv[1])==-1) {
- fprintf(stderr,"Failed to open \"%s\"\n", argv[1]);
- goto error;
- }
-
- start = argc>=3 ? atol(argv[2]) : 0;
-
- end = argc>=4 ? atol(argv[3]) : gv_file_get_max_offset(fops);
+ ASSERT_NE (-1, gv_file_open(fops, file_path));
+ end = gv_file_get_max_offset(fops);
- for (current = start; current < end; current++)
+ for (current = 0; current < end; current++)
{
value = gv_file_get_byte(fops, current);
-
- if (value==-1)
- break;
-
- printf("%c",(unsigned char)value);
+ ASSERT_TRUE (0 <= value && value <= 255 );
}
-error:
+ ASSERT_NE(-1, gv_file_open(fops, file_path));
+
gv_file_free(fops);
g_free(fops);
- return 0;
}
diff --git a/tests/iv_fileops.h b/tests/iv_fileops.h
new file mode 100644
index 0000000..240c144
--- /dev/null
+++ b/tests/iv_fileops.h
@@ -0,0 +1,36 @@
+/*
+ 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.
+*/
+
+#ifndef FILEOPS_TEST_H
+#define FILEOPS_TEST_H
+
+#include <intviewer/libgviewer.h>
+#include <intviewer/gvtypes.h>
+#include <intviewer/fileops.h>
+
+// The fixture for testing class Foo.
+class FileOpsTest : public ::testing::Test {
+ protected:
+ FileOpsTest();
+ virtual ~FileOpsTest();
+};
+
+#endif
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]