<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: propread.hxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: kz $ $Date: 2006-12-12 16:36:45 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library 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
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _PROPREAD_HXX_
#define _PROPREAD_HXX_

#ifndef _SOLAR_H
#include <tools/solar.h>
#endif
#include <sot/storage.hxx>
#ifndef _SV_GEN_HXX
#include <tools/gen.hxx>
#endif
#ifndef _LIST_HXX
#include <tools/list.hxx>
#endif
#ifndef _STREAM_HXX
#include <tools/stream.hxx>
#endif
#ifndef _DATETIME_HXX
#include <tools/datetime.hxx>
#endif

#include <tools/string.hxx>

// SummaryInformation
#define PID_TITLE               0x02
#define PID_SUBJECT             0x03
#define PID_AUTHOR              0x04
#define PID_KEYWORDS            0x05
#define PID_COMMENTS            0x06
#define PID_TEMPLATE            0x07
#define PID_LASTAUTHOR          0x08
#define PID_REVNUMBER           0x09
#define PID_EDITTIME            0x0a
#define PID_LASTPRINTED_DTM     0x0b
#define PID_CREATE_DTM          0x0c
#define PID_LASTSAVED_DTM       0x0d

// DocumentSummaryInformation
#define PID_CATEGORY            0x02
#define PID_PRESFORMAT          0x03
#define PID_BYTECOUNT           0x04
#define PID_LINECOUNT           0x05
#define PID_PARACOUNT           0x06
#define PID_SLIDECOUNT          0x07
#define PID_NOTECOUNT           0x08
#define PID_HIDDENCOUNT         0x09
#define PID_MMCLIPCOUNT         0x0a
#define PID_SCALE               0x0b
#define PID_HEADINGPAIR         0x0c
#define PID_DOCPARTS            0x0d
#define PID_MANAGER             0x0e
#define PID_COMPANY             0x0f
#define PID_LINKSDIRTY          0x10

#define VT_EMPTY            0
#define VT_NULL             1
#define VT_I2               2
#define VT_I4               3
#define VT_R4               4
#define VT_R8               5
#define VT_CY               6
#define VT_DATE             7
#define VT_BSTR             8
#define VT_UI4              9
#define VT_ERROR            10
#define VT_BOOL             11
#define VT_VARIANT          12
#define VT_DECIMAL          14
#define VT_I1               16
#define VT_UI1              17
#define VT_UI2              18
#define VT_I8               20
#define VT_UI8              21
#define VT_INT              22
#define VT_UINT             23
#define VT_LPSTR            30
#define VT_LPWSTR           31
#define VT_FILETIME         64
#define VT_BLOB             65
#define VT_STREAM           66
#define VT_STORAGE          67
#define VT_STREAMED_OBJECT  68
#define VT_STORED_OBJECT    69
#define VT_BLOB_OBJECT      70
#define VT_CF               71
#define VT_CLSID            72
#define VT_VECTOR           0x1000
#define VT_ARRAY            0x2000
#define VT_BYREF            0x4000
#define VT_TYPEMASK         0xFFF

// ------------------------------------------------------------------------

class PropItem : public SvMemoryStream
{
        sal_uInt16      mnTextEnc;

    public :
                        PropItem(){};
        void            Clear();

        void            SetTextEncoding( sal_uInt16 nTextEnc ){ mnTextEnc = nTextEnc; };
        sal_Bool        Read( String& rString, sal_uInt32 nType = VT_EMPTY, sal_Bool bDwordAlign = sal_True );
        PropItem&       operator=( PropItem& rPropItem );

    using SvStream::Read;
};

// ------------------------------------------------------------------------

class Dictionary : protected List
{
    friend class Section;

        void        AddProperty( UINT32 nId, const String& rString );

    public :
                    Dictionary(){};
                    ~Dictionary();
        Dictionary& operator=( Dictionary& rDictionary );
        UINT32      GetProperty( const String& rPropName );
};

// ------------------------------------------------------------------------

class Section : private List
{
        sal_uInt16              mnTextEnc;

    protected:

        BYTE                    aFMTID[ 16 ];

        void                    AddProperty( sal_uInt32 nId, const sal_uInt8* pBuf, sal_uInt32 nBufSize );

    public:
                                Section( const sal_uInt8* pFMTID );
                                Section( Section& rSection );
                                ~Section();

        Section&                operator=( Section& rSection );
        sal_Bool                GetProperty( sal_uInt32 nId, PropItem& rPropItem );
        sal_Bool                GetDictionary( Dictionary& rDict );
        const sal_uInt8*        GetFMTID() const { return aFMTID; };
        void                    Read( SvStorageStream* pStrm );
};

// ------------------------------------------------------------------------

class PropRead : private List
{
        sal_Bool                mbStatus;
        SvStorageStream*        mpSvStream;

        sal_uInt16              mnByteOrder;
        sal_uInt16              mnFormat;
        sal_uInt16              mnVersionLo;
        sal_uInt16              mnVersionHi;
        sal_uInt8               mApplicationCLSID[ 16 ];

        void                    AddSection( Section& rSection );

    public:
                                PropRead( SvStorage& rSvStorage, const String& rName );
                                ~PropRead();

        PropRead&               operator=( PropRead& rPropRead );
        const Section*          GetSection( const BYTE* pFMTID );
        sal_Bool                IsValid() const { return mbStatus; };
        void                    Read();
};

#endif

<commit_msg>INTEGRATION: CWS changefileheader (1.6.298); FILE MERGED 2008/04/01 15:33:56 thb 1.6.298.2: #i85898# Stripping all external header guards 2008/03/31 13:56:47 rt 1.6.298.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: propread.hxx,v $
 * $Revision: 1.7 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef _PROPREAD_HXX_
#define _PROPREAD_HXX_

#include <tools/solar.h>
#include <sot/storage.hxx>
#include <tools/gen.hxx>
#include <tools/list.hxx>
#include <tools/stream.hxx>
#include <tools/datetime.hxx>

#include <tools/string.hxx>

// SummaryInformation
#define PID_TITLE               0x02
#define PID_SUBJECT             0x03
#define PID_AUTHOR              0x04
#define PID_KEYWORDS            0x05
#define PID_COMMENTS            0x06
#define PID_TEMPLATE            0x07
#define PID_LASTAUTHOR          0x08
#define PID_REVNUMBER           0x09
#define PID_EDITTIME            0x0a
#define PID_LASTPRINTED_DTM     0x0b
#define PID_CREATE_DTM          0x0c
#define PID_LASTSAVED_DTM       0x0d

// DocumentSummaryInformation
#define PID_CATEGORY            0x02
#define PID_PRESFORMAT          0x03
#define PID_BYTECOUNT           0x04
#define PID_LINECOUNT           0x05
#define PID_PARACOUNT           0x06
#define PID_SLIDECOUNT          0x07
#define PID_NOTECOUNT           0x08
#define PID_HIDDENCOUNT         0x09
#define PID_MMCLIPCOUNT         0x0a
#define PID_SCALE               0x0b
#define PID_HEADINGPAIR         0x0c
#define PID_DOCPARTS            0x0d
#define PID_MANAGER             0x0e
#define PID_COMPANY             0x0f
#define PID_LINKSDIRTY          0x10

#define VT_EMPTY            0
#define VT_NULL             1
#define VT_I2               2
#define VT_I4               3
#define VT_R4               4
#define VT_R8               5
#define VT_CY               6
#define VT_DATE             7
#define VT_BSTR             8
#define VT_UI4              9
#define VT_ERROR            10
#define VT_BOOL             11
#define VT_VARIANT          12
#define VT_DECIMAL          14
#define VT_I1               16
#define VT_UI1              17
#define VT_UI2              18
#define VT_I8               20
#define VT_UI8              21
#define VT_INT              22
#define VT_UINT             23
#define VT_LPSTR            30
#define VT_LPWSTR           31
#define VT_FILETIME         64
#define VT_BLOB             65
#define VT_STREAM           66
#define VT_STORAGE          67
#define VT_STREAMED_OBJECT  68
#define VT_STORED_OBJECT    69
#define VT_BLOB_OBJECT      70
#define VT_CF               71
#define VT_CLSID            72
#define VT_VECTOR           0x1000
#define VT_ARRAY            0x2000
#define VT_BYREF            0x4000
#define VT_TYPEMASK         0xFFF

// ------------------------------------------------------------------------

class PropItem : public SvMemoryStream
{
        sal_uInt16      mnTextEnc;

    public :
                        PropItem(){};
        void            Clear();

        void            SetTextEncoding( sal_uInt16 nTextEnc ){ mnTextEnc = nTextEnc; };
        sal_Bool        Read( String& rString, sal_uInt32 nType = VT_EMPTY, sal_Bool bDwordAlign = sal_True );
        PropItem&       operator=( PropItem& rPropItem );

    using SvStream::Read;
};

// ------------------------------------------------------------------------

class Dictionary : protected List
{
    friend class Section;

        void        AddProperty( UINT32 nId, const String& rString );

    public :
                    Dictionary(){};
                    ~Dictionary();
        Dictionary& operator=( Dictionary& rDictionary );
        UINT32      GetProperty( const String& rPropName );
};

// ------------------------------------------------------------------------

class Section : private List
{
        sal_uInt16              mnTextEnc;

    protected:

        BYTE                    aFMTID[ 16 ];

        void                    AddProperty( sal_uInt32 nId, const sal_uInt8* pBuf, sal_uInt32 nBufSize );

    public:
                                Section( const sal_uInt8* pFMTID );
                                Section( Section& rSection );
                                ~Section();

        Section&                operator=( Section& rSection );
        sal_Bool                GetProperty( sal_uInt32 nId, PropItem& rPropItem );
        sal_Bool                GetDictionary( Dictionary& rDict );
        const sal_uInt8*        GetFMTID() const { return aFMTID; };
        void                    Read( SvStorageStream* pStrm );
};

// ------------------------------------------------------------------------

class PropRead : private List
{
        sal_Bool                mbStatus;
        SvStorageStream*        mpSvStream;

        sal_uInt16              mnByteOrder;
        sal_uInt16              mnFormat;
        sal_uInt16              mnVersionLo;
        sal_uInt16              mnVersionHi;
        sal_uInt8               mApplicationCLSID[ 16 ];

        void                    AddSection( Section& rSection );

    public:
                                PropRead( SvStorage& rSvStorage, const String& rName );
                                ~PropRead();

        PropRead&               operator=( PropRead& rPropRead );
        const Section*          GetSection( const BYTE* pFMTID );
        sal_Bool                IsValid() const { return mbStatus; };
        void                    Read();
};

#endif

<|endoftext|>


<commit_before>#define CATCH_CONFIG_RUNNER
#include "catch/catch.hpp"

#include <exception>
#include <iostream>
#include <string>

// clang-format off
#include "base_test_fixture.h" // Must be included last!
// clang-format on

nanodbc::test::Config cfg;

