[Spice-devel] [vdagent-win PATCH v3] Add a test for logging functions

Christophe Fergeau cfergeau at redhat.com
Wed Jul 26 15:07:01 UTC 2017


Acked-by: Christophe Fergeau <cfergeau at redhat.com>

On Wed, Jul 26, 2017 at 03:48:25PM +0100, Frediano Ziglio wrote:
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
>  Makefile.am         | 13 +++++++++++++
>  common/test-log.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>  test-log            |  3 +++
>  3 files changed, 71 insertions(+)
>  create mode 100644 common/test-log.cpp
>  create mode 100755 test-log
> 
> Changes since v2:
> - use more portable functions.
> 
> 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..9941612
> --- /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
> -- 
> 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/4d59415f/attachment.sig>


More information about the Spice-devel mailing list