text:
/* vim: set tabstop=4 : */
#ifndef __terark_io_hole_stream_h__
#define __terark_io_hole_stream_h__

#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif

//#include <assert.h>
//#include <string.h> // for memcpy
//#include <boost/current_function.hpp>
//#include <boost/type_traits/integral_constant.hpp>

#include <terark/stdtypes.hpp>
//#include "IOException.hpp"

namespace terark {

class HoleStream
{
public:
	explicit HoleStream() : m_pos(0) {}

//	size_t read(void* vbuf, size_t length) { m_pos += length; return length; }
	size_t write(const void* vbuf, size_t length) { m_pos += length; return length; }

//	void ensureRead(void* vbuf, size_t length) { m_pos += length; }
	void ensureWrite(const void* vbuf, size_t length) { m_pos += length; }

//	byte readByte() { return 0; }

	void writeByte(unsigned char) { m_pos++; }

private:
	stream_position_t m_pos;
};

class SeekableHoleStream
{
public:
	explicit SeekableHoleStream(stream_position_t size)
	{
		m_pos  = 0;
		m_size = size;
	}

private:
	stream_position_t m_pos;
	stream_position_t m_size;
};

} // namespace terark

#endif

max_stars_repo_name: rockeet/terark-zip

max_issues_repo_name: rockeet/terark-zip

max_forks_repo_name: rockeet/terark-zip


text:
//==============================================================================
//         Copyright 2003 - 2011   LASMEA UMR 6602 CNRS/Univ. Clermont II
//         Copyright 2009 - 2013   LRI    UMR 8623 CNRS/Univ Paris Sud XI
//         Copyright 2012 - 2013   MetaScale SAS
//
//          Distributed under the Boost Software License, Version 1.0.
//                 See accompanying file LICENSE.txt or copy at
//                     http://www.boost.org/LICENSE_1_0.txt
//==============================================================================
#ifndef BOOST_SIMD_META_IS_ALIGNED_HPP_INCLUDED
#define BOOST_SIMD_META_IS_ALIGNED_HPP_INCLUDED

#include <boost/simd/meta/is_power_of_2.hpp>
#include <boost/simd/preprocessor/parameters.hpp>
#include <boost/mpl/size_t.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/bool.hpp>
#include <cstddef>

namespace boost { namespace simd {  namespace meta
{
  /*!
    @brief Check alignment of arbitrary integral value

    Checks if any given integral value @c V is aligned on any
    given power of two boundary @c N.

    @par Semantic:
    For any given integral value @c N and @c V:

    @code
    typedef is_aligned_c<V,N>::type r;
    @endcode

    is equivalent to:

    @code
    typedef mpl::bool<!(V & (N-1) )>::type r;
    @endcode

    If @c N is not a power of two, a BOOST_SIMD_INVALID_ALIGNMENT_VALUE static
    assertion is triggered.

    @usage{meta/is_aligned_c.cpp}

    @tparam V Integral value to check
    @tparam N Alignment to check for. By default, @c N is equal to current
            architecture preferred alignment.
  **/
  template< std::size_t V
          , std::size_t N = BOOST_SIMD_CONFIG_ALIGNMENT
          >
  struct  is_aligned_c
#if !defined(DOXYGEN_ONLY)
        : boost::mpl::bool_<!(V & (N-1) )>
#endif
  {
#if !defined(DOXYGEN_ONLY)
    //==========================================================================
    //               ****BOOST_SIMD_INVALID_ALIGNMENT_VALUE****
    // If this static assert triggers, a call to is_aligned_c has been issued
    // with a non-power of 2 boundary argument.
    //               ****BOOST_SIMD_INVALID_ALIGNMENT_VALUE****
    //==========================================================================
    BOOST_MPL_ASSERT_MSG
    ( (boost::simd::meta::is_power_of_2_c<N>::value)
    , BOOST_SIMD_INVALID_ALIGNMENT_VALUE
    , (boost::mpl::int_<N>)
    );
#endif
  };