int main(int argc, char* argv[])
{
    try
    {
        // Specify custom command line options
        auto cli
            = Catch::clara::Help(cfg.show_help_)
            | Catch::clara::Opt(cfg.connection_string_, "connection")
                ["-c"]["--connection-string"]
                ("connection string to test database; if not specified, "
                "an attempt will be made to read it from environment variables: "
                 "NANODBC_TEST_CONNSTR or NANODBC_TEST_CONNSTR_<DB>");
        auto parse_result = cli.parse(Catch::clara::Args(argc, argv));
        if (!parse_result)
        {
            Catch::cerr()
                << Catch::Colour(Catch::Colour::Red)
                << "\nError(s) in input:\n"
                << Catch::Column(parse_result.errorMessage()).indent(2)
                << "\n\n";
            Catch::cerr() << "Run with -? for usage\n" << std::endl;
            return EXIT_FAILURE;
        }

        // Disable custom options to avoid Catch warnings or failures
        for (int i = 1; i < argc; ++i)
        {
            if (strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "--connection-string") == 0)
            {
                *argv[i++] = 0;
                *argv[i] = 0;
            }
        }

        Catch::Session session;
        if (cfg.show_help_)
        {
            session.showHelp();

            Catch::cerr()
                << Catch::Colour(Catch::Colour::Yellow)
                << "nanodbc\n"
                << cli << std::endl;

            return EXIT_FAILURE;
        }

        if (session.applyCommandLine(argc, argv) != 0)
            return EXIT_FAILURE;

        // Run tests
        return session.run(argc, argv);
    }
    catch (std::exception const& e)
    {
        Catch::cerr()
            << Catch::Colour(Catch::Colour::Red)
            << "\nError(s):\n"
            << e.what() << '\n';
    }
    catch (...)
    {
        Catch::cerr()
            << Catch::Colour(Catch::Colour::Red)
            << "\nError(s): uncaught exception\n";
    }
}
<commit_msg>Replace -c with -z as Catch reserved former option<commit_after>#define CATCH_CONFIG_RUNNER
#include "catch/catch.hpp"

#include <exception>
#include <iostream>
#include <string>

// clang-format off
#include "base_test_fixture.h" // Must be included last!
// clang-format on

nanodbc::test::Config cfg;

int main(int argc, char* argv[])
{
    try
    {
        // Specify custom command line options
        auto cli
            = Catch::clara::Help(cfg.show_help_)
            | Catch::clara::Opt(cfg.connection_string_, "connection")
                ["-z"]["--connection-string"]
                ("connection string to test database; if not specified, "
                "an attempt will be made to read it from environment variables: "
                 "NANODBC_TEST_CONNSTR or NANODBC_TEST_CONNSTR_<DB>");
        auto parse_result = cli.parse(Catch::clara::Args(argc, argv));
        if (!parse_result)
        {
            Catch::cerr()
                << Catch::Colour(Catch::Colour::Red)
                << "\nError(s) in input:\n"
                << Catch::Column(parse_result.errorMessage()).indent(2)
                << "\n\n";
            Catch::cerr() << "Run with -? for usage\n" << std::endl;
            return EXIT_FAILURE;
        }

        // Disable custom options to avoid Catch warnings or failures
        for (int i = 1; i < argc; ++i)
        {
            if (strcmp(argv[i], "-z") == 0 || strcmp(argv[i], "--connection-string") == 0)
            {
                *argv[i++] = 0;
                *argv[i] = 0;
            }
        }

        Catch::Session session;
        if (cfg.show_help_)
        {
            session.showHelp();

            Catch::cerr()
                << Catch::Colour(Catch::Colour::Yellow)
                << "nanodbc\n"
                << cli << std::endl;

            return EXIT_FAILURE;
        }

        if (session.applyCommandLine(argc, argv) != 0)
            return EXIT_FAILURE;

        // Run tests
        return session.run(argc, argv);
    }
    catch (std::exception const& e)
    {
        Catch::cerr()
            << Catch::Colour(Catch::Colour::Red)
            << "\nError(s):\n"
            << e.what() << '\n';
    }
    catch (...)
    {
        Catch::cerr()
            << Catch::Colour(Catch::Colour::Red)
            << "\nError(s): uncaught exception\n";
    }
    return EXIT_FAILURE;
}
<|endoftext|>


<commit_before>/*

Copyright (c) 2008, Arvid Norberg
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in
      the documentation and/or other materials provided with the distribution.
    * Neither the name of the author nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

*/

#include <iostream>
#include <boost/config.hpp>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h> // for exit()
#include "setup_transfer.hpp" // for tests_failure

int test_main();

#include "libtorrent/assert.hpp"
#include "libtorrent/file.hpp"
#include <signal.h>

void sig_handler(int sig)
{
	char stack_text[10000];

#if (defined TORRENT_DEBUG && !TORRENT_NO_ASSERTS) || TORRENT_RELEASE_ASSERTS
	print_backtrace(stack_text, sizeof(stack_text), 30);
#elif defined __FUNCTION__
	strcat(stack_text, __FUNCTION__);
#else
	stack_text[0] = 0;
#endif
	char const* sig_name = 0;
	switch (sig)
	{
#define SIG(x) case x: sig_name = #x; break
		SIG(SIGSEGV);
#ifdef SIGBUS
		SIG(SIGBUS);
#endif
		SIG(SIGILL);
		SIG(SIGABRT);
		SIG(SIGFPE);
#ifdef SIGSYS
		SIG(SIGSYS);
#endif
#undef SIG
	};
	fprintf(stderr, "signal: %s caught:\n%s\n", sig_name, stack_text);
	exit(138);
}

using namespace libtorrent;

int main()
{
#ifdef O_NONBLOCK
	// on darwin, stdout is set to non-blocking mode by default
	// which sometimes causes tests to fail with EAGAIN just
	// by printing logs
	int flags = fcntl(fileno(stdout), F_GETFL, 0);
	fcntl(fileno(stdout), F_SETFL, flags & ~O_NONBLOCK);
	flags = fcntl(fileno(stderr), F_GETFL, 0);
	fcntl(fileno(stderr), F_SETFL, flags & ~O_NONBLOCK);
#endif

	signal(SIGSEGV, &sig_handler);
#ifdef SIGBUS
	signal(SIGBUS, &sig_handler);
#endif
	signal(SIGILL, &sig_handler);
	signal(SIGABRT, &sig_handler);
	signal(SIGFPE, &sig_handler);
#ifdef SIGSYS
	signal(SIGSYS, &sig_handler);
#endif

	char dir[40];
	snprintf(dir, sizeof(dir), "test_tmp_%u", rand());
	std::string test_dir = complete(dir);
	error_code ec;
	create_directory(test_dir, ec);
	if (ec)
	{
		fprintf(stderr, "Failed to create test directory: %s\n", ec.message().c_str());
		return 1;
	}
#ifdef TORRENT_WINDOWS
	SetCurrentDirectoryA(dir);
#else
	chdir(dir);
#endif

#ifndef BOOST_NO_EXCEPTIONS
	try
	{
#endif
		test_main();
#ifndef BOOST_NO_EXCEPTIONS
	}
	catch (std::exception const& e)
	{
		std::cerr << "Terminated with exception: \"" << e.what() << "\"\n";
		tests_failure = true;
	}
	catch (...)
	{
		std::cerr << "Terminated with unknown exception\n";
		tests_failure = true;
	}
#endif
	fflush(stdout);
	fflush(stderr);
	remove_all(test_dir, ec);
	if (ec)
		fprintf(stderr, "failed to remove test dir: %s\n", ec.message().c_str());
	return tests_failure ? 1 : 0;
}

<commit_msg>initialize random number generator for tests<commit_after>/*

Copyright (c) 2008, Arvid Norberg
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in
      the documentation and/or other materials provided with the distribution.
    * Neither the name of the author nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

*/

#include <iostream>
#include <boost/config.hpp>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h> // for exit()
#include "setup_transfer.hpp" // for tests_failure

int test_main();

#include "libtorrent/assert.hpp"
#include "libtorrent/file.hpp"
#include <signal.h>

void sig_handler(int sig)
{
	char stack_text[10000];

#if (defined TORRENT_DEBUG && !TORRENT_NO_ASSERTS) || TORRENT_RELEASE_ASSERTS
	print_backtrace(stack_text, sizeof(stack_text), 30);
#elif defined __FUNCTION__
	strcat(stack_text, __FUNCTION__);
#else
	stack_text[0] = 0;
#endif
	char const* sig_name = 0;
	switch (sig)
	{
#define SIG(x) case x: sig_name = #x; break
		SIG(SIGSEGV);
#ifdef SIGBUS
		SIG(SIGBUS);
#endif
		SIG(SIGILL);
		SIG(SIGABRT);
		SIG(SIGFPE);
#ifdef SIGSYS
		SIG(SIGSYS);
#endif
#undef SIG
	};
	fprintf(stderr, "signal: %s caught:\n%s\n", sig_name, stack_text);
	exit(138);
}

using namespace libtorrent;

int main()
{
	srand(total_microseconds(time_now_hires() - min_time()));
#ifdef O_NONBLOCK
	// on darwin, stdout is set to non-blocking mode by default
	// which sometimes causes tests to fail with EAGAIN just
	// by printing logs
	int flags = fcntl(fileno(stdout), F_GETFL, 0);
	fcntl(fileno(stdout), F_SETFL, flags & ~O_NONBLOCK);
	flags = fcntl(fileno(stderr), F_GETFL, 0);
	fcntl(fileno(stderr), F_SETFL, flags & ~O_NONBLOCK);
#endif

	signal(SIGSEGV, &sig_handler);
#ifdef SIGBUS
	signal(SIGBUS, &sig_handler);
#endif
	signal(SIGILL, &sig_handler);
	signal(SIGABRT, &sig_handler);
	signal(SIGFPE, &sig_handler);
#ifdef SIGSYS
	signal(SIGSYS, &sig_handler);
#endif

	char dir[40];
	snprintf(dir, sizeof(dir), "test_tmp_%u", rand());
	std::string test_dir = complete(dir);
	error_code ec;
	create_directory(test_dir, ec);
	if (ec)
	{
		fprintf(stderr, "Failed to create test directory: %s\n", ec.message().c_str());
		return 1;
	}
#ifdef TORRENT_WINDOWS
	SetCurrentDirectoryA(dir);
#else
	chdir(dir);
#endif

#ifndef BOOST_NO_EXCEPTIONS
	try
	{
#endif
		test_main();
#ifndef BOOST_NO_EXCEPTIONS
	}
	catch (std::exception const& e)
	{
		std::cerr << "Terminated with exception: \"" << e.what() << "\"\n";
		tests_failure = true;
	}
	catch (...)
	{
		std::cerr << "Terminated with unknown exception\n";
		tests_failure = true;
	}
#endif
	fflush(stdout);
	fflush(stderr);
	remove_all(test_dir, ec);
	if (ec)
		fprintf(stderr, "failed to remove test dir: %s\n", ec.message().c_str());
	return tests_failure ? 1 : 0;
}

<|endoftext|>


