summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrediano Ziglio <fziglio@redhat.com>2017-07-26 10:36:09 +0100
committerFrediano Ziglio <fziglio@redhat.com>2017-07-26 16:16:16 +0100
commitd827d0ab51495e88631a1b296f36424fc50ed194 (patch)
tree56a43c7b61208a223875437aa45d9673731d5315
parentcc1534a3a0f38f55bc912992d067e310c9712981 (diff)
Add a test for logging functions
Signed-off-by: Frediano Ziglio <fziglio@redhat.com> Acked-by: Christophe Fergeau <cfergeau@redhat.com>
-rw-r--r--Makefile.am13
-rw-r--r--common/test-log.cpp52
-rwxr-xr-xtest-log3
3 files changed, 68 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index 38c8711..7fafb8b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -87,6 +87,19 @@ imagetest_SOURCES = \
TESTS = test-png
EXTRA_DIST += test-png
+check_PROGRAMS += test-log-win
+TESTS += test-log
+EXTRA_DIST += test-log
+
+test_log_win_LDFLAGS = $(AM_LDFLAGS) -Wl,--subsystem,console
+test_log_win_SOURCES = \
+ common/vdcommon.cpp \
+ common/vdcommon.h \
+ common/vdlog.cpp \
+ common/vdlog.h \
+ common/test-log.cpp \
+ $(NULL)
+
deps.txt:
$(AM_V_GEN)rpm -qa | grep $(host_os) | sort | unix2dos > $@
diff --git a/common/test-log.cpp b/common/test-log.cpp
new file mode 100644
index 0000000..341b605
--- /dev/null
+++ b/common/test-log.cpp
@@ -0,0 +1,52 @@
+/*
+ Copyright (C) 2017 Red Hat, Inc.
+
+ 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, see <http://www.gnu.org/licenses/>.
+*/
+#undef NDEBUG
+#include <assert.h>
+#include "vdlog.h"
+
+using namespace std;
+
+int main(int argc, char **argv)
+{
+ TCHAR temp_path[MAX_PATH];
+ assert(GetTempPath(ARRAYSIZE(temp_path), temp_path) != 0);
+
+ TCHAR path[MAX_PATH];
+ assert(GetTempFileName(temp_path, TEXT("tst"), 0, path) != 0);
+
+ VDLog *log = VDLog::get(path);
+ assert(log);
+
+ log_version();
+ vd_printf("Log something");
+ log->printf("A number %d", 123456);
+ delete log;
+
+ FILE *f = _wfopen(path, L"r");
+ assert(f);
+ char line[1024];
+ assert(fgets(line, sizeof(line), f) != NULL);
+ assert(strstr(line, "log_version") != NULL);
+ assert(fgets(line, sizeof(line), f) != NULL);
+ assert(strstr(line, "Log something") != NULL);
+ assert(fgets(line, sizeof(line), f) != NULL);
+ assert(strstr(line, "A number 123456") != NULL);
+ fclose(f);
+
+ DeleteFile(path);
+ return 0;
+}
diff --git a/test-log b/test-log
new file mode 100755
index 0000000..4ba2efe
--- /dev/null
+++ b/test-log
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+exec wine test-log-win.exe