  /*!
    @brief Check alignment of arbitrary @mplint

    Checks if any given @mplint @c V is aligned on any given power of two
    boundary @c N.

    @par Semantic:
    For any given @mplint @c N and @c V:

    @code
    typedef is_aligned<V,N>::type r;
    @endcode

    is equivalent to:

    @code
    typedef is_aligned_c<V::value,N::value>::type r;
    @endcode

    If @c N is not a power of two, a BOOST_SIMD_INVALID_ALIGNMENT_VALUE static
    assertion is triggered.

    @par Models:

    @metafunction

    @usage{meta/is_aligned.cpp}

    @tparam V @mplint to check
    @tparam N Alignment to check for. By default, @c N is equal to current
            architecture preferred alignment.
  **/
  template< typename V
          , typename N = boost::mpl::size_t<BOOST_SIMD_CONFIG_ALIGNMENT>
          >
  struct  is_aligned
#if !defined(DOXYGEN_ONLY)
        : is_aligned_c<V::value,N::value>
#endif
  {};
} } }

#endif

ext: hpp


text:
/*
 * Copyright (c) 2013, The University of Oxford
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 * 2. 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.
 * 3. Neither the name of the University of Oxford 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 HOLDER 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 "DataViewerTest.h"
#include "DataViewer.h"
#include "TestDataViewerWidget.h"

#include "output/DataBlobClient.h"
#include "output/PelicanTCPBlobServer.h"
#include "output/Stream.h"
#include "data/test/TestDataBlob.h"
#include "utility/Config.h"
#include "utility/ConfigNode.h"
#include "output/test/TestDataBlobClient.h"

#include <QtGui/QApplication>
#include <QtCore/QDebug>
#include <boost/shared_ptr.hpp>

#include <iostream>
#include <unistd.h>

using namespace std;

namespace pelican {

using test::TestDataBlob;
using test::TestDataBlobClient;
using test::TestDataViewerWidget;

/**
 * @details Constructs a DataViewerTest object.
 */
DataViewerTest::DataViewerTest()
    : CppUnit::TestFixture()
{
}

/**
 * @details Destroys the DataViewerTest object.
 */
DataViewerTest::~DataViewerTest()
{
}

void DataViewerTest::test_client()
{
    QString testStream("testStream");
    boost::shared_ptr<TestDataBlob> blob( new TestDataBlob );
    blob->setData("somedata");

    // Use Case:
    // Add a simple DataBlobClient
    // and send some data
    //
    // Expect:
    // streams available to be updated
    // widgets update methods to be called
    //
    {
        Config config;
        Config::TreeAddress address;
        address << Config::NodeId("viewers", "");

        ConfigNode configNode;
        TestDataBlobClient client;
        DataViewer viewer(config, address);
        viewer.setClient(client);
        viewer.setStreamViewer(testStream, "TestDataViewerWidget");
        CPPUNIT_ASSERT_EQUAL(0, client.subscriptions().size() );
        viewer.enableStream(testStream);

        Stream str( testStream );
        str.setData(blob);
        client.send( str );
        QCoreApplication::processEvents();

        CPPUNIT_ASSERT_EQUAL( 1, viewer.streams().size() );
        CPPUNIT_ASSERT_EQUAL( testStream.toStdString() ,
                viewer.streams()[0].toStdString() );
        CPPUNIT_ASSERT_EQUAL(1, client.subscriptions().size() );
        CPPUNIT_ASSERT_EQUAL( 1, TestDataViewerWidget::updateCalled() );
    }
}

void DataViewerTest::test_integrationWithDataClient()
{
    // Use Case:
    // full integration test with a rela DataBlobClient
    // Setup a test server
    QString xml = "<PelicanTCPBlobServer>"
        "   <connection port=\"0\"/>"  // 0 = find unused system port
        "</PelicanTCPBlobServer>";

    ConfigNode config(xml);
    PelicanTCPBlobServer server(config);
    usleep(100);

    DataBlobClient* client = _client( &server );
//    DataViewer viewer(config, address);
//    viewer.setClient(client);
    TestDataBlob blob;
    blob.setData("integration test");
    server.send("testData", &blob);

    delete client;
}

DataBlobClient* DataViewerTest::_client( PelicanTCPBlobServer* server )
{
    QString conf = QString("<connection host=\"127.0.0.1\" />");
    ConfigNode config(conf);
    DataBlobClient* client = new DataBlobClient(config);
    client->setPort(server->serverPort());
    client->setHost("127.0.0.1");
    //connect( client, SIGNAL( newStreamsAvailable() ), this, SLOT( _newStreamsAvailable() ));
    return client;
}

} // namespace pelican

ext: cpp

max_stars_repo_name: pelican/pelican

max_issues_repo_name: pelican/pelican

max_forks_repo_name: pelican/pelican