<commit_before>/*
	Main testing file for the linear_algebra_containers
	Copyright (C) 2015  Fabian Löschner

	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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <iostream>
#include <string>
#include <cassert>

#include "../source/matrix.h"
#include "../source/column_vector.h"
#include "../source/vector3.h"
#include "../source/quaternion.h"

void msg(const std::string& string) {
	std::cout << string << "... ";
}

void ok() {
	std::cout << "ok." << std::endl;
}

int run_matrix_test()
{
	typedef matrix<double,4,4> mat4x4d;
	typedef matrix<double,4,1> mat4x1d;
	typedef matrix<double,4,2> mat4x2d;

	msg("Testing braced initialization and subscript operator");
	mat4x4d mat{{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}};
	for(int i = 0; i < 16; i++) {
		assert(mat[i] == i+1);
	}
	ok();

	msg("Testing ()-operator");
	assert(mat(0,0) == 1);
	assert(mat(1,0) == 2);
	assert(mat(2,0) == 3);
	assert(mat(3,0) == 4);
	assert(mat(0,1) == 5);
	assert(mat(1,1) == 6);
	assert(mat(2,1) == 7);
	assert(mat(3,1) == 8);
	assert(mat(0,2) == 9);
	assert(mat(1,2) == 10);
	assert(mat(2,2) == 11);
	assert(mat(3,2) == 12);
	assert(mat(0,3) == 13);
	assert(mat(1,3) == 14);
	assert(mat(2,3) == 15);
	assert(mat(3,3) == 16);
	ok();

	msg("Testing fill()");
	mat4x1d v;
	v.fill(12.345);
	assert(v[0] == 12.345);
	assert(v[1] == 12.345);
	assert(v[2] == 12.345);
	assert(v[3] == 12.345);
	ok();

	msg("Testing zeros()");
	v.zeros();
	assert(v[0] == 0);
	assert(v[1] == 0);
	assert(v[2] == 0);
	assert(v[3] == 0);
	ok();

	msg("Testing identity matrix eye()");
	mat.toIdentity();
	for(int i = 0; i < 4; i++) {
		for(int j = 0; j < 4; j++) {
			if(i == j) {
				assert(mat(i,j) == 1);
			} else {
				assert(mat(i,j) == 0);
			}
		}
	}
	ok();

	msg("Testing matrix multiplication");
	for(int i = 0; i < 16; i++) {
		mat[i] = i+1;
	}
	mat4x2d mat2;
	for(int i = 0; i < 8; i++) {
		mat2[i] = i+1;
	}
	matrix<double,4,2> mat3 = mat*mat2;
	assert(mat3(0,0) == 90);
	assert(mat3(1,0) == 100);
	assert(mat3(2,0) == 110);
	assert(mat3(3,0) == 120);
	assert(mat3(0,1) == 202);
	assert(mat3(1,1) == 228);
	assert(mat3(2,1) == 254);
	assert(mat3(3,1) == 280);
	ok();

	msg("Testing matrix scaling");
	matrix<double,2,2> mat4;
	mat4.fill(3);
	mat4 *= 2;
	assert(mat4[0] == 6);
	assert(mat4[1] == 6);
	assert(mat4[2] == 6);
	assert(mat4[3] == 6);
	ok();

	msg("Testing matrix sum/difference");
	matrix<double,2,2> mat5;
	mat5.fill(2);
	mat4 -= mat5;
	assert(mat4[0] == 4);
	assert(mat4[1] == 4);
	assert(mat4[2] == 4);
	assert(mat4[3] == 4);
	mat5.fill(3);
	mat5 += mat4;
	assert(mat5[0] == 7);
	assert(mat5[1] == 7);
	assert(mat5[2] == 7);
	assert(mat5[3] == 7);

	mat4.toIdentity();
	matrix<double,2,2> mat6 = mat5-mat4;
	assert(mat6(0,0) == 6);
	assert(mat6(1,0) == 7);
	assert(mat6(0,1) == 7);
	assert(mat6(1,1) == 6);
	ok();

	msg("Testing matrix comparison");
	assert(mat5 != mat4);
	assert(!(mat5 == mat4));
	ok();

	// TODO: Test data
	// TODO: Test const
	// TODO: Test transposed
	// TODO: Test scalar product

	return 0;
}

int run_column_vector_test()
{
	typedef column_vector<double,3> vec3d;
	vec3d v1;
	vec3d v2;

	msg("Testing fill() and array subscript operator");
	v1.fill(2.5);
	assert(v1[0] == 2.5);
	assert(v1[1] == 2.5);
	assert(v1[2] == 2.5);
	ok();

	msg("Testing zeors()");
	v2.zeros();
	assert(v2[0] == 0);
	assert(v2[1] == 0);
	assert(v2[2] == 0);
	ok();

	msg("Testing length()");
	v1.fill(3);
	assert(v1.length() == sqrt(27));
	ok();

	msg("Testing normalize()");
	v1.fill(3);
	v1.normalize();
	assert(v1.length() == 1);
	ok();

	msg("Testing normalized()");
	v1.fill(3);
	assert(v1.normalized().length() == 1);
	ok();

	msg("Testing dot product");
	v1[0] = 1;
	v1[1] = 2;
	v1[2] = 3;
	v2[0] = 4;
	v2[1] = 5;
	v2[2] = 6;
	assert(vec3d::dotProduct(v1,v2) == 32);
	ok();

	msg("Testing implicit conversion between matrix and column vector");
	v1.fill(2); v2.fill(3);
	assert(vec3d::dotProduct((v1.transposed().transposed()), v2) == 18);
	auto t = v1.transposed().transposed();
	assert(vec3d::dotProduct(t, v2) == 18);
	ok();

	return 0;
}

int run_vector3_test()
{
	typedef vector3<double> vec3d;

	msg("Testing constructor");
	vec3d v1(0.1,312.112,77);
	assert(v1[0] == 0.1);
	assert(v1[1] == 312.112);
	assert(v1[2] == 77);

	const double k = 77;
	vec3d v2(0.1,312.112,k);
	assert(v2[0] == 0.1);
	assert(v2[1] == 312.112);
	assert(v2[2] == k);
	ok();

	msg("Testing getters");
	v1[0] = 3.3;
	v1[1] = 4.4;
	v1[2] = 5.5;
	assert(v1.x() == 3.3);
	assert(v1.y() == 4.4);
	assert(v1.z() == 5.5);
	ok();

	msg("Testing setters");
	const double d = 22.2;
	v2.setX(1);
	v2.setY(d);
	v2.setZ(22);
	assert(v2.x() == 1);
	assert(v2.y() == d);
	assert(v2.z() == 22);
	ok();

	msg("Testing cross product");
	v1.setX(1);
	v1.setY(2);
	v1.setZ(3);
	v2.setX(3);
	v2.setY(4);
	v2.setZ(5);
	auto r = vec3d::crossProduct(v1,v2);
	assert(r.x() == -2);
	assert(r.y() == 4);
	assert(r.z() == -2);
	ok();

	// TODO: Test implicit conversion

	return 0;
}

int run_quaternion_test()
{
	typedef quaternion<double> quatd;

	quatd q(1,2,3,4);

	// TODO: All tests

	return 0;
}

int main()
{
	#ifdef NDEBUG
		std::cout << "WARNING: This is no debug build! Asserts (i.e. the tests) won't work!" << std::endl;
		std::cout << "Please rebuild without NDEBUG!" << std::endl;
		return 1;
	#endif

	int state = 0;

	std::cout << "Running matrix tests..." << std::endl;
	state += run_matrix_test();
	std::cout << std::endl;

	std::cout << "Running column_vector tests..." << std::endl;
	state += run_column_vector_test();
	std::cout << std::endl;

	std::cout << "Running column_vector tests..." << std::endl;
	state += run_vector3_test();
	std::cout << std::endl;

	std::cout << "Running quaternion tests..." << std::endl;
	state += run_quaternion_test();
	std::cout << std::endl;

	return state;
}
<commit_msg>Small update<commit_after>/*
	Main testing file for the linear_algebra_containers
	Copyright (C) 2015  Fabian Löschner

	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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#include <iostream>
#include <string>
#include <cassert>

#include "../source/matrix.h"
#include "../source/column_vector.h"
#include "../source/vector3.h"
#include "../source/quaternion.h"

void msg(const std::string& string) {
	std::cout << string << "... ";
}

void ok() {
	std::cout << "ok." << std::endl;
}

int run_matrix_test()
{
	typedef matrix<double,4,4> mat4x4d;
	typedef matrix<double,4,1> mat4x1d;
	typedef matrix<double,4,2> mat4x2d;

	msg("Testing braced initialization and subscript operator");
	mat4x4d mat{{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}};
	for(int i = 0; i < 16; i++) {
		assert(mat[i] == i+1);
	}
	ok();

	msg("Testing ()-operator");
	assert(mat(0,0) == 1);
	assert(mat(1,0) == 2);
	assert(mat(2,0) == 3);
	assert(mat(3,0) == 4);
	assert(mat(0,1) == 5);
	assert(mat(1,1) == 6);
	assert(mat(2,1) == 7);
	assert(mat(3,1) == 8);
	assert(mat(0,2) == 9);
	assert(mat(1,2) == 10);
	assert(mat(2,2) == 11);
	assert(mat(3,2) == 12);
	assert(mat(0,3) == 13);
	assert(mat(1,3) == 14);
	assert(mat(2,3) == 15);
	assert(mat(3,3) == 16);
	ok();

	msg("Testing fill()");
	mat4x1d v;
	v.fill(12.345);
	assert(v[0] == 12.345);
	assert(v[1] == 12.345);
	assert(v[2] == 12.345);
	assert(v[3] == 12.345);
	ok();

	msg("Testing zeros()");
	v.zeros();
	assert(v[0] == 0);
	assert(v[1] == 0);
	assert(v[2] == 0);
	assert(v[3] == 0);
	ok();

	msg("Testing identity matrix eye()");
	mat.toIdentity();
	for(int i = 0; i < 4; i++) {
		for(int j = 0; j < 4; j++) {
			if(i == j) {
				assert(mat(i,j) == 1);
			} else {
				assert(mat(i,j) == 0);
			}
		}
	}
	ok();

	msg("Testing matrix multiplication");
	for(int i = 0; i < 16; i++) {
		mat[i] = i+1;
	}
	mat4x2d mat2;
	for(int i = 0; i < 8; i++) {
		mat2[i] = i+1;
	}
	matrix<double,4,2> mat3 = mat*mat2;
	assert(mat3(0,0) == 90);
	assert(mat3(1,0) == 100);
	assert(mat3(2,0) == 110);
	assert(mat3(3,0) == 120);
	assert(mat3(0,1) == 202);
	assert(mat3(1,1) == 228);
	assert(mat3(2,1) == 254);
	assert(mat3(3,1) == 280);
	ok();

	msg("Testing matrix scaling");
	matrix<double,2,2> mat4;
	mat4.fill(3);
	mat4 *= 2;
	assert(mat4[0] == 6);
	assert(mat4[1] == 6);
	assert(mat4[2] == 6);
	assert(mat4[3] == 6);
	ok();

	msg("Testing matrix sum/difference");
	matrix<double,2,2> mat5;
	mat5.fill(2);
	mat4 -= mat5;
	assert(mat4[0] == 4);
	assert(mat4[1] == 4);
	assert(mat4[2] == 4);
	assert(mat4[3] == 4);
	mat5.fill(3);
	mat5 += mat4;
	assert(mat5[0] == 7);
	assert(mat5[1] == 7);
	assert(mat5[2] == 7);
	assert(mat5[3] == 7);

	mat4.toIdentity();
	matrix<double,2,2> mat6 = mat5-mat4;
	assert(mat6(0,0) == 6);
	assert(mat6(1,0) == 7);
	assert(mat6(0,1) == 7);
	assert(mat6(1,1) == 6);
	ok();

	msg("Testing matrix comparison");
	assert(mat5 != mat4);
	assert(!(mat5 == mat4));
	ok();

	// TODO: Test data
	// TODO: Test const
	// TODO: Test transposed
	// TODO: Test scalar product

	return 0;
}

int run_column_vector_test()
{
	typedef column_vector<double,3> vec3d;
	vec3d v1;
	vec3d v2;

	// TODO: Test initializer list

	msg("Testing fill() and array subscript operator");
	v1.fill(2.5);
	assert(v1[0] == 2.5);
	assert(v1[1] == 2.5);
	assert(v1[2] == 2.5);
	ok();

	msg("Testing zeors()");
	v2.zeros();
	assert(v2[0] == 0);
	assert(v2[1] == 0);
	assert(v2[2] == 0);
	ok();

	msg("Testing length()");
	v1.fill(3);
	assert(v1.length() == sqrt(27));
	ok();

	msg("Testing normalize()");
	v1.fill(3);
	v1.normalize();
	assert(v1.length() == 1);
	ok();

	msg("Testing normalized()");
	v1.fill(3);
	assert(v1.normalized().length() == 1);
	ok();

	msg("Testing dot product");
	v1[0] = 1;
	v1[1] = 2;
	v1[2] = 3;
	v2[0] = 4;
	v2[1] = 5;
	v2[2] = 6;
	assert(vec3d::dotProduct(v1,v2) == 32);
	ok();

	msg("Testing implicit conversion between matrix and column vector");
	v1.fill(2); v2.fill(3);
	assert(vec3d::dotProduct((v1.transposed().transposed()), v2) == 18);
	auto t = v1.transposed().transposed();
	assert(vec3d::dotProduct(t, v2) == 18);
	ok();

	return 0;
}

int run_vector3_test()
{
	typedef vector3<double> vec3d;

	msg("Testing constructor");
	vec3d v1(0.1,312.112,77);
	assert(v1[0] == 0.1);
	assert(v1[1] == 312.112);
	assert(v1[2] == 77);

	const double k = 77;
	vec3d v2(0.1,312.112,k);
	assert(v2[0] == 0.1);
	assert(v2[1] == 312.112);
	assert(v2[2] == k);
	ok();

	msg("Testing getters");
	v1[0] = 3.3;
	v1[1] = 4.4;
	v1[2] = 5.5;
	assert(v1.x() == 3.3);
	assert(v1.y() == 4.4);
	assert(v1.z() == 5.5);
	ok();

	msg("Testing setters");
	const double d = 22.2;
	v2.setX(1);
	v2.setY(d);
	v2.setZ(22);
	assert(v2.x() == 1);
	assert(v2.y() == d);
	assert(v2.z() == 22);
	ok();

	msg("Testing cross product");
	v1.setX(1);
	v1.setY(2);
	v1.setZ(3);
	v2.setX(3);
	v2.setY(4);
	v2.setZ(5);
	auto r = vec3d::crossProduct(v1,v2);
	assert(r.x() == -2);
	assert(r.y() == 4);
	assert(r.z() == -2);
	ok();

	// TODO: Test implicit conversion

	return 0;
}

int run_quaternion_test()
{
	typedef quaternion<double> quatd;

	quatd q(1,2,3,4);

	// TODO: All tests

	return 0;
}

int main()
{
	#ifdef NDEBUG
		std::cout << "WARNING: This is no debug build! Asserts (i.e. the tests) won't work!" << std::endl;
		std::cout << "Please rebuild without NDEBUG!" << std::endl;
		return 1;
	#endif

	int state = 0;

	std::cout << "Running matrix tests..." << std::endl;
	state += run_matrix_test();
	std::cout << std::endl;

	std::cout << "Running column_vector tests..." << std::endl;
	state += run_column_vector_test();
	std::cout << std::endl;

	std::cout << "Running column_vector tests..." << std::endl;
	state += run_vector3_test();
	std::cout << std::endl;

	std::cout << "Running quaternion tests..." << std::endl;
	state += run_quaternion_test();
	std::cout << std::endl;

	return state;
}
<|endoftext|>


<commit_before>/*****************************************************************************************
 *                                                                                *
 * GHOUL                                                                                *
 * General Helpful Open Utility Library                                                  *
 *                                                                                *
 * Copyright (c) 2012-2014                                                               *
 *                                                                                *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this  *
 * software and associated documentation files (the "Software"), to deal in the Software *
 * without restriction, including without limitation the rights to use, copy, modify,    *
 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to    *
 * permit persons to whom the Software is furnished to do so, subject to the following   *
 * conditions:                                                                           *
 *                                                                                *
 * The above copyright notice and this permission notice shall be included in all copies *
 * or substantial portions of the Software.                                              *
 *                                                                                *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,   *
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A         *
 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT    *
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF  *
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE  *
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                                         *
 ****************************************************************************************/

