[Spice-devel] [vdagent-win PATCH v2 3/3] Add a test for logging functions
Christophe Fergeau
cfergeau at redhat.com
Wed Jul 26 14:38:44 UTC 2017
Acked-by: Christophe Fergeau <cfergeau at redhat.com>
On Wed, Jul 26, 2017 at 12:49:17PM +0100, Frediano Ziglio wrote:
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
> Makefile.am | 13 ++++++++++++
> common/test-log.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++
> test-log | 3 +++
> 3 files changed, 73 insertions(+)
> create mode 100644 common/test-log.cpp
> create mode 100755 test-log
>
> Changes since v1:
> - uses temporary file and delete only at the end
>
> 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..6798209
> --- /dev/null
> +++ b/common/test-log.cpp
> @@ -0,0 +1,57 @@
> +/*
> + 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 <iostream>
> +#include <fstream>
> +#include <string>
> +#include <codecvt>
> +#include <iomanip>
> +#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;
> +
> + wstring_convert<codecvt_utf8<wchar_t>> conv;
> + ifstream f(conv.to_bytes(path));
> + string line;
> + getline(f, line);
> + assert(line.find("log_version") != string::npos);
> + getline(f, line);
> + assert(line.find("Log something") != string::npos);
> + getline(f, line);
> + assert(line.find("A number 123456") != string::npos);
> + f.close();
> +
> + 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
> --
> 2.13.3
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20170726/0be4f121/attachment.sig>
More information about the Spice-devel
mailing list