#include <ghoul/filesystem/cachemanager.h>

#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/crc32.h>

#include <algorithm>
#include <assert.h>
#include <fstream>
#include <string>

namespace {
	const std::string _loggerCat = "CacheManager";
	const std::string _cacheFile = "cache";
	const char _hashDelimiter = '|'; // something that cannot occur in the filesystem
}

namespace ghoul {
namespace filesystem {

CacheManager::CacheManager(std::string directory)
    : _directory(std::move(directory))
{
    // In the cache state, we check our cache directory for all values, in a later step
    // we remove all persistent values, so that only the non-persistent values remain
    // Under normal operation, the resulting vector should be of size == 0, but if the
    // last execution of the application crashed, the directory was not cleaned up
    // properly
    std::vector<LoadedCacheInfo> cacheState = cacheInformationFromDirectory(_directory);
	std::string&& path = FileSys.pathByAppendingComponent(_directory, _cacheFile);

	std::ifstream file(path);
	if (file.good()) {
		std::string line;
        // loading the cache file that might exist from a previous run of the application
        // and reading all the persistent files from that file
		while (std::getline(file, line)) {
            // The structure of the cache file is assumed as follows (writting in the
            // destructor call of the application's previous run):
            // for each file:
            //   hash number\n
            //   filepath\n
			std::stringstream s(line);

			unsigned int hash;
			s >> hash;

			CacheInformation info;
			std::getline(file, info.file);
			info.isPersistent = true;
			_files.emplace(hash, info);

            // If the current hash + file is contained in the cache state, we have to
            // remove it
			cacheState.erase(std::remove_if(cacheState.begin(), cacheState.end(),
				[hash, &info](const LoadedCacheInfo& i) {
					return hash == i.first && info.file == i.second;
				}), cacheState.end());
		}
	}

    // At this point all values that remain in the cache state vector are left from a
    // previous crash of the application
    if (!cacheState.empty()) {
        LINFO("There was a crash in the previous run and it left the cache unclean. "
              "Cleaning it now");
        for (auto cache : cacheState) {
            LINFO("Deleting file '" << cache.second << "'");
            FileSys.deleteFile(cache.second);
        }
        cleanDirectory(_directory);
    }
}

CacheManager::~CacheManager() {
	std::string&& path = FileSys.pathByAppendingComponent(_directory, _cacheFile);
	std::ofstream file(path, std::ofstream::out);
	if (file.good()) {
		for (auto p : _files) {
			if (!p.second.isPersistent) {
                // Delete all the non-persistent files
				if (FileSys.fileExists(p.second.file))
					FileSys.deleteFile(p.second.file);
			}
			else
                // Save the persistent files in the cache file
				file << p.first << std::endl <<
						p.second.file << std::endl;
		}
		file.close();
	}
	else
		LERROR("Could not open file '" << path << "' for writing permanent cache files");
	cleanDirectory(_directory);
}

bool CacheManager::getCachedFile(const File& file, std::string& cachedFileName,
	bool isPersistent)
{
	std::string lastModifiedTime = file.lastModifiedDate();
	return getCachedFile(file, lastModifiedTime, cachedFileName, isPersistent);
}

bool CacheManager::getCachedFile(const File& file, const std::string& information,
                                 std::string &cachedFileName, bool isPersistent)
{
    return getCachedFile(file.filename(), information, cachedFileName, isPersistent);
}

bool CacheManager::getCachedFile(const std::string& baseName,
                                 const std::string& information,
                                 std::string& cachedFileName, bool isPersistent)
{
    size_t pos = baseName.find_first_of("/\\?%*:|\"<>");
    if (pos != std::string::npos) {
        LERROR("Base name '" << baseName << "' consists of illegal character");
        return false;
    }

	unsigned int hash = generateHash(baseName, information);

	auto it = _files.find(hash);
	if (it != _files.end()) {
        // If we find the hash, it has been created before and we can just return the
        // file name to the caller
		cachedFileName = it->second.file;
		return true;
	}

    // If we couldn't find the file, we have to generate a directory with the name of the
    // hash and return the full path containing of the cache path + requested filename +
    // hash value
	std::string destinationBase = FileSys.pathByAppendingComponent(_directory, baseName);

    // If this is the first time anyone requests a cache for the file name, we have to
    // create the base directory under the cache directory
	if (!FileSys.directoryExists(destinationBase))
		FileSys.createDirectory(destinationBase);

	std::string destination = FileSys.pathByAppendingComponent(destinationBase,
		std::to_string(hash));

    // The new destination should always not exist, since we checked before if we have the
    // value in the map and only get here if it isn't; persistent cache entries are always
    // in the map and non-persistent entries should have been deleted on application close
	if (!FileSys.directoryExists(destination))
		FileSys.createDirectory(destination);
    else {
        LERROR("Cache directory '" << destination << "' already existed even though it "
               "was not registered before");
        return false;
    }

    // Generate and output the newly generated cache name
	cachedFileName = FileSys.pathByAppendingComponent(destination, baseName);

    // Store the cache information in the map
	CacheInformation info = {
		cachedFileName,
		isPersistent
	};
	_files.emplace(hash, info);
	return true;
}

bool CacheManager::hasCachedFile(const File& file) const {
	std::string lastModifiedTime = file.lastModifiedDate();
	return hasCachedFile(file, lastModifiedTime);
}

bool CacheManager::hasCachedFile(const File& file, const std::string& information) const {
    return hasCachedFile(file.filename(), information);
}

bool CacheManager::hasCachedFile(const std::string& baseName,
                                 const std::string& information) const
{
    size_t pos = baseName.find_first_of("/\\?%*:|\"<>.");
    if (pos != std::string::npos) {
        LERROR("Base name '" << baseName << "' consists of illegal character");
        return false;
    }

    unsigned int hash = generateHash(baseName, information);
    return _files.find(hash) != _files.end();
}

void CacheManager::removeCacheFile(const File& file) {
	std::string lastModifiedTime = file.lastModifiedDate();
	removeCacheFile(file, lastModifiedTime);
}

void CacheManager::removeCacheFile(const File& file, const std::string& information) {
    removeCacheFile(file.filename(), information);
}

void CacheManager::removeCacheFile(const std::string& baseName,
                         const std::string& information)
{
    size_t pos = baseName.find_first_of("/\\?%*:|\"<>.");
    if (pos != std::string::npos) {
        LERROR("Base name '" << baseName << "' consists of illegal character");
        return;
    }

    unsigned int hash = generateHash(baseName, information);

    auto it = _files.find(hash);
    if (it != _files.end()) {
        // If we find the hash, it has been created before and we can just return the
        // file name to the caller
        const std::string& cachedFileName = it->second.file;
        FileSys.deleteFile(cachedFileName);
        _files.erase(it);
    }
}

unsigned int CacheManager::generateHash(std::string file, std::string information) const
{
	std::string hashString = file + _hashDelimiter + information;
	unsigned int hash = hashCRC32(hashString);

	return hash;
}

void CacheManager::cleanDirectory(const Directory& dir) const {
    LDEBUG("Cleaning directory '" << dir << "'");
    // First search for all subdirectories and call this function recursively on them
	std::vector<std::string> contents = dir.readDirectories();
	for (auto content : contents) {
        if (FileSys.directoryExists(content)) {
			cleanDirectory(content);
        }
	}
    // We get to this point in the recursion if either all subdirectories have been
    // deleted or there exists a file somewhere in the directory tree

	contents = dir.read();
    bool isEmpty = contents.size() == 0;
#ifdef __APPLE__
    // Apple stores the .DS_Store directory in the directory which can be removed
    std::string dsStore = FileSys.pathByAppendingComponent(dir, ".DS_Store");
    isEmpty |= ((contents.size() == 1) && contents[0] == dsStore);
#endif
    // If this directory is empty, we can delete it
    if (isEmpty) {
        LDEBUG("Deleting directory '" << dir << "'");
		FileSys.deleteDirectory(dir);
    }
}

std::vector<CacheManager::LoadedCacheInfo> CacheManager::cacheInformationFromDirectory(
    const Directory& dir) const
{
    std::vector<LoadedCacheInfo> result;
    std::vector<std::string> directories = dir.readDirectories(false);
    for (auto directory : directories) {
        Directory d(directory);

        // Extract the name of the directory
        // +1 as the last path delimiter is missing from the path
        std::string directoryName = directory.substr(dir.path().size() + 1);

        std::vector<std::string> hashes = d.readDirectories();
        for (auto hash : hashes) {
            // Extract the hash from the directory name
            // +1 as the last path delimiter is missing from the path
            std::string hashName = hash.substr(d.path().size() + 1);

            std::vector<std::string> files = Directory(hash).readFiles();
            // Cache directories should only contain a single file with the
            // same name as the directory
            if (files.size() > 1)
                LERROR("Directory '" << hash << "' contained more than one file");
            if (files.size() == 1) {
                // Extract the file name from the full path
                // +1 as the last path delimiter is missing from the path
                std::string filename = files[0].substr(Directory(hash).path().size() + 1);
				if (filename != directoryName)
					LERROR("File contained in cache directory '" <<
					hash << "' contains a file with name '" << filename <<
					"instead of the expected '" << directoryName << "'");
				else
					// Adding the absPath to normalize all / and \ for Windows
					result.emplace_back(std::stoul(hashName), absPath(files[0]));
            }
        }
    }

    return std::move(result);
}

} // namespace filesystem
} // namespace ghoul
<commit_msg>Allow the CacheManager fix manually deleted cache directories<commit_after>/*****************************************************************************************
 *                                                                                *
 * GHOUL                                                                                *
 * General Helpful Open Utility Library                                                  *
 *                                                                                *
 * Copyright (c) 2012-2014                                                               *
 *                                                                                *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this  *
 * software and associated documentation files (the "Software"), to deal in the Software *
 * without restriction, including without limitation the rights to use, copy, modify,    *
 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to    *
 * permit persons to whom the Software is furnished to do so, subject to the following   *
 * conditions:                                                                           *
 *                                                                                *
 * The above copyright notice and this permission notice shall be included in all copies *
 * or substantial portions of the Software.                                              *
 *                                                                                *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,   *
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A         *
 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT    *
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF  *
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE  *
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                                         *
 ****************************************************************************************/

#include <ghoul/filesystem/cachemanager.h>

#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/crc32.h>

#include <algorithm>
#include <assert.h>
#include <fstream>
#include <string>

namespace {
	const std::string _loggerCat = "CacheManager";
	const std::string _cacheFile = "cache";
	const char _hashDelimiter = '|'; // something that cannot occur in the filesystem
}

namespace ghoul {
namespace filesystem {

CacheManager::CacheManager(std::string directory)
    : _directory(std::move(directory))
{
    // In the cache state, we check our cache directory for all values, in a later step
    // we remove all persistent values, so that only the non-persistent values remain
    // Under normal operation, the resulting vector should be of size == 0, but if the
    // last execution of the application crashed, the directory was not cleaned up
    // properly
    std::vector<LoadedCacheInfo> cacheState = cacheInformationFromDirectory(_directory);
	std::string&& path = FileSys.pathByAppendingComponent(_directory, _cacheFile);

	std::ifstream file(path);
	if (file.good()) {
		std::string line;
        // loading the cache file that might exist from a previous run of the application
        // and reading all the persistent files from that file
		while (std::getline(file, line)) {
            // The structure of the cache file is assumed as follows (writting in the
            // destructor call of the application's previous run):
            // for each file:
            //   hash number\n
            //   filepath\n
			std::stringstream s(line);

			unsigned int hash;
			s >> hash;

			CacheInformation info;
			std::getline(file, info.file);
			info.isPersistent = true;
			_files.emplace(hash, info);

            // If the current hash + file is contained in the cache state, we have to
            // remove it
			cacheState.erase(std::remove_if(cacheState.begin(), cacheState.end(),
				[hash, &info](const LoadedCacheInfo& i) {
					return hash == i.first && info.file == i.second;
				}), cacheState.end());
		}
	}

    // At this point all values that remain in the cache state vector are left from a
    // previous crash of the application
    if (!cacheState.empty()) {
        LINFO("There was a crash in the previous run and it left the cache unclean. "
              "Cleaning it now");
        for (auto cache : cacheState) {
            LINFO("Deleting file '" << cache.second << "'");
            FileSys.deleteFile(cache.second);
        }
        cleanDirectory(_directory);
    }
}

CacheManager::~CacheManager() {
	std::string&& path = FileSys.pathByAppendingComponent(_directory, _cacheFile);
	std::ofstream file(path, std::ofstream::out);
	if (file.good()) {
		for (auto p : _files) {
			if (!p.second.isPersistent) {
                // Delete all the non-persistent files
				if (FileSys.fileExists(p.second.file))
					FileSys.deleteFile(p.second.file);
			}
			else
                // Save the persistent files in the cache file
				file << p.first << std::endl <<
						p.second.file << std::endl;
		}
		file.close();
	}
	else
		LERROR("Could not open file '" << path << "' for writing permanent cache files");
	cleanDirectory(_directory);
}

bool CacheManager::getCachedFile(const File& file, std::string& cachedFileName,
	bool isPersistent)
{
	std::string lastModifiedTime = file.lastModifiedDate();
	return getCachedFile(file, lastModifiedTime, cachedFileName, isPersistent);
}

bool CacheManager::getCachedFile(const File& file, const std::string& information,
                                 std::string &cachedFileName, bool isPersistent)
{
    return getCachedFile(file.filename(), information, cachedFileName, isPersistent);
}

bool CacheManager::getCachedFile(const std::string& baseName,
                                 const std::string& information,
                                 std::string& cachedFileName, bool isPersistent)
{
    size_t pos = baseName.find_first_of("/\\?%*:|\"<>");
    if (pos != std::string::npos) {
        LERROR("Base name '" << baseName << "' consists of illegal character");
        return false;
    }

	unsigned int hash = generateHash(baseName, information);

    // If we couldn't find the file, we have to generate a directory with the name of the
    // hash and return the full path containing of the cache path + requested filename +
    // hash value
	std::string destinationBase = FileSys.pathByAppendingComponent(_directory, baseName);

    // If this is the first time anyone requests a cache for the file name, we have to
    // create the base directory under the cache directory
	if (!FileSys.directoryExists(destinationBase))
		FileSys.createDirectory(destinationBase);

	std::string destination = FileSys.pathByAppendingComponent(destinationBase,
		std::to_string(hash));

    // The new destination should always not exist, since we checked before if we have the
    // value in the map and only get here if it isn't; persistent cache entries are always
    // in the map and non-persistent entries should have been deleted on application close
	if (!FileSys.directoryExists(destination))
		FileSys.createDirectory(destination);

	auto it = _files.find(hash);
	if (it != _files.end()) {
		// If we find the hash, it has been created before and we can just return the
		// file name to the caller
		cachedFileName = it->second.file;
		return true;
	}

    // Generate and output the newly generated cache name
	cachedFileName = FileSys.pathByAppendingComponent(destination, baseName);

    // Store the cache information in the map
	CacheInformation info = {
		cachedFileName,
		isPersistent
	};
	_files.emplace(hash, info);
	return true;
}

bool CacheManager::hasCachedFile(const File& file) const {
	std::string lastModifiedTime = file.lastModifiedDate();
	return hasCachedFile(file, lastModifiedTime);
}

bool CacheManager::hasCachedFile(const File& file, const std::string& information) const {
    return hasCachedFile(file.filename(), information);
}

bool CacheManager::hasCachedFile(const std::string& baseName,
                                 const std::string& information) const
{
    size_t pos = baseName.find_first_of("/\\?%*:|\"<>.");
    if (pos != std::string::npos) {
        LERROR("Base name '" << baseName << "' consists of illegal character");
        return false;
    }

    unsigned int hash = generateHash(baseName, information);
    return _files.find(hash) != _files.end();
}

void CacheManager::removeCacheFile(const File& file) {
	std::string lastModifiedTime = file.lastModifiedDate();
	removeCacheFile(file, lastModifiedTime);
}

void CacheManager::removeCacheFile(const File& file, const std::string& information) {
    removeCacheFile(file.filename(), information);
}

void CacheManager::removeCacheFile(const std::string& baseName,
                         const std::string& information)
{
    size_t pos = baseName.find_first_of("/\\?%*:|\"<>.");
    if (pos != std::string::npos) {
        LERROR("Base name '" << baseName << "' consists of illegal character");
        return;
    }

    unsigned int hash = generateHash(baseName, information);

    auto it = _files.find(hash);
    if (it != _files.end()) {
        // If we find the hash, it has been created before and we can just return the
        // file name to the caller
        const std::string& cachedFileName = it->second.file;
        FileSys.deleteFile(cachedFileName);
        _files.erase(it);
    }
}

unsigned int CacheManager::generateHash(std::string file, std::string information) const
{
	std::string hashString = file + _hashDelimiter + information;
	unsigned int hash = hashCRC32(hashString);

	return hash;
}

void CacheManager::cleanDirectory(const Directory& dir) const {
    LDEBUG("Cleaning directory '" << dir << "'");
    // First search for all subdirectories and call this function recursively on them
	std::vector<std::string> contents = dir.readDirectories();
	for (auto content : contents) {
        if (FileSys.directoryExists(content)) {
			cleanDirectory(content);
        }
	}
    // We get to this point in the recursion if either all subdirectories have been
    // deleted or there exists a file somewhere in the directory tree

	contents = dir.read();
    bool isEmpty = contents.size() == 0;
#ifdef __APPLE__
    // Apple stores the .DS_Store directory in the directory which can be removed
    std::string dsStore = FileSys.pathByAppendingComponent(dir, ".DS_Store");
    isEmpty |= ((contents.size() == 1) && contents[0] == dsStore);
#endif
    // If this directory is empty, we can delete it
    if (isEmpty) {
        LDEBUG("Deleting directory '" << dir << "'");
		FileSys.deleteDirectory(dir);
    }
}

std::vector<CacheManager::LoadedCacheInfo> CacheManager::cacheInformationFromDirectory(
    const Directory& dir) const
{
    std::vector<LoadedCacheInfo> result;
    std::vector<std::string> directories = dir.readDirectories(false);
    for (auto directory : directories) {
        Directory d(directory);

        // Extract the name of the directory
        // +1 as the last path delimiter is missing from the path
        std::string directoryName = directory.substr(dir.path().size() + 1);

        std::vector<std::string> hashes = d.readDirectories();
        for (auto hash : hashes) {
            // Extract the hash from the directory name
            // +1 as the last path delimiter is missing from the path
            std::string hashName = hash.substr(d.path().size() + 1);

            std::vector<std::string> files = Directory(hash).readFiles();
            // Cache directories should only contain a single file with the
            // same name as the directory
            if (files.size() > 1)
                LERROR("Directory '" << hash << "' contained more than one file");
            if (files.size() == 1) {
                // Extract the file name from the full path
                // +1 as the last path delimiter is missing from the path
                std::string filename = files[0].substr(Directory(hash).path().size() + 1);
				if (filename != directoryName)
					LERROR("File contained in cache directory '" <<
					hash << "' contains a file with name '" << filename <<
					"instead of the expected '" << directoryName << "'");
				else
					// Adding the absPath to normalize all / and \ for Windows
					result.emplace_back(std::stoul(hashName), absPath(files[0]));
            }
        }
    }

    return std::move(result);
}

} // namespace filesystem
} // namespace ghoul
<|endoftext|>


<commit_before>/*
 * IpcChannelUnitTest.cpp
 *
 *  Created on: Feb 6, 2015
 *      Author: Tim Nicholls, STFC Application Engineering Group
 */

#include <boost/test/unit_test.hpp>

#include "IpcChannel.h"

struct TestFixture
{
    TestFixture() :
        send_channel(ZMQ_PAIR),
        recv_channel(ZMQ_PAIR)

    {
        BOOST_TEST_MESSAGE("Setup test fixture");
        send_channel.bind("inproc://rx_channel");
        recv_channel.connect("inproc://rx_channel");
    }

    ~TestFixture()
    {
        BOOST_TEST_MESSAGE("Tear down test fixture");
    }

    FrameReceiver::IpcChannel send_channel;
    FrameReceiver::IpcChannel recv_channel;
};

BOOST_FIXTURE_TEST_SUITE( IpcChannelUnitTest , TestFixture);

BOOST_AUTO_TEST_CASE( InprocBasicSendReceive )
{
    std::string testMessage("This is a test message");
    std::cout << testMessage.length() << " : >>" << testMessage << "<<" << std::endl;;

    send_channel.send(testMessage);
    std::string reply = recv_channel.recv();
    std::cout << reply.length() << " : >>" << reply << "<<" << std::endl;

    BOOST_CHECK_EQUAL(testMessage, reply);

}

BOOST_AUTO_TEST_CASE( BasicSendReceiveWithPoll )
{

    std::string testMessage("Basic poll test message");
    send_channel.send(testMessage);

    BOOST_CHECK(recv_channel.poll(-1));
    std::string reply = recv_channel.recv();
    BOOST_CHECK_EQUAL(testMessage, reply);

}

BOOST_AUTO_TEST_SUITE_END();

<commit_msg>Tidying up stray cout messages in IpcChannelUnitTest.cpp<commit_after>/*
 * IpcChannelUnitTest.cpp
 *
 *  Created on: Feb 6, 2015
 *      Author: Tim Nicholls, STFC Application Engineering Group
 */

#include <boost/test/unit_test.hpp>

#include "IpcChannel.h"

struct TestFixture
{
    TestFixture() :
        send_channel(ZMQ_PAIR),
        recv_channel(ZMQ_PAIR)

    {
        BOOST_TEST_MESSAGE("Setup test fixture");
        send_channel.bind("inproc://rx_channel");
        recv_channel.connect("inproc://rx_channel");
    }

    ~TestFixture()
    {
        BOOST_TEST_MESSAGE("Tear down test fixture");
    }

    FrameReceiver::IpcChannel send_channel;
    FrameReceiver::IpcChannel recv_channel;
};

BOOST_FIXTURE_TEST_SUITE( IpcChannelUnitTest , TestFixture);

BOOST_AUTO_TEST_CASE( InprocBasicSendReceive )
{
    std::string testMessage("This is a test message");

    send_channel.send(testMessage);
    std::string reply = recv_channel.recv();

    BOOST_CHECK_EQUAL(testMessage, reply);

}

BOOST_AUTO_TEST_CASE( BasicSendReceiveWithPoll )
{

    std::string testMessage("Basic poll test message");
    send_channel.send(testMessage);

    BOOST_CHECK(recv_channel.poll(-1));
    std::string reply = recv_channel.recv();
    BOOST_CHECK_EQUAL(testMessage, reply);

}

BOOST_AUTO_TEST_SUITE_END();

<|endoftext|>


<commit_before>/*
 *  RBCreditsControl.cpp
 *  golf
 *
 *  Created by Robert Rose on 4/25/09.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */

#include "RBCreditsControl.h"

#include "RudeFont.h"

RBCreditsControl::RBCreditsControl()
{
}

void RBCreditsControl::Render()
{
	RudeControl::Render();

	if(RUDE_IPAD)
	{

		int yoffset = 550;
		int y = yoffset;

		const int kNumThanks = 5;

		const char * kThanks[kNumThanks] = {
			"\"Anytime Golf\", \"Anytime Golf: Magic Touch\", \"Bork3D Games\"",
			"and associated logos are Copyright © Bork 3D LLC",
			"",
			"Made with the Bork3D Game Engine",
			"For more information please visit bork3d.com"
		};

		y += 20;

		for(int i = 0; i < kNumThanks; i++)
		{
			RudeFontManager::GetFont(kDefaultFontOutline)->Write(768/2, y, 0.0f, kThanks[i], 0, FONT_ALIGN_CENTER, 0xFF000000, 0xFF000000);
			RudeFontManager::GetFont(kDefaultFont)->Write(768/2, y, 0.0f, kThanks[i], 0, FONT_ALIGN_CENTER, 0xFFFFFFFF, 0xFFCCCCCC);

			y+= 28;
		}
	}
	else
	{
		int yoffset = 200;
		int y = yoffset;

		RudeFontManager::GetFont(kBigFontOutline)->Write(320/2, y, 0.0f, "Credits", 0, FONT_ALIGN_CENTER, 0xFF000000, 0xFF000000);
		RudeFontManager::GetFont(kBigFont)->Write(320/2, y, 0.0f, "Credits", 0, FONT_ALIGN_CENTER, 0xFFFFFFFF, 0xFFFFE9CA);

		typedef struct {
			const char *title;
			const char *name;
		} tName;

		const int kNumLines = 4;

		const tName kLines[kNumLines] = {
			{ "Programming:" , "Robert Rose" },
			{ "Art:" , "Jake Helms" },
			{ "Animation:" , "Keo Heng" },
			{ "Music:" , "Mick Rippon" }
		};

		y += 40;
		int inset = 50;

		for(int i = 0; i < kNumLines; i++)
		{

			RudeFontManager::GetFont(kDefaultFontOutline)->Write(inset, y, 0.0f, kLines[i].title, 0, FONT_ALIGN_LEFT, 0xFF000000, 0xFF000000);
			RudeFontManager::GetFont(kDefaultFont)->Write(inset, y, 0.0f, kLines[i].title, 0, FONT_ALIGN_LEFT, 0xFFFFFFFF, 0xFFCCCCCC);

			RudeFontManager::GetFont(kDefaultFontOutline)->Write(320 - inset, y, 0.0f, kLines[i].name, 0, FONT_ALIGN_RIGHT, 0xFF000000, 0xFF000000);
			RudeFontManager::GetFont(kDefaultFont)->Write(320 - inset, y, 0.0f, kLines[i].name, 0, FONT_ALIGN_RIGHT, 0xFFFFFFFF, 0xFFCCCCCC);

			y += 20;
		}

		const int kNumThanks = 4;

		const char * kThanks[kNumThanks] = {
			"Special thanks to Maria and Monica",
			"for making this game possible.",
			"",
			"www.bork3d.com"
		};

		y += 20;

		for(int i = 0; i < kNumThanks; i++)
		{
			RudeFontManager::GetFont(kDefaultFontOutline)->Write(320/2, y, 0.0f, kThanks[i], 0, FONT_ALIGN_CENTER, 0xFF000000, 0xFF000000);
			RudeFontManager::GetFont(kDefaultFont)->Write(320/2, y, 0.0f, kThanks[i], 0, FONT_ALIGN_CENTER, 0xFFFFFFFF, 0xFFCCCCCC);

			y+= 16;
		}
	}
}
<commit_msg>Updatd credits for iphone<commit_after>/*
 *  RBCreditsControl.cpp
 *  golf
 *
 *  Created by Robert Rose on 4/25/09.
 *  Copyright 2009 __MyCompanyName__. All rights reserved.
 *
 */

#include "RBCreditsControl.h"

#include "RudeFont.h"

RBCreditsControl::RBCreditsControl()
{
}

void RBCreditsControl::Render()
{
	RudeControl::Render();

	if(RUDE_IPAD)
	{

		int yoffset = 550;
		int y = yoffset;

		const int kNumThanks = 5;

		const char * kThanks[kNumThanks] = {
			"\"Anytime Golf\", \"Anytime Golf: Magic Touch\", \"Bork3D Games\"",
			"and associated logos are Copyright © Bork 3D LLC",
			"",
			"Made with the Bork3D Game Engine",
			"For more information please visit bork3d.com"
		};

		y += 20;

		for(int i = 0; i < kNumThanks; i++)
		{
			RudeFontManager::GetFont(kDefaultFontOutline)->Write(768/2, y, 0.0f, kThanks[i], 0, FONT_ALIGN_CENTER, 0xFF000000, 0xFF000000);
			RudeFontManager::GetFont(kDefaultFont)->Write(768/2, y, 0.0f, kThanks[i], 0, FONT_ALIGN_CENTER, 0xFFFFFFFF, 0xFFCCCCCC);

			y+= 28;
		}
	}
	else
	{
		int yoffset = 160;
		int y = yoffset;

		RudeFontManager::GetFont(kBigFontOutline)->Write(320/2, y, 0.0f, "Credits", 0, FONT_ALIGN_CENTER, 0xFF000000, 0xFF000000);
		RudeFontManager::GetFont(kBigFont)->Write(320/2, y, 0.0f, "Credits", 0, FONT_ALIGN_CENTER, 0xFFFFFFFF, 0xFFFFE9CA);

		typedef struct {
			const char *title;
			const char *name;
		} tName;

		const int kNumLines = 4;

		const tName kLines[kNumLines] = {
			{ "Programming:" , "Robert Rose" },
			{ "Art:" , "Jake Helms" },
			{ "Animation:" , "Keo Heng" },
			{ "Music:" , "Mick Rippon" }
		};

		y += 40;
		int inset = 50;

		for(int i = 0; i < kNumLines; i++)
		{

			RudeFontManager::GetFont(kDefaultFontOutline)->Write(inset, y, 0.0f, kLines[i].title, 0, FONT_ALIGN_LEFT, 0xFF000000, 0xFF000000);
			RudeFontManager::GetFont(kDefaultFont)->Write(inset, y, 0.0f, kLines[i].title, 0, FONT_ALIGN_LEFT, 0xFFFFFFFF, 0xFFCCCCCC);

			RudeFontManager::GetFont(kDefaultFontOutline)->Write(320 - inset, y, 0.0f, kLines[i].name, 0, FONT_ALIGN_RIGHT, 0xFF000000, 0xFF000000);
			RudeFontManager::GetFont(kDefaultFont)->Write(320 - inset, y, 0.0f, kLines[i].name, 0, FONT_ALIGN_RIGHT, 0xFFFFFFFF, 0xFFCCCCCC);

			y += 20;
		}

		const int kNumThanks = 8;

		const char * kThanks[kNumThanks] = {
			"Special thanks to Maria and Monica.",
			"",
			"\"Anytime Golf\", \"Anytime Golf: Magic Touch\",",
			"\"Bork3D Games\" and associated logos are",
			"Copyright © Bork 3D LLC.",
			"",
			"Made with the Bork3D Game Engine.",
			"For more information please visit bork3d.com"
		};

		y += 16;

		for(int i = 0; i < kNumThanks; i++)
		{
			RudeFontManager::GetFont(kDefaultFontOutline)->Write(320/2, y, 0.0f, kThanks[i], 0, FONT_ALIGN_CENTER, 0xFF000000, 0xFF000000);
			RudeFontManager::GetFont(kDefaultFont)->Write(320/2, y, 0.0f, kThanks[i], 0, FONT_ALIGN_CENTER, 0xFFFFFFFF, 0xFFCCCCCC);

			y+= 16;
		}
	}
}
<|endoftext|>


<commit_before>/**
 * Copyright 2008 Matthew Graham
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "client_server_test.h"
#include <testpp/test.h>

mock_connection_c::mock_connection_c( std::queue< std::string > &read_queue,
			std::queue< std::string > &write_queue )
: m_read_queue( read_queue )
, m_write_queue( write_queue )
{}

void mock_connection_c::read_line( std::string &line )
{
	line = m_read_queue.front();
	m_read_queue.pop();
}

void mock_connection_c::write_line( const std::string &line )
{
	m_write_queue.push( line );
}

bool mock_connection_c::line_ready() const
{
	return ! m_read_queue.empty();
}

mock_client_server_connection_c::mock_client_server_connection_c()
: m_client_read_queue()
, m_server_read_queue()
, m_client( m_client_read_queue, m_server_read_queue )
, m_server( m_server_read_queue, m_client_read_queue )
{}

<commit_msg>added a test to verify that the client/server code works, not including any actual networking code.  got some mocks into the test.  need to add the actual execution and assertions now.<commit_after>/**
 * Copyright 2008 Matthew Graham
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "client_server_test.h"
#include "blocking_client_queue.h"
#include "polling_server_queue.h"
#include "connection_listener_test.h"
#include <testpp/test.h>

mock_connection_c::mock_connection_c( std::queue< std::string > &read_queue,
			std::queue< std::string > &write_queue )
: m_read_queue( read_queue )
, m_write_queue( write_queue )
{}

void mock_connection_c::read_line( std::string &line )
{
	line = m_read_queue.front();
	m_read_queue.pop();
}

void mock_connection_c::write_line( const std::string &line )
{
	m_write_queue.push( line );
}

bool mock_connection_c::line_ready() const
{
	return ! m_read_queue.empty();
}

mock_client_server_connection_c::mock_client_server_connection_c()
: m_client_read_queue()
, m_server_read_queue()
, m_client( m_client_read_queue, m_server_read_queue )
, m_server( m_server_read_queue, m_client_read_queue )
{}

TESTPP( test_client_server )
{
	mock_client_server_connection_c cs;

	blocking_client_queue_c client( cs.client() );
	mock_connection_listener_c listener( cs.server() );
	polling_server_queue_c server( listener );

	not_implemented();

	// need to add code and assertions here
	// create client command
	// send command to client
	// execute dispatcher
	// read client response
}

<|endoftext|>


<commit_before>/// \file PasswordSafe.cpp
/// \brief  Defines the class behaviors for the application.
//-----------------------------------------------------------------------------

#include "stdafx.h"
#include "PasswordSafe.h"

#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>

#include "PasskeyEntry.h"
#include "PasskeySetup.h"
#include "CryptKeyEntry.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//-----------------------------------------------------------------------------
/*
  The one and only CPasswordSafeApp object.  In the MFC world, creating
  this global object is what starts the application.
*/

CPasswordSafeApp app;

//-----------------------------------------------------------------------------

BEGIN_MESSAGE_MAP(CPasswordSafeApp, CWinApp)
//   ON_COMMAND(ID_HELP, CWinApp::OnHelp)
   ON_COMMAND(ID_HELP, OnHelp)
END_MESSAGE_MAP()

CPasswordSafeApp::CPasswordSafeApp()
{
   srand((unsigned)time(NULL));
}

CPasswordSafeApp::~CPasswordSafeApp()
{
#if !defined(WITH_BACKEND)
   //We no longer need the global bf_P and bf_S variables, so trash them
   trashMemory((unsigned char*)tempbf_P, 18*4);
   trashMemory((unsigned char*)tempbf_S, 256*4);
   trashMemory((unsigned char*)bf_P, 18*4);
   trashMemory((unsigned char*)bf_S, 256*4);
#endif

   /*
     apparently, with vc7, there's a CWinApp::HtmlHelp - I'd like
     to see the docs, someday.  In the meantime, force with :: syntax
   */

   ::HtmlHelp(NULL, NULL, HH_CLOSE_ALL, 0);
}

BOOL
CPasswordSafeApp::InitInstance()
{
   /*
    * It's always best to start at the beginning.  [Glinda, Witch of the North]
    */

   // these 3d enables are signalled as deprecated by VC7...
#ifdef _AFXDLL
   Enable3dControls();          // Call this when using MFC in a shared DLL
#else
   Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

   if (GetOSVersion() == Win32s)
   {
      AfxMessageBox(
         "Sorry. Password Safe uses advanced Windows features and\n"
         "cannot be run under Windows 3.x with Win32s\n"
         "The program will terminate now.");
      exit(20);
   }

   /*
     save the current directory in a data member - I wonder why {jpr}
   */

   char fn[_MAX_PATH];
   int result = GetCurrentDirectory(_MAX_PATH, fn);
   if ((result == 0) || (result > _MAX_PATH))
      m_curdir = "";
   else
      m_curdir = (CMyString)fn + (CMyString) "\\";

   /*
     this pulls 'Counterpane Systems' out of the string table, verifies
     that it exists (actually, only verifies that *some* IDS_COMPANY
     string exists -- it could be 'Microsoft' for all we know), and then
     instructs the app to use the registry instead of .ini files.  The
     path ends up being

     HKEY_CURRENT_USER\Software\(companyname)\(appname)\(sectionname)\(valuename)

     Assuming the open-source version of this is going to become less
     Counterpane-centric, I expect this may change, but if it does, an
     automagic migration ought to happen. -- {jpr}
   */

   CMyString companyname;
   VERIFY(companyname.LoadString(IDS_COMPANY) != 0);
   SetRegistryKey(companyname);

   /*
     Command line processing or main dialog box?
   */

   if (m_lpCmdLine[0] != '\0')
   {
      CCryptKeyEntry dlg(NULL);
      int nResponse = dlg.DoModal();

      if (nResponse==IDOK)
      {
         m_passkey = dlg.m_cryptkey1;
         manageCmdLine(m_lpCmdLine);
      }
      /*
       * we're done with the 'commandline version' - exit the app
       */
      return FALSE;
   }

   /*
    * normal startup
    */

   /*
    * here's where PWS currently does DboxMain, which in turn will do
    * the initial PasskeyEntry.  This makes things very hard to control.
    * The app object (here) should instead do the initial PasskeyEntry,
    * and, if successful, move on to DboxMain.  I think. {jpr}
    */

   m_maindlg = new DboxMain(NULL);
   m_pMainWnd = m_maindlg;

   //Set up an Accelerator table
   m_ghAccelTable = LoadAccelerators(AfxGetInstanceHandle(),
                                     MAKEINTRESOURCE(IDR_ACCS));

   //Run dialog
   //int rc  = m_maindlg->DoModal();
   (void) m_maindlg->DoModal();

   /*
     note that we don't particularly care what the response was
   */

   delete m_maindlg;

   // Since the dialog has been closed, return FALSE so that we exit the
   //  application, rather than start the application's message pump.

   return FALSE;
}

//Copied from Knowledge Base article Q100770
BOOL
CPasswordSafeApp::ProcessMessageFilter(int code,
                                       LPMSG lpMsg)
{
   if (code < 0)
      CWinApp::ProcessMessageFilter(code, lpMsg);

   if (m_maindlg != NULL
       && m_ghAccelTable != NULL)
   {
      if (::TranslateAccelerator(m_maindlg->m_hWnd, m_ghAccelTable, lpMsg))
         return TRUE;
   }
   return CWinApp::ProcessMessageFilter(code, lpMsg);
}

void
CPasswordSafeApp::OnHelp()
{
   ::HtmlHelp(NULL,
              "pwsafe.chm::/html/pws_intro.htm",
              HH_DISPLAY_TOPIC, 0);
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
<commit_msg>Add BlowFish header<commit_after>/// \file PasswordSafe.cpp
/// \brief  Defines the class behaviors for the application.
//-----------------------------------------------------------------------------

#include "stdafx.h"
#include "PasswordSafe.h"

#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>

#include "PasskeyEntry.h"
#include "PasskeySetup.h"
#include "CryptKeyEntry.h"

#include "BlowFish.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

//-----------------------------------------------------------------------------
/*
  The one and only CPasswordSafeApp object.  In the MFC world, creating
  this global object is what starts the application.
*/

CPasswordSafeApp app;

//-----------------------------------------------------------------------------

BEGIN_MESSAGE_MAP(CPasswordSafeApp, CWinApp)
//   ON_COMMAND(ID_HELP, CWinApp::OnHelp)
   ON_COMMAND(ID_HELP, OnHelp)
END_MESSAGE_MAP()

CPasswordSafeApp::CPasswordSafeApp()
{
   srand((unsigned)time(NULL));
}

CPasswordSafeApp::~CPasswordSafeApp()
{
#if !defined(WITH_BACKEND)
   //We no longer need the global bf_P and bf_S variables, so trash them
   trashMemory((unsigned char*)tempbf_P, 18*4);
   trashMemory((unsigned char*)tempbf_S, 256*4);
   trashMemory((unsigned char*)bf_P, 18*4);
   trashMemory((unsigned char*)bf_S, 256*4);
#endif

   /*
     apparently, with vc7, there's a CWinApp::HtmlHelp - I'd like
     to see the docs, someday.  In the meantime, force with :: syntax
   */

   ::HtmlHelp(NULL, NULL, HH_CLOSE_ALL, 0);
}

BOOL
CPasswordSafeApp::InitInstance()
{
   /*
    * It's always best to start at the beginning.  [Glinda, Witch of the North]
    */

   // these 3d enables are signalled as deprecated by VC7...
#ifdef _AFXDLL
   Enable3dControls();          // Call this when using MFC in a shared DLL
#else
   Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif

   if (GetOSVersion() == Win32s)
   {
      AfxMessageBox(
         "Sorry. Password Safe uses advanced Windows features and\n"
         "cannot be run under Windows 3.x with Win32s\n"
         "The program will terminate now.");
      exit(20);
   }

   /*
     save the current directory in a data member - I wonder why {jpr}
   */

   char fn[_MAX_PATH];
   int result = GetCurrentDirectory(_MAX_PATH, fn);
   if ((result == 0) || (result > _MAX_PATH))
      m_curdir = "";
   else
      m_curdir = (CMyString)fn + (CMyString) "\\";

   /*
     this pulls 'Counterpane Systems' out of the string table, verifies
     that it exists (actually, only verifies that *some* IDS_COMPANY
     string exists -- it could be 'Microsoft' for all we know), and then
     instructs the app to use the registry instead of .ini files.  The
     path ends up being

     HKEY_CURRENT_USER\Software\(companyname)\(appname)\(sectionname)\(valuename)

     Assuming the open-source version of this is going to become less
     Counterpane-centric, I expect this may change, but if it does, an
     automagic migration ought to happen. -- {jpr}
   */

   CMyString companyname;
   VERIFY(companyname.LoadString(IDS_COMPANY) != 0);
   SetRegistryKey(companyname);

   /*
     Command line processing or main dialog box?
   */

   if (m_lpCmdLine[0] != '\0')
   {
      CCryptKeyEntry dlg(NULL);
      int nResponse = dlg.DoModal();

      if (nResponse==IDOK)
      {
         m_passkey = dlg.m_cryptkey1;
         manageCmdLine(m_lpCmdLine);
      }
      /*
       * we're done with the 'commandline version' - exit the app
       */
      return FALSE;
   }

   /*
    * normal startup
    */

   /*
    * here's where PWS currently does DboxMain, which in turn will do
    * the initial PasskeyEntry.  This makes things very hard to control.
    * The app object (here) should instead do the initial PasskeyEntry,
    * and, if successful, move on to DboxMain.  I think. {jpr}
    */

   m_maindlg = new DboxMain(NULL);
   m_pMainWnd = m_maindlg;

   //Set up an Accelerator table
   m_ghAccelTable = LoadAccelerators(AfxGetInstanceHandle(),
                                     MAKEINTRESOURCE(IDR_ACCS));

   //Run dialog
   //int rc  = m_maindlg->DoModal();
   (void) m_maindlg->DoModal();

   /*
     note that we don't particularly care what the response was
   */

   delete m_maindlg;

   // Since the dialog has been closed, return FALSE so that we exit the
   //  application, rather than start the application's message pump.

   return FALSE;
}

//Copied from Knowledge Base article Q100770
BOOL
CPasswordSafeApp::ProcessMessageFilter(int code,
                                       LPMSG lpMsg)
{
   if (code < 0)
      CWinApp::ProcessMessageFilter(code, lpMsg);

   if (m_maindlg != NULL
       && m_ghAccelTable != NULL)
   {
      if (::TranslateAccelerator(m_maindlg->m_hWnd, m_ghAccelTable, lpMsg))
         return TRUE;
   }
   return CWinApp::ProcessMessageFilter(code, lpMsg);
}

void
CPasswordSafeApp::OnHelp()
{
   ::HtmlHelp(NULL,
              "pwsafe.chm::/html/pws_intro.htm",
              HH_DISPLAY_TOPIC, 0);
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
<|endoftext|>


<commit_before>/*************************************************************************************
 *  Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org>              *
 *                                                                                *
 *  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 Street, Fifth Floor, Boston, MA  02110-1301, USA   *
 *************************************************************************************/

#include <unistd.h>

#include <QtCore/QDebug>
#include <QtCore/QProcess>

#include <KApplication>
#include <KAboutData>
#include <KComponentData>
#include <KCmdLineArgs>
#include <KApplication>
#include <KAboutData>

#include "console.h"

using namespace std;

void showCommands()
{
    qDebug() << "Commands: " << endl;
    qDebug() << "    bug \t <Show information needed for a bug report>" << endl;
    qDebug() << "    config \t <Show kscreen config files>" << endl;
    qDebug() << "    outputs \t <Show Output information>" << endl;
    qDebug() << "    monitor \t <Monitors for changes>" << endl;
}
int main (int argc, char *argv[])
{
    dup2(1, 2);

    KAboutData aboutData("kscreen-console", "kscreen-console", ki18n("KScreen Console"), "1.0", ki18n("KScreen Console"),
    KAboutData::License_GPL, ki18n("(c) 2012 KScreen Team"));

    aboutData.addAuthor(ki18n("Alejandro Fiestas Olivares"), ki18n("Maintainer"), "afiestas@kde.org",
        "http://www.afiestas.org/");

    KCmdLineArgs::init(argc, argv, &aboutData);

    KCmdLineOptions options;
    options.add("commands", ki18n("Show available commands"));
    options.add("+[arg(s)]", ki18n("Arguments for command"));

    KCmdLineArgs::addCmdLineOptions(options);
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    if (args->isSet("commands")) {
        showCommands();
        return 1;
    }
    KApplication app;

    Console *loop = new Console(0);

    QString command;
    if (args->count() > 0) {
        command = args->arg(0);
    }

    if (command.isEmpty()) {
        loop->printConfig();
        loop->monitorAndPrint();
        return app.exec();
    }

    if (command == "monitor") {
        //Do nothing, enable backend output to see debug
        return app.exec();
    }

    if (command == "outputs") {
        loop->printConfig();
        return 1;
    }

    if (command == "config") {
        loop->printSerializations();
        return 1;
    }
    if (command == "bug") {
        qDebug() << endl << "========================xrandr --verbose==========================" << endl;
        QProcess proc;
        proc.setProcessChannelMode(QProcess::MergedChannels);
        proc.start("xrandr", QStringList("--verbose"));
        proc.waitForFinished();
        qDebug() << proc.readAll().data();
        qDebug() << endl << "========================Outputs===================================" << endl;
        loop->printConfig();
        qDebug() << endl << "========================Configurations============================" << endl;
        loop->printSerializations();
        return 1;
    }
    showCommands();
    return -1;
}
<commit_msg>Print config at the beginning of monitor<commit_after>/*************************************************************************************
 *  Copyright (C) 2012 by Alejandro Fiestas Olivares <afiestas@kde.org>              *
 *                                                                                *
 *  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 Street, Fifth Floor, Boston, MA  02110-1301, USA   *
 *************************************************************************************/

#include <unistd.h>

#include <QtCore/QDebug>
#include <QtCore/QProcess>

#include <KApplication>
#include <KAboutData>
#include <KComponentData>
#include <KCmdLineArgs>
#include <KApplication>
#include <KAboutData>

#include "console.h"

using namespace std;

void showCommands()
{
    qDebug() << "Commands: " << endl;
    qDebug() << "    bug \t <Show information needed for a bug report>" << endl;
    qDebug() << "    config \t <Show kscreen config files>" << endl;
    qDebug() << "    outputs \t <Show Output information>" << endl;
    qDebug() << "    monitor \t <Monitors for changes>" << endl;
}
int main (int argc, char *argv[])
{
    dup2(1, 2);

    KAboutData aboutData("kscreen-console", "kscreen-console", ki18n("KScreen Console"), "1.0", ki18n("KScreen Console"),
    KAboutData::License_GPL, ki18n("(c) 2012 KScreen Team"));

    aboutData.addAuthor(ki18n("Alejandro Fiestas Olivares"), ki18n("Maintainer"), "afiestas@kde.org",
        "http://www.afiestas.org/");

    KCmdLineArgs::init(argc, argv, &aboutData);

    KCmdLineOptions options;
    options.add("commands", ki18n("Show available commands"));
    options.add("+[arg(s)]", ki18n("Arguments for command"));

    KCmdLineArgs::addCmdLineOptions(options);
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
    if (args->isSet("commands")) {
        showCommands();
        return 1;
    }
    KApplication app;

    Console *console = new Console(0);

    QString command;
    if (args->count() > 0) {
        command = args->arg(0);
    }

    if (command.isEmpty()) {
        console->printConfig();
        console->monitorAndPrint();
        return app.exec();
    }

    if (command == "monitor") {
        qDebug() << "Remember to enable KSRandR or KSRandR11 in kdebugdialog";
        //Print config so that we have some pivot data
        console->printConfig();
        //Do nothing, enable backend output to see debug
        return app.exec();
    }

    if (command == "outputs") {
        console->printConfig();
        return 1;
    }

    if (command == "config") {
        console->printSerializations();
        return 1;
    }
    if (command == "bug") {
        qDebug() << endl << "========================xrandr --verbose==========================" << endl;
        QProcess proc;
        proc.setProcessChannelMode(QProcess::MergedChannels);
        proc.start("xrandr", QStringList("--verbose"));
        proc.waitForFinished();
        qDebug() << proc.readAll().data();
        qDebug() << endl << "========================Outputs===================================" << endl;
        console->printConfig();
        qDebug() << endl << "========================Configurations============================" << endl;
        console->printSerializations();
        return 1;
    }
    showCommands();
    return -1;
}
<|endoftext|>