<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: slide.hxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: obo $ $Date: 2005-10-11 08:54:29 $
 *
 *  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 _SLIDESHOW_SLIDE_HXX
#define _SLIDESHOW_SLIDE_HXX

#ifndef _COM_SUN_STAR_UNO_XCOMPONENTCONTEXT_HXX_
#include <com/sun/star/uno/XComponentContext.hpp>
#endif
#ifndef _COM_SUN_STAR_DRAWING_XDRAWPAGE_HPP_
#include <com/sun/star/drawing/XDrawPage.hpp>
#endif

#ifndef BOOST_SHARED_PTR_HPP_INCLUDED
#include <boost/shared_ptr.hpp>
#endif

#ifndef _CPPCANVAS_SPRITECANVAS_HXX
#include <cppcanvas/spritecanvas.hxx>
#endif

#ifndef _BGFX_VECTOR_B2ISIZE_HXX
#include <basegfx/vector/b2isize.hxx>
#endif

#include <vector>
#include <utility>

#include <unoview.hxx>
#include <event.hxx>
#include <layermanager.hxx>
#include <userpaintoverlay.hxx>
#include <slideanimations.hxx>
#include <slidebitmap.hxx>
#include <shapeeventbroadcaster.hxx>
#include "boost/optional.hpp"

/* Definition of Slide class */

namespace presentation
{
    namespace internal
    {
        class EventQueue;
        class ActivitiesQueue;
        class UserEventQueue;

        class Slide
        {
        public:
            /** Construct from XDrawPage

                Prefetches shapes from draw page, thus might take some
                time. The Slide object generally works in XDrawPage
                model coordinates, that is, the page will have the
                width and height as specified in the XDrawPage's
                property set. The top, left corner of the page will be
                rendered at (0,0) in the given canvas' view coordinate
                system.
             */
            Slide( const ::com::sun::star::uno::Reference<
                       ::com::sun::star::drawing::XDrawPage >&          xDrawPage,
                   const ::com::sun::star::uno::Reference<
                       ::com::sun::star::animations::XAnimationNode >&  xRootNode,
                   EventQueue&                                          rEventQueue,
                   ActivitiesQueue&                                     rActivitiesQueue,
                   EventMultiplexer&                                    rEventMultiplexer,
                   UserEventQueue&                                      rUserEventQueue,
                   const ::com::sun::star::uno::Reference<
                               ::com::sun::star::uno::XComponentContext >& xContext );

            ~Slide();

            /** Add a view to this slide
             */
            void addView( const UnoViewSharedPtr& rView );

            /** Remove a previously added a view from this slide

                @return true, if this view was successfully removed, false
                otherwise (e.g. if this view wasn't added in the first place)
            */
            bool removeView( const UnoViewSharedPtr& rView );

            /** Add the given listener for the given shape.

                This method implements the addShapeEventListener
                method of the XSlideShow interface. The given listener
                is called, whenever a user clicks on the shape. If the
                shape is not contained in this slide, this method does
                nothing.
             */
            void addShapeEventListener( const ::com::sun::star::uno::Reference<
                                                ::com::sun::star::presentation::XShapeEventListener >&  xListener,
                                        const ::com::sun::star::uno::Reference<
                                                ::com::sun::star::drawing::XShape >&                    xShape );

            /** Revoke the given listener for the given shape.

                This method implements the removeShapeEventListener
                method of the XSlideShow interface.
             */
            void removeShapeEventListener( const ::com::sun::star::uno::Reference<
                                                       ::com::sun::star::presentation::XShapeEventListener >&   xListener,
                                           const ::com::sun::star::uno::Reference<
                                                       ::com::sun::star::drawing::XShape >&                     xShape );

            /** Control intrinsic animation behaviour

                @param bImageAnimationsAllowed
                When true, GIF and drawing layer animations will be
                shown. When false, those shapes have no intrinsic
                animation.
             */
            void setImageAnimationsAllowed( bool bImageAnimationsAllowed );

            /** Set the mouse cursor for a given shape.

                This method implements the setShapeCursor method of
                the XSlideShow interface. Whenever the mouse hovers
                over the given shape, the specified mouse cursor will
                be shown. To reset the mouse cursor to the default,
                specify awt::SystemPointer::ARROW.
             */
            void setShapeCursor( const ::com::sun::star::uno::Reference<
                                         ::com::sun::star::drawing::XShape >&   xShape,
                                 sal_Int16                                      nPointerShape );

            /** Prepares to show slide.

                Call this method to reduce the timeout show(), and
                getInitialSlideBitmap() need to complete. If
                prefetchShow() is not called explicitely, the named
                methods will call it implicitely.
             */
            bool prefetchShow();

            /** Paint the slide on all registered views, without any effects
             */
            bool paint();

            /** Shows the slide on all registered views
             */
            bool show();

            /** Force-end the slide show.
             */
            void end();

            /** Query whether this slide is currently showing.

                @return true, if this slide is currently showing
                (i.e. show() was called more often than end()).
             */
            bool isShowing() const;

            /** Query whether the slide has animations at all

                If the slide doesn't have animations, show() is
                equivalent to paint(). If an event is registered with
                registerSlideEndEvent(), this event will be
                immediately activated at the end of the show() method.

                @return true, if this slide has animations, false
                otherwise
             */
            bool isAnimated();

            /** Request bitmap for current slide appearance.

                The bitmap returned by this method is dependent on the
                current state of the slide and the contained
                animations. A newly generated slide will return the
                initial slide content here (e.g. with all 'appear'
                effect shapes invisible), a slide whose effects are
                currently running will return a bitmap corresponding
                to the current position on the animation timeline, and
                a slide whose effects have all been run will generate
                a bitmap with the final slide appearance (e.g. with
                all 'hide' effect shapes invisible).

                @param rView
                View to retrieve bitmap for (note that the bitmap will
                have device-pixel equivalence to the content that
                would have been rendered onto the given view). Note
                that the view must have been added to this slide via
                addView() before, otherwise, this method will throw an
                exception.
             */
            // TODO(F2): Rework SlideBitmap to no longer be based on XBitmap,
            // but on canvas-independent basegfx bitmaps
            SlideBitmapSharedPtr getCurrentSlideBitmap( const UnoViewSharedPtr& rView );

            /** Query the slide, whether next slide should appear
                automatically.

                @return true, if next slide should be displayed
                automatically. When false is returned, the user is
                required to click to have the next slide shown.
             */
            bool hasAutomaticNextSlide() const;

            /** Query the slide for the timeout, until the next slide
                is automatically shown.

                This value is undefined, should
                hasAutomaticNextSlide() return false.

                @return a timeout in seconds, for which to delay the
                display of the next slide.
             */
            double getAutomaticNextSlideTimeout() const;

            /** Control the user paint mode.

                The user paint mode lets the user paint on this slide
                with the given color, when pressing down the
                mousebutton.
             */
            void setUserPaintColor( boost::optional<RGBColor> const& rColor );

            /// Query the XDrawPage's size
            basegfx::B2ISize getSlideSize() const;

            /// Get size of the slide in device coordinates for given view
            ::basegfx::B2ISize getSlideSizePixel(
                UnoViewSharedPtr const & pView ) const;

            /// Gets the underlying API page
            ::com::sun::star::uno::Reference<
                ::com::sun::star::drawing::XDrawPage > const&
            getXDrawPage() const { return mxDrawPage; }

            /// Gets the animation node.
            ::com::sun::star::uno::Reference<
                ::com::sun::star::animations::XAnimationNode > const&
            getXAnimationNode() const { return mxRootNode; }

        private:
            // default: disabled copy/assignment
            Slide(const Slide&);
            Slide& operator=( const Slide& );

            void enablePaintOverlay();
            void disablePaintOverlay();

            /// Set all Shapes to their initial attributes for slideshow
            bool applyInitialShapeAttributes( const ::com::sun::star::uno::Reference<
                                                  ::com::sun::star::animations::XAnimationNode >& xRootAnimationNode );

            /// Renders current slide content to bitmap
            SlideBitmapSharedPtr createCurrentSlideBitmap(
                const UnoViewSharedPtr& rView,
                ::basegfx::B2ISize const & rSlideSize );

            /// Prefetch all shapes (not the animations)
            bool prefetchShapes();

            /// Prefetch show, but don't call applyInitialShapeAttributes()
            bool implPrefetchShow();

            /// Query the rectangle covered by the slide
            ::basegfx::B2DRectangle getSlideRect() const;

            /// Start GIF and other intrinsic shape animations
            void endIntrinsicAnimations();

            /// End GIF and other intrinsic shape animations
            void startIntrinsicAnimations();

            // Types
            // =====

            enum SlideAnimationState
            {
                CONSTRUCTING_STATE=0,
                INITIAL_STATE=1,
                SHOWING_STATE=2,
                FINAL_STATE=3,
                SlideAnimationState_NUM_ENTRIES=4
            };

            /** Vector of slide bitmaps.

                Since the bitmap content is sensitive to animation
                effects, we have an inner vector containing a distinct
                bitmap for each of the SlideAnimationStates.
             */
            typedef ::std::vector< ::std::vector< SlideBitmapSharedPtr > > VectorOfSlideBitmaps;

            // Member variables
            // ================

            /// The page model object
            ::com::sun::star::uno::Reference<
                ::com::sun::star::drawing::XDrawPage > const mxDrawPage;
            ::com::sun::star::uno::Reference<
                ::com::sun::star::animations::XAnimationNode > const mxRootNode;

            /// Contains common objects needed throughout the slideshow
            SlideShowContext                                    maContext;

            ::boost::shared_ptr<ShapeEventBroadcaster> mpEventBroadcaster;

            /// Handles the animation and event generation for us
            SlideAnimations                                     maAnimations;

            /// All added views
            UnoViewVector                                       maViews;

            ::boost::optional<RGBColor>                         maUserPaintColor;
            UserPaintOverlaySharedPtr                           mpPaintOverlay;

            /// Bitmap with initial slide content
            VectorOfSlideBitmaps                                maSlideBitmaps;

            /// Timeout for automatic next slide display
            double                                              mnNextSlideTimeout;

            SlideAnimationState                                 meAnimationState;

            /// True, when intrinsic shape animations are allowed
            bool                                                mbImageAnimationsAllowed;

            /// True, if initial load of all page shapes succeeded
            bool                                                mbShapesLoaded;

            /// True, if initial load of all animation info succeeded
            bool                                                mbShowLoaded;

            /** True, if this slide is not static.

                If this slide has animated content, this variable wiil
                be true, and false otherwise.
             */
            bool                                                mbHaveAnimations;

            /** True, if this slide has a main animation sequence.

                If this slide has animation content, which in turn has
                a main animation sequence (which must be fully run
                before EventMultiplexer::notifySlideAnimationsEnd() is
                called), this member is true.
             */
            bool                                                mbMainSequenceFound;

            /** When true, next slide should display without further
                user interaction.
             */
            bool                                                mbHasAutomaticNextSlide;

            struct ShapesIterationFunc;  friend struct ShapesIterationFunc;
        };

        typedef ::boost::shared_ptr< ::presentation::internal::Slide > SlideSharedPtr;

    }
}

#endif /* _SLIDESHOW_SLIDE_HXX */
<commit_msg>INTEGRATION: CWS presfixes09 (1.7.16); FILE MERGED 2006/04/03 16:19:04 thb 1.7.16.5: #i37778# Now passing down ComponentContext to all interested parties; building a second, all-exports version of the slideshow component (to facilitate unit testing also for internal classes) - this made necessary renaming ImportFailedException to ShapeLoadFailedException (because of silly i63703); applied relevant parts of #i63770# (const-correctness); reworked view handling in such a way that views are now kept in one central repository (and are not duplicated across all interested objects); moved code from namespace presentation to namespace slideshow 2006/03/24 18:23:37 thb 1.7.16.4: #i37778# Moved whole slideshow engine from namespace presentation (which conflicts with one of the UNO subnamespaces) to slideshow 2006/03/23 17:22:45 thb 1.7.16.3: #i49357# Changed manual noncopyable boiler plate to boost::noncopyable 2006/03/15 15:22:24 thb 1.7.16.2: #i49357# Removed external include guards from all non-export headers (and from the cxx files, anyway) 2006/03/06 22:14:36 thb 1.7.16.1: #i53194# #i55294# #i59324# Overhauled IntrinsicAnimationActivity; fixes GIF animation import; corrected rehearse timings sprite size; several cosmetic changes (removed external header guards); prepared scene for sprite prio<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: slide.hxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: kz $ $Date: 2006-12-13 16:02:36 $
 *
 *  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 _SLIDESHOW_SLIDE_HXX
#define _SLIDESHOW_SLIDE_HXX

#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/drawing/XDrawPage.hpp>

#include <cppcanvas/spritecanvas.hxx>

#include <basegfx/vector/b2isize.hxx>

#include "unoview.hxx"
#include "event.hxx"
#include "layermanager.hxx"
#include "userpaintoverlay.hxx"
#include "slideanimations.hxx"
#include "slidebitmap.hxx"
#include "shapeeventbroadcaster.hxx"

#include <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
#include <boost/optional.hpp>

#include <vector>
#include <utility>

/* Definition of Slide class */

namespace slideshow
{
    namespace internal
    {
        class EventQueue;
        class ActivitiesQueue;
        class UserEventQueue;

        typedef ::boost::shared_ptr< class Slide > SlideSharedPtr;

        class Slide : private boost::noncopyable,
                      public ViewEventHandler
        {
        public:
            /** Construct from XDrawPage

                Prefetches shapes from draw page, thus might take some
                time. The Slide object generally works in XDrawPage
                model coordinates, that is, the page will have the
                width and height as specified in the XDrawPage's
                property set. The top, left corner of the page will be
                rendered at (0,0) in the given canvas' view coordinate
                system.
             */
            static SlideSharedPtr create( const ::com::sun::star::uno::Reference<
                                                ::com::sun::star::drawing::XDrawPage >&         xDrawPage,
                                          const ::com::sun::star::uno::Reference<
                                                ::com::sun::star::animations::XAnimationNode >& xRootNode,
                                          EventQueue&                                           rEventQueue,
                                          ActivitiesQueue&                                      rActivitiesQueue,
                                          EventMultiplexer&                                     rEventMultiplexer,
                                          UserEventQueue&                                       rUserEventQueue,
                                          const ::com::sun::star::uno::Reference<
                                                ::com::sun::star::uno::XComponentContext >&     xContext,
                                          const UnoViewContainer&                               rViewContainer );
            ~Slide();

            // ViewEventHandler
            virtual void viewAdded( const UnoViewSharedPtr& rView );
            virtual void viewRemoved( const UnoViewSharedPtr& rView );
            virtual void viewChanged( const UnoViewSharedPtr& rView );

            /** Add the given listener for the given shape.

                This method implements the addShapeEventListener
                method of the XSlideShow interface. The given listener
                is called, whenever a user clicks on the shape. If the
                shape is not contained in this slide, this method does
                nothing.
             */
            void addShapeEventListener( const ::com::sun::star::uno::Reference<
                                                ::com::sun::star::presentation::XShapeEventListener >&  xListener,
                                        const ::com::sun::star::uno::Reference<
                                                ::com::sun::star::drawing::XShape >&                    xShape );

            /** Revoke the given listener for the given shape.

                This method implements the removeShapeEventListener
                method of the XSlideShow interface.
             */
            void removeShapeEventListener( const ::com::sun::star::uno::Reference<
                                                       ::com::sun::star::presentation::XShapeEventListener >&   xListener,
                                           const ::com::sun::star::uno::Reference<
                                                       ::com::sun::star::drawing::XShape >&                     xShape );

            /** Control intrinsic animation behaviour

                @param bImageAnimationsAllowed
                When true, GIF and drawing layer animations will be
                shown. When false, those shapes have no intrinsic
                animation.
             */
            void setImageAnimationsAllowed( bool bImageAnimationsAllowed );

            /** Set the mouse cursor for a given shape.

                This method implements the setShapeCursor method of
                the XSlideShow interface. Whenever the mouse hovers
                over the given shape, the specified mouse cursor will
                be shown. To reset the mouse cursor to the default,
                specify awt::SystemPointer::ARROW.
             */
            void setShapeCursor( const ::com::sun::star::uno::Reference<
                                         ::com::sun::star::drawing::XShape >&   xShape,
                                 sal_Int16                                      nPointerShape );

            /** Prepares to show slide.

                Call this method to reduce the timeout show(), and
                getInitialSlideBitmap() need to complete. If
                prefetchShow() is not called explicitely, the named
                methods will call it implicitely.
             */
            bool prefetchShow();

            /** Paint the slide on given view, without any animation effects
             */
            bool paint( const UnoViewSharedPtr& rView );

            /** Shows the slide on all registered views
             */
            bool show();

            /** Force-end the slide show.
             */
            void end();

            /** Query whether this slide is currently showing.

                @return true, if this slide is currently showing
                (i.e. show() was called more often than end()).
             */
            bool isShowing() const;

            /** Query whether the slide has animations at all

                If the slide doesn't have animations, show() is
                equivalent to paint(). If an event is registered with
                registerSlideEndEvent(), this event will be
                immediately activated at the end of the show() method.

                @return true, if this slide has animations, false
                otherwise
             */
            bool isAnimated();

            /** Request bitmap for current slide appearance.

                The bitmap returned by this method is dependent on the
                current state of the slide and the contained
                animations. A newly generated slide will return the
                initial slide content here (e.g. with all 'appear'
                effect shapes invisible), a slide whose effects are
                currently running will return a bitmap corresponding
                to the current position on the animation timeline, and
                a slide whose effects have all been run will generate
                a bitmap with the final slide appearance (e.g. with
                all 'hide' effect shapes invisible).

                @param rView
                View to retrieve bitmap for (note that the bitmap will
                have device-pixel equivalence to the content that
                would have been rendered onto the given view). Note
                that the view must have been added to this slide
                before via viewAdded().
             */
            // TODO(F2): Rework SlideBitmap to no longer be based on XBitmap,
            // but on canvas-independent basegfx bitmaps
            SlideBitmapSharedPtr getCurrentSlideBitmap( const UnoViewSharedPtr& rView );

            /** Query the slide, whether next slide should appear
                automatically.

                @return true, if next slide should be displayed
                automatically. When false is returned, the user is
                required to click to have the next slide shown.
             */
            bool hasAutomaticNextSlide() const;

            /** Query the slide for the timeout, until the next slide
                is automatically shown.

                This value is undefined, should
                hasAutomaticNextSlide() return false.

                @return a timeout in seconds, for which to delay the
                display of the next slide.
             */
            double getAutomaticNextSlideTimeout() const;

            /** Control the user paint mode.

                The user paint mode lets the user paint on this slide
                with the given color, when pressing down the
                mousebutton.
             */
            void setUserPaintColor( boost::optional<RGBColor> const& rColor );

            /// Query the XDrawPage's size
            basegfx::B2ISize getSlideSize() const;

            /// Get size of the slide in device coordinates for given view
            ::basegfx::B2ISize getSlideSizePixel(
                UnoViewSharedPtr const & pView ) const;

            /// Gets the underlying API page
            ::com::sun::star::uno::Reference<
                ::com::sun::star::drawing::XDrawPage > const&
            getXDrawPage() const { return mxDrawPage; }

            /// Gets the animation node.
            ::com::sun::star::uno::Reference<
                ::com::sun::star::animations::XAnimationNode > const&
            getXAnimationNode() const { return mxRootNode; }

        private:
            Slide( const ::com::sun::star::uno::Reference<
                       ::com::sun::star::drawing::XDrawPage >&          xDrawPage,
                   const ::com::sun::star::uno::Reference<
                       ::com::sun::star::animations::XAnimationNode >&  xRootNode,
                   EventQueue&                                          rEventQueue,
                   ActivitiesQueue&                                     rActivitiesQueue,
                   EventMultiplexer&                                    rEventMultiplexer,
                   UserEventQueue&                                      rUserEventQueue,
                   const ::com::sun::star::uno::Reference<
                         ::com::sun::star::uno::XComponentContext >&    xContext,
                   const UnoViewContainer&                              rViewContainer );

            void enablePaintOverlay();
            void disablePaintOverlay();

            /// Set all Shapes to their initial attributes for slideshow
            bool applyInitialShapeAttributes( const ::com::sun::star::uno::Reference<
                                                  ::com::sun::star::animations::XAnimationNode >& xRootAnimationNode );

            /// Renders current slide content to bitmap
            SlideBitmapSharedPtr createCurrentSlideBitmap(
                const UnoViewSharedPtr& rView,
                ::basegfx::B2ISize const & rSlideSize );

            /// Prefetch all shapes (not the animations)
            bool prefetchShapes();

            /// Prefetch show, but don't call applyInitialShapeAttributes()
            bool implPrefetchShow();

            /// Query the rectangle covered by the slide
            ::basegfx::B2DRectangle getSlideRect() const;

            /// Start GIF and other intrinsic shape animations
            void endIntrinsicAnimations();

            /// End GIF and other intrinsic shape animations
            void startIntrinsicAnimations();

            // Types
            // =====

            enum SlideAnimationState
            {
                CONSTRUCTING_STATE=0,
                INITIAL_STATE=1,
                SHOWING_STATE=2,
                FINAL_STATE=3,
                SlideAnimationState_NUM_ENTRIES=4
            };

            typedef std::vector< SlideBitmapSharedPtr > VectorOfSlideBitmaps;
            /** Vector of slide bitmaps.

                Since the bitmap content is sensitive to animation
                effects, we have an inner vector containing a distinct
                bitmap for each of the SlideAnimationStates.
             */
            typedef ::std::vector< std::pair< UnoViewSharedPtr,
                                              VectorOfSlideBitmaps > > VectorOfVectorOfSlideBitmaps;

            // Member variables
            // ================

            /// The page model object
            const com::sun::star::uno::Reference<
                com::sun::star::drawing::XDrawPage >            mxDrawPage;
            const com::sun::star::uno::Reference<
                com::sun::star::animations::XAnimationNode >    mxRootNode;

            /// Contains common objects needed throughout the slideshow
            SlideShowContext                                    maContext;

            ::boost::shared_ptr<ShapeEventBroadcaster>          mpEventBroadcaster;

            /// Handles the animation and event generation for us
            SlideAnimations                                     maAnimations;

            ::boost::optional<RGBColor>                         maUserPaintColor;
            UserPaintOverlaySharedPtr                           mpPaintOverlay;

            /// Bitmaps with slide content at various states
            VectorOfVectorOfSlideBitmaps                        maSlideBitmaps;

            /// Timeout for automatic next slide display
            double                                              mnNextSlideTimeout;

            SlideAnimationState                                 meAnimationState;

            /// True, when intrinsic shape animations are allowed
            bool                                                mbImageAnimationsAllowed;

            /// True, if initial load of all page shapes succeeded
            bool                                                mbShapesLoaded;

            /// True, if initial load of all animation info succeeded
            bool                                                mbShowLoaded;

            /** True, if this slide is not static.

                If this slide has animated content, this variable wiil
                be true, and false otherwise.
             */
            bool                                                mbHaveAnimations;

            /** True, if this slide has a main animation sequence.

                If this slide has animation content, which in turn has
                a main animation sequence (which must be fully run
                before EventMultiplexer::notifySlideAnimationsEnd() is
                called), this member is true.
             */
            bool                                                mbMainSequenceFound;

            /** When true, next slide should display without further
                user interaction.
             */
            bool                                                mbHasAutomaticNextSlide;

            struct ShapesIterationFunc;  friend struct ShapesIterationFunc;
        };
    }
}

#endif /* _SLIDESHOW_SLIDE_HXX */
<|endoftext|>


<commit_before>#include "stdafx.h"
#include "BrowserManager.h"
#include <windows.h>
#include <objbase.h>

int APIENTRY _tWinMain(HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPTSTR    lpCmdLine,
	int       nCmdShow)
{
	int result = 0;
	HRESULT Hr = ::CoInitialize(NULL);
	if(FAILED(Hr)) return 0;

	DuiLib::CPaintManagerUI::SetInstance(hInstance);
	DuiLib::CPaintManagerUI::SetResourceType(DuiLib::UILIB_ZIPRESOURCE);
	DuiLib::CPaintManagerUI::SetResourcePath(DuiLib::CPaintManagerUI::GetInstancePath());
	DuiLib::CPaintManagerUI::SetResourceZip(MAKEINTRESOURCE(IDR_ZIPRES), _T("ZIPRES"));

	CefMainArgs main_args(hInstance);
	CefRefPtr<CefApp> app;
	CefSettings settings;// Specify CEF global settings here.
	void* sandbox_info = NULL;
#ifdef CEF_USE_SANDBOX
  CefScopedSandboxInfo scoped_sandbox;
  sandbox_info = scoped_sandbox.sandbox_info();
#else
	settings.no_sandbox = true;
#endif
	//CefRefPtr<Browser::ClientAppBrowser> app(new Browser::ClientAppBrowser);
	CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
    app = new Browser::ClientAppBrowser();
	command_line->InitFromString(::GetCommandLineW());
	const std::string& process_type = command_line->GetSwitchValue("type");

	// Execute the secondary process, if any.
	int exit_code = CefExecuteProcess(main_args, app, sandbox_info);
	if (exit_code >= 0)
		return exit_code;

	WCHAR szBuffer[MAX_PATH];
	::ZeroMemory(&szBuffer, sizeof(szBuffer));
	GetTempPathW(MAX_PATH,szBuffer);
	std::wstring sBuffer = szBuffer;
	sBuffer += L"Browser";
	CefString(&settings.cache_path).FromWString(sBuffer);

	settings.ignore_certificate_errors = true;

	//settings.command_line_args_disabled = true;

	CefString(&settings.locale).FromASCII("zh-CN");

	// Initialize CEF.
	CefInitialize(main_args, settings, app, sandbox_info);

	scoped_ptr<Browser::BrowserManager> pBrowserManager(new Browser::BrowserManager(true));
	scoped_ptr<Browser::MessageLoop> message_loop;
	message_loop.reset(new Browser::MessageLoop);

	pBrowserManager->CreateRootWindow(true,false,CefRect(),_T("https://www.hao123.com/"));

	//DuiLib::CPaintManagerUI::MessageLoop();
	result = message_loop->Run();

	DuiLib::CPaintManagerUI::Term();

	// Shut down CEF.
	CefShutdown();

	message_loop.reset();

	::CoUninitialize();
	return result;
}
<commit_msg>Release版不输出日志<commit_after>#include "stdafx.h"
#include "BrowserManager.h"
#include <windows.h>
#include <objbase.h>

int APIENTRY _tWinMain(HINSTANCE hInstance,
	HINSTANCE hPrevInstance,
	LPTSTR    lpCmdLine,
	int       nCmdShow)
{
	int result = 0;
	HRESULT Hr = ::CoInitialize(NULL);
	if(FAILED(Hr)) return 0;

	DuiLib::CPaintManagerUI::SetInstance(hInstance);
	DuiLib::CPaintManagerUI::SetResourceType(DuiLib::UILIB_ZIPRESOURCE);
	DuiLib::CPaintManagerUI::SetResourcePath(DuiLib::CPaintManagerUI::GetInstancePath());
	DuiLib::CPaintManagerUI::SetResourceZip(MAKEINTRESOURCE(IDR_ZIPRES), _T("ZIPRES"));

	CefMainArgs main_args(hInstance);
	CefRefPtr<CefApp> app;
	CefSettings settings;// Specify CEF global settings here.
	void* sandbox_info = NULL;
#ifdef CEF_USE_SANDBOX
  CefScopedSandboxInfo scoped_sandbox;
  sandbox_info = scoped_sandbox.sandbox_info();
#else
	settings.no_sandbox = true;
#endif
	//CefRefPtr<Browser::ClientAppBrowser> app(new Browser::ClientAppBrowser);
	CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
    app = new Browser::ClientAppBrowser();
	command_line->InitFromString(::GetCommandLineW());
	const std::string& process_type = command_line->GetSwitchValue("type");

	// Execute the secondary process, if any.
	int exit_code = CefExecuteProcess(main_args, app, sandbox_info);
	if (exit_code >= 0)
		return exit_code;

	WCHAR szBuffer[MAX_PATH];
	::ZeroMemory(&szBuffer, sizeof(szBuffer));
	GetTempPathW(MAX_PATH,szBuffer);
	std::wstring sBuffer = szBuffer;
	sBuffer += L"Browser";
	CefString(&settings.cache_path).FromWString(sBuffer);

	settings.ignore_certificate_errors = true;

	//settings.command_line_args_disabled = true;

	CefString(&settings.locale).FromASCII("zh-CN");

#ifndef _DEBUG
	settings.log_severity = LOGSEVERITY_DISABLE;
#endif

	// Initialize CEF.
	CefInitialize(main_args, settings, app, sandbox_info);

	scoped_ptr<Browser::BrowserManager> pBrowserManager(new Browser::BrowserManager(true));
	scoped_ptr<Browser::MessageLoop> message_loop;
	message_loop.reset(new Browser::MessageLoop);

	pBrowserManager->CreateRootWindow(true,false,CefRect(),_T("https://www.hao123.com/"));

	//DuiLib::CPaintManagerUI::MessageLoop();
	result = message_loop->Run();

	DuiLib::CPaintManagerUI::Term();

	// Shut down CEF.
	CefShutdown();

	message_loop.reset();

	::CoUninitialize();
	return result;
}
<|endoftext|>


<commit_before>#include "ScriptLoader.h"

#include <Server_Common/Logging/Logger.h>
#include <Server_Common/Config/XMLConfig.h>
#include "ServerZone.h"

#include <boost/format.hpp>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string/predicate.hpp>

extern Core::Logger g_log;
extern Core::ServerZone g_serverZone;

namespace fs = boost::filesystem;

Core::Scripting::ScriptLoader::ScriptLoader()
{}

const std::string Core::Scripting::ScriptLoader::getModuleExtension()
{
#ifdef _WIN32
   return ".dll";
#elif __APPLE__
   return ".dylib";
#else
   return ".so";
#endif
}

bool Core::Scripting::ScriptLoader::unloadModule( ModuleHandle handle )
{
#ifdef _WIN32
   bool success = FreeLibrary( handle ) != 0;
#else
   bool success = dlclose( handle ) == 0;
#endif

   if( !success )
   {
      g_log.error( "Failed to unload module @ 0x" + boost::str( boost::format( "%|08X|" ) % handle ) );

      return false;
   }

   g_log.debug( "Unloaded module @ 0x" + boost::str( boost::format( "%|08X|" ) % handle ) );

   return true;
}

Core::Scripting::ScriptInfo* Core::Scripting::ScriptLoader::loadModule( const std::string& path )
{
   boost::filesystem::path f( path );

   if ( isModuleLoaded( f.stem().string() ) )
   {
      g_log.error( "Unable to load module '" + f.stem().string() + "' as it is already loaded" );
      return nullptr;
   }

   // copy to temp dir
   fs::path cacheDir( f.parent_path() /= g_serverZone.getConfig()->getValue< std::string >( "Settings.General.Scripts.CachePath", "./cache/" ) );
   fs::create_directories( cacheDir );
   fs::path dest( cacheDir /= f.filename().string() );

   if ( fs::exists( dest ) )
   {
      fs::remove( dest );
   }

   fs::copy_file( f, dest );

#ifdef _WIN32
   ModuleHandle handle = LoadLibrary( dest.string().c_str() );
#else
   ModuleHandle handle = dlopen( dest.string().c_str(), RTLD_LAZY );
#endif

   if( !handle )
   {
      g_log.error( "Failed to load module from: " + path );

      return nullptr;
   }

   g_log.info( "Loaded module '" + f.filename().string() + "' @ 0x" + boost::str( boost::format( "%|08X|" ) % handle ) );

   auto info = new ScriptInfo;
   info->handle = handle;
   info->library_name = f.stem().string();
   info->cache_path = dest.string();
   info->library_path = f.string();

   m_scriptMap.insert( std::make_pair( f.stem().string(), info ) );

   return info;
}

ScriptObject* Core::Scripting::ScriptLoader::getScriptObject( ModuleHandle handle )
{
   using getScript = ScriptObject*(*)();

#ifdef _WIN32
   getScript func = reinterpret_cast< getScript >( GetProcAddress( handle, "getScript" ) );
#else
   getScript func = reinterpret_cast< getScript >( dlsym( handle, "getScript" ) );
#endif

   if( func )
   {
      auto ptr = func();

      g_log.debug( "got ScriptObject @ 0x" + boost::str( boost::format( "%|08X|" ) % ptr ) );
      g_log.debug( "script info -> name: " + std::string( ptr->getName() ) + ", id: " + std::to_string( ptr->getId() ) );

      return ptr;
   }
   else
      return nullptr;
}

bool Core::Scripting::ScriptLoader::unloadScript( Core::Scripting::ScriptInfo* info )
{
   return unloadScript( info->handle );
}

bool Core::Scripting::ScriptLoader::unloadScript( ModuleHandle handle )
{
   for( auto it = m_scriptMap.begin(); it != m_scriptMap.end(); ++it )
   {
      if( it->second->handle == handle )
      {
         auto info = it->second;
         m_scriptMap.erase( it );

         if( unloadModule( handle ) )
         {
            // remove cached file
            fs::remove( info->cache_path );

            delete info;

            return true;
         }

         g_log.error( "failed to unload module: " + info->library_name );

         return false;
      }
   }

   return false;
}

bool Core::Scripting::ScriptLoader::isModuleLoaded( std::string name )
{
   for( auto it = m_scriptMap.begin(); it != m_scriptMap.end(); ++it )
   {
      if( boost::iequals( it->second->library_name, name ) )
         return true;
   }

   return false;
}

Core::Scripting::ScriptInfo* Core::Scripting::ScriptLoader::getScriptInfo( std::string name )
{
   for( auto it = m_scriptMap.begin(); it != m_scriptMap.end(); ++it )
   {
      if( it->second->script_name == name )
      {
         return it->second;
      }
   }

   return nullptr;
}

void Core::Scripting::ScriptLoader::findScripts( std::set< Core::Scripting::ScriptInfo* >& scripts, const std::string& search )
{
   for( auto it = m_scriptMap.begin(); it != m_scriptMap.end(); ++it )
   {
      if( it->second->script_name.find( search ) != std::string::npos )
      {
         scripts.insert( it->second );
      }
   }
}<commit_msg>maybe, just maybe, it builds on travis now<commit_after>#include "ScriptLoader.h"

#include <Server_Common/Logging/Logger.h>
#include <Server_Common/Config/XMLConfig.h>
#include "ServerZone.h"

#include <boost/format.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <experimental/filesystem>

extern Core::Logger g_log;
extern Core::ServerZone g_serverZone;

namespace fs = std::experimental::filesystem;

Core::Scripting::ScriptLoader::ScriptLoader()
{}

const std::string Core::Scripting::ScriptLoader::getModuleExtension()
{
#ifdef _WIN32
   return ".dll";
#elif __APPLE__
   return ".dylib";
#else
   return ".so";
#endif
}

bool Core::Scripting::ScriptLoader::unloadModule( ModuleHandle handle )
{
#ifdef _WIN32
   bool success = FreeLibrary( handle ) != 0;
#else
   bool success = dlclose( handle ) == 0;
#endif

   if( !success )
   {
      g_log.error( "Failed to unload module @ 0x" + boost::str( boost::format( "%|08X|" ) % handle ) );

      return false;
   }

   g_log.debug( "Unloaded module @ 0x" + boost::str( boost::format( "%|08X|" ) % handle ) );

   return true;
}

Core::Scripting::ScriptInfo* Core::Scripting::ScriptLoader::loadModule( const std::string& path )
{
   fs::path f( path );

   if ( isModuleLoaded( f.stem().string() ) )
   {
      g_log.error( "Unable to load module '" + f.stem().string() + "' as it is already loaded" );
      return nullptr;
   }

   // copy to temp dir
   fs::path cacheDir( f.parent_path() /= g_serverZone.getConfig()->getValue< std::string >( "Settings.General.Scripts.CachePath", "./cache/" ) );
   fs::create_directories( cacheDir );
   fs::path dest( cacheDir /= f.filename().string() );

   if ( fs::exists( dest ) )
   {
      fs::remove( dest );
   }

   fs::copy_file( f, dest );

#ifdef _WIN32
   ModuleHandle handle = LoadLibrary( dest.string().c_str() );
#else
   ModuleHandle handle = dlopen( dest.string().c_str(), RTLD_LAZY );
#endif

   if( !handle )
   {
      g_log.error( "Failed to load module from: " + path );

      return nullptr;
   }

   g_log.info( "Loaded module '" + f.filename().string() + "' @ 0x" + boost::str( boost::format( "%|08X|" ) % handle ) );

   auto info = new ScriptInfo;
   info->handle = handle;
   info->library_name = f.stem().string();
   info->cache_path = dest.string();
   info->library_path = f.string();

   m_scriptMap.insert( std::make_pair( f.stem().string(), info ) );

   return info;
}

ScriptObject* Core::Scripting::ScriptLoader::getScriptObject( ModuleHandle handle )
{
   using getScript = ScriptObject*(*)();

#ifdef _WIN32
   getScript func = reinterpret_cast< getScript >( GetProcAddress( handle, "getScript" ) );
#else
   getScript func = reinterpret_cast< getScript >( dlsym( handle, "getScript" ) );
#endif

   if( func )
   {
      auto ptr = func();

      g_log.debug( "got ScriptObject @ 0x" + boost::str( boost::format( "%|08X|" ) % ptr ) );
      g_log.debug( "script info -> name: " + std::string( ptr->getName() ) + ", id: " + std::to_string( ptr->getId() ) );

      return ptr;
   }
   else
      return nullptr;
}

bool Core::Scripting::ScriptLoader::unloadScript( Core::Scripting::ScriptInfo* info )
{
   return unloadScript( info->handle );
}

bool Core::Scripting::ScriptLoader::unloadScript( ModuleHandle handle )
{
   for( auto it = m_scriptMap.begin(); it != m_scriptMap.end(); ++it )
   {
      if( it->second->handle == handle )
      {
         auto info = it->second;
         m_scriptMap.erase( it );

         if( unloadModule( handle ) )
         {
            // remove cached file
            fs::remove( info->cache_path );

            delete info;

            return true;
         }

         g_log.error( "failed to unload module: " + info->library_name );

         return false;
      }
   }

   return false;
}

bool Core::Scripting::ScriptLoader::isModuleLoaded( std::string name )
{
   for( auto it = m_scriptMap.begin(); it != m_scriptMap.end(); ++it )
   {
      if( boost::iequals( it->second->library_name, name ) )
         return true;
   }

   return false;
}

Core::Scripting::ScriptInfo* Core::Scripting::ScriptLoader::getScriptInfo( std::string name )
{
   for( auto it = m_scriptMap.begin(); it != m_scriptMap.end(); ++it )
   {
      if( it->second->script_name == name )
      {
         return it->second;
      }
   }

   return nullptr;
}

void Core::Scripting::ScriptLoader::findScripts( std::set< Core::Scripting::ScriptInfo* >& scripts, const std::string& search )
{
   for( auto it = m_scriptMap.begin(); it != m_scriptMap.end(); ++it )
   {
      if( it->second->script_name.find( search ) != std::string::npos )
      {
         scripts.insert( it->second );
      }
   }
}<|endoftext|>


<commit_before>/***************************************************************************
                          kopete.cpp  -  description
                             -------------------
    begin                : Wed Dec 26 03:12:10 CLST 2001
    copyright            : (C) 2001 by Duncan Mac-Vicar Prett
    email                : duncan@puc.cl
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include <qvaluelist.h>
#include <qlist.h>
#include <qlayout.h>

#include <kconfig.h>
#include <kdebug.h>
#include <kcrash.h>
#include <kglobal.h>
#include <kiconloader.h>

#include <kopete.h>
#include <preferencesdialog.h>
#include <kopetewindow.h>
#include "plugin.h"
#include "pluginloader.h"
#include "pluginmodule.h"
#include <addwizardimpl.h>
#include "systemtray.h"

class Plugins;

Kopete::Kopete(): KUniqueApplication(true, true, true)
{
	//plugins = new PluginManager;
	allConnected = false;

	mLibraryLoader = new LibraryLoader;
	mIconLoader = KGlobal::iconLoader();
	mPref=new PreferencesDialog;
	Plugins *blah = new Plugins(this);

	mainwindow = new KopeteWindow;
	setMainWidget(mainwindow);
	mainwindow->statusBar()->show();

  	mPref->hide();

	KConfig *config=KGlobal::config();
	config->setGroup("");
	/* Ups! the user dont have plugins selected. */
	if (!config->hasKey("Modules"))
	{
		QStringList modules;
		modules.append("icq.plugin");
		modules.append("msn.plugin");
		config->writeEntry("Modules", modules);
	}
	/* Ok, load saved plugins */
	loadPlugins();
	tray = new KopeteSystemTray();

}

Kopete::~Kopete()
{
	delete mPref;
	delete mLibraryLoader;
	delete mainwindow;

	// Only use this if cant find crash cause :-)
	//KCrash::setCrashHandler(Kopete::cleverKCrashHack);
}
void Kopete::slotPreferences()
{
  mPref->show();
  mPref->raise();
}
/** No descriptions */
void Kopete::slotExit()
{
	quit();
}

KopeteSystemTray *Kopete::systemTray()
{
	return tray;
}

/** No descriptions */
void Kopete::readOptions()
{
	/*
  KConfig *config = KGlobal::config();
  config->setGroup("General");
	visible = config->readBoolEntry("Visible",true);
	QSize size          = config->readSizeEntry("Geometry");
  config->readBoolEntry("Idle Detection",false);
  config->readNumEntry("MaxIdle",15);

  if(!size.isEmpty())
  {
    resize(size);
  }
  QPoint pos=config->readPointEntry("Position");
  if(!pos.isNull())
  {
    move(pos);
  }
  config->setGroup("ICQ");
  QString icqNick = config->readEntry( "icqNick" );
  QString icqUIN = config->readEntry( "icqUIN" );
	QString icqPass = config->readEntry( "icqPass" );
	config->setGroup("MSN");
  QString msnNick = config->readEntry( "msnNick" );
  QString msnID = config->readEntry( "msnID" );
	QString msnPass = config->readEntry( "msnPass" );

	autoConnect=-1;
  if ( profiles.count() == 0 )
    slotSettings();
  else
  {
    //Construct menu...
    for ( int i = 0 ; i < profiles.count() ; i++ )
    {
      KAction *tmpaction = new KMsnAction( profiles[i] , //Name
                                        0           , //Accel
                                        this        , //Receiver
                                        SLOT(slotConnector( int ) ),
                                        actionCollection(),//Parent (not sure...)
                                        profiles[i] , //Internal name
                                        i );          //ID, needed for connecting
      //Add actions to the submenu
      fileConnector->insert( tmpaction );
      //And add them to our list...
      actions.append( tmpaction );
      //.. and make sure that they're deleted when we delete them
      actions.setAutoDelete( true );

      if (autoStr == profiles[i])
	autoConnect=i;
    }
  }

*/
}
/** No descriptions */
void Kopete::saveOptions(){
}

/** Connect to all loaded protocol plugins */
void Kopete::slotConnectAll()
{
	QValueList<KopeteLibraryInfo> l = kopeteapp->libraryLoader()->loaded();
    for (QValueList<KopeteLibraryInfo>::Iterator i = l.begin(); i != l.end(); ++i)
	{
		kdDebug() << "Kopete: [Connect All]: "<<(*i).name <<"\n";
		Plugin *tmpprot = (kopeteapp->libraryLoader())->mLibHash[(*i).specfile]->plugin;
		IMProtocol *prot =  static_cast<IMProtocol*>(tmpprot);
		if ( !(prot->isConnected()))
		{
			prot->Connect();
		}
	}
	allConnected = true;
	mainWindow()->actionConnect->setEnabled(false);
    mainWindow()->actionDisconnect->setEnabled(true);
}

/** Connect to all loaded protocol plugins */
void Kopete::slotDisconnectAll()
{
	QValueList<KopeteLibraryInfo> l = kopeteapp->libraryLoader()->loaded();
    for (QValueList<KopeteLibraryInfo>::Iterator i = l.begin(); i != l.end(); ++i)
	{
		kdDebug() << "Kopete: [Disconnect All]: "<<(*i).name <<"\n";
		Plugin *tmpprot = (kopeteapp->libraryLoader())->mLibHash[(*i).specfile]->plugin;
		IMProtocol *prot =  static_cast<IMProtocol*>(tmpprot);
		if (prot->isConnected())
		{
			prot->Disconnect();
		}
	}
	allConnected = false;
	mainWindow()->actionConnect->setEnabled(true);
    mainWindow()->actionDisconnect->setEnabled(false);
}

/** No descriptions */
void Kopete::slotAboutPlugins()
{
	AboutPlugins *aboutPl;
	aboutPl = new AboutPlugins(mainwindow);
	aboutPl->show();

}
/** Add a contact through Wizard */
void Kopete::slotAddContact()
{
	AddWizardImpl *tmpdialog = new AddWizardImpl(this->mainWindow());
	tmpdialog->show();
}

/** No descriptions */
void Kopete::slotSetAway()
{
}/** No descriptions */
void Kopete::initPlugins()
{

}
/** No descriptions */
void Kopete::loadPlugins()
{
	mLibraryLoader->loadAll();
}

void Kopete::cleverKCrashHack(int)
{
	// do nothing

	// Understand that the KDE libraries have a memory leak, and
	// the playlist cannot be unloaded without causing a crash
	// in QApplication::windowMapper() or something similar.
	// this is just to prevent the KCrash window from appearing
	// and bugging the user regularly

	// someone fix the libraries.
	kdDebug() << "Crashed.\n" << endl;
	_exit(255);
}
/** No descriptions */
KStatusBar *Kopete::statusBar()
{
	return mainwindow->statusBar();
}
/** No descriptions */
ContactList *Kopete::contactList()
{
	return mainwindow->contactlist;

}
<commit_msg>- Systray should be created before plugins get loaded   if not, plugins are not able to add menus to it<commit_after>/***************************************************************************
                          kopete.cpp  -  description
                             -------------------
    begin                : Wed Dec 26 03:12:10 CLST 2001
    copyright            : (C) 2001 by Duncan Mac-Vicar Prett
    email                : duncan@puc.cl
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#include <qvaluelist.h>
#include <qlist.h>
#include <qlayout.h>

#include <kconfig.h>
#include <kdebug.h>
#include <kcrash.h>
#include <kglobal.h>
#include <kiconloader.h>

#include <kopete.h>
#include <preferencesdialog.h>
#include <kopetewindow.h>
#include "plugin.h"
#include "pluginloader.h"
#include "pluginmodule.h"
#include <addwizardimpl.h>
#include "systemtray.h"

class Plugins;

Kopete::Kopete(): KUniqueApplication(true, true, true)
{
	//plugins = new PluginManager;
	allConnected = false;

	mLibraryLoader = new LibraryLoader;
	mIconLoader = KGlobal::iconLoader();
	mPref=new PreferencesDialog;
	Plugins *blah = new Plugins(this);

	mainwindow = new KopeteWindow;
	setMainWidget(mainwindow);
	mainwindow->statusBar()->show();

  	mPref->hide();

	KConfig *config=KGlobal::config();
	config->setGroup("");
	/* Ups! the user dont have plugins selected. */
	if (!config->hasKey("Modules"))
	{
		QStringList modules;
		modules.append("icq.plugin");
		modules.append("msn.plugin");
		config->writeEntry("Modules", modules);
	}
	tray = new KopeteSystemTray();
	/* Ok, load saved plugins */
	loadPlugins();
}

Kopete::~Kopete()
{
	delete mPref;
	delete mLibraryLoader;
	delete mainwindow;

	// Only use this if cant find crash cause :-)
	//KCrash::setCrashHandler(Kopete::cleverKCrashHack);
}
void Kopete::slotPreferences()
{
  mPref->show();
  mPref->raise();
}
/** No descriptions */
void Kopete::slotExit()
{
	quit();
}

KopeteSystemTray *Kopete::systemTray()
{
	return tray;
}

/** No descriptions */
void Kopete::readOptions()
{
	/*
  KConfig *config = KGlobal::config();
  config->setGroup("General");
	visible = config->readBoolEntry("Visible",true);
	QSize size          = config->readSizeEntry("Geometry");
  config->readBoolEntry("Idle Detection",false);
  config->readNumEntry("MaxIdle",15);

  if(!size.isEmpty())
  {
    resize(size);
  }
  QPoint pos=config->readPointEntry("Position");
  if(!pos.isNull())
  {
    move(pos);
  }
  config->setGroup("ICQ");
  QString icqNick = config->readEntry( "icqNick" );
  QString icqUIN = config->readEntry( "icqUIN" );
	QString icqPass = config->readEntry( "icqPass" );
	config->setGroup("MSN");
  QString msnNick = config->readEntry( "msnNick" );
  QString msnID = config->readEntry( "msnID" );
	QString msnPass = config->readEntry( "msnPass" );

	autoConnect=-1;
  if ( profiles.count() == 0 )
    slotSettings();
  else
  {
    //Construct menu...
    for ( int i = 0 ; i < profiles.count() ; i++ )
    {
      KAction *tmpaction = new KMsnAction( profiles[i] , //Name
                                        0           , //Accel
                                        this        , //Receiver
                                        SLOT(slotConnector( int ) ),
                                        actionCollection(),//Parent (not sure...)
                                        profiles[i] , //Internal name
                                        i );          //ID, needed for connecting
      //Add actions to the submenu
      fileConnector->insert( tmpaction );
      //And add them to our list...
      actions.append( tmpaction );
      //.. and make sure that they're deleted when we delete them
      actions.setAutoDelete( true );

      if (autoStr == profiles[i])
	autoConnect=i;
    }
  }

*/
}
/** No descriptions */
void Kopete::saveOptions(){
}

/** Connect to all loaded protocol plugins */
void Kopete::slotConnectAll()
{
	QValueList<KopeteLibraryInfo> l = kopeteapp->libraryLoader()->loaded();
    for (QValueList<KopeteLibraryInfo>::Iterator i = l.begin(); i != l.end(); ++i)
	{
		kdDebug() << "Kopete: [Connect All]: "<<(*i).name <<"\n";
		Plugin *tmpprot = (kopeteapp->libraryLoader())->mLibHash[(*i).specfile]->plugin;
		IMProtocol *prot =  static_cast<IMProtocol*>(tmpprot);
		if ( !(prot->isConnected()))
		{
			prot->Connect();
		}
	}
	allConnected = true;
	mainWindow()->actionConnect->setEnabled(false);
    mainWindow()->actionDisconnect->setEnabled(true);
}

/** Connect to all loaded protocol plugins */
void Kopete::slotDisconnectAll()
{
	QValueList<KopeteLibraryInfo> l = kopeteapp->libraryLoader()->loaded();
    for (QValueList<KopeteLibraryInfo>::Iterator i = l.begin(); i != l.end(); ++i)
	{
		kdDebug() << "Kopete: [Disconnect All]: "<<(*i).name <<"\n";
		Plugin *tmpprot = (kopeteapp->libraryLoader())->mLibHash[(*i).specfile]->plugin;
		IMProtocol *prot =  static_cast<IMProtocol*>(tmpprot);
		if (prot->isConnected())
		{
			prot->Disconnect();
		}
	}
	allConnected = false;
	mainWindow()->actionConnect->setEnabled(true);
    mainWindow()->actionDisconnect->setEnabled(false);
}

/** No descriptions */
void Kopete::slotAboutPlugins()
{
	AboutPlugins *aboutPl;
	aboutPl = new AboutPlugins(mainwindow);
	aboutPl->show();

}
/** Add a contact through Wizard */
void Kopete::slotAddContact()
{
	AddWizardImpl *tmpdialog = new AddWizardImpl(this->mainWindow());
	tmpdialog->show();
}

/** No descriptions */
void Kopete::slotSetAway()
{
}/** No descriptions */
void Kopete::initPlugins()
{

}
/** No descriptions */
void Kopete::loadPlugins()
{
	mLibraryLoader->loadAll();
}

void Kopete::cleverKCrashHack(int)
{
	// do nothing

	// Understand that the KDE libraries have a memory leak, and
	// the playlist cannot be unloaded without causing a crash
	// in QApplication::windowMapper() or something similar.
	// this is just to prevent the KCrash window from appearing
	// and bugging the user regularly

	// someone fix the libraries.
	kdDebug() << "Crashed.\n" << endl;
	_exit(255);
}
/** No descriptions */
KStatusBar *Kopete::statusBar()
{
	return mainwindow->statusBar();
}
/** No descriptions */
ContactList *Kopete::contactList()
{
	return mainwindow->contactlist;

}
<|endoftext|>


<commit_before>// $Id: RegularData1D_test.C,v 1.6 2001/07/10 10:38:42 oliver Exp $
#include <BALL/CONCEPT/classTest.h>

///////////////////////////

#include <BALL/DATATYPE/regularData1D.h>

///////////////////////////

START_TEST(class_name, "$Id: RegularData1D_test.C,v 1.6 2001/07/10 10:38:42 oliver Exp $")

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////

using namespace BALL;
using namespace std;

RegularData1D* rd_ptr;
CHECK(TRegularData1D::TRegularData1D())
	rd_ptr = new RegularData1D;
	TEST_NOT_EQUAL(rd_ptr, 0)
RESULT

CHECK(TRegularData1D::~TRegularData1D())
  delete rd_ptr;
RESULT

CHECK(TRegularData1D::BALL_CREATE(RegularData1D<T>))

RESULT

RegularData1D rd;
CHECK(TRegularData1D::TRegularData1D(const TRegularData1D& data))
	rd.setBoundaries(1.1, 2.1);
	rd.resize(1);
	rd[0] = 1.2;
	RegularData1D rd2(rd);
	TEST_REAL_EQUAL(rd2.getLowerBound(), 1.1)
	TEST_REAL_EQUAL(rd2.getUpperBound(), 2.1)
	TEST_REAL_EQUAL(rd2[0], 1.2)
	TEST_EQUAL(rd2.getSize(), 1)
RESULT

CHECK(TRegularData1D::clear())
	rd.clear();
	TEST_REAL_EQUAL(rd.getLowerBound(), 1.1)
	TEST_REAL_EQUAL(rd.getUpperBound(), 2.1)
	TEST_EQUAL(rd.getSize(), 1)
	TEST_REAL_EQUAL(rd[0], 0.0)
RESULT

CHECK(TRegularData1D::destroy())
	rd[0] = 2.3;
	rd.destroy();
	TEST_REAL_EQUAL(rd.getLowerBound(), 0.0)
	TEST_REAL_EQUAL(rd.getUpperBound(), 0.0)
	TEST_EQUAL(rd.getSize(), 0)
RESULT

CHECK(TRegularData1D::TRegularData1D& operator = (const TRegularData1D& data))
	rd.setBoundaries(1.1, 2.1);
	rd.resize(1);
	rd[0] = 1.2;
	RegularData1D rd2 = rd;
	TEST_REAL_EQUAL(rd2.getLowerBound(), 1.1)
	TEST_REAL_EQUAL(rd2.getUpperBound(), 2.1)
	TEST_REAL_EQUAL(rd2[0], 1.2)
	TEST_EQUAL(rd2.getSize(), 1)
RESULT

CHECK(TRegularData1D::TRegularData1D& operator = (const VectorType& data))
	RegularData1D::VectorType v;
	v.push_back(1.1);
	v.push_back(1.2);
	v.push_back(1.3);
	v.push_back(1.4);
	RegularData1D rd2;
	rd2.setBoundaries(0.0, 1.0);
	rd2 = v;
	TEST_REAL_EQUAL(rd2.getLowerBound(), 0.0)
	TEST_REAL_EQUAL(rd2.getUpperBound(), 1.0)
	TEST_EQUAL(rd2.getSize(), 4)
	TEST_REAL_EQUAL(rd2[0], 1.1)
	TEST_REAL_EQUAL(rd2[1], 1.2)
	TEST_REAL_EQUAL(rd2[2], 1.3)
	TEST_REAL_EQUAL(rd2[3], 1.4)
RESULT

CHECK(TRegularData1D::bool operator == (const TRegularData1D& data) const )
	rd.destroy();
	rd.resize(4);
	rd[0] = 1.1;
	rd[1] = 1.2;
	rd[2] = 1.3;
	rd[3] = 1.4;
	RegularData1D rd2 = rd;
	TEST_EQUAL(rd == rd2, true)
	rd2[3] = 1.41;
	TEST_EQUAL(rd == rd2, false)
	rd2[3] = 1.4;
	TEST_EQUAL(rd == rd2, true)
	rd.setBoundaries(1.1, 1.4);
	TEST_EQUAL(rd == rd2, false)
	rd2.setBoundaries(1.1, 1.4);
	TEST_EQUAL(rd == rd2, true)
RESULT

CHECK(TRegularData1D::T& operator [] (Position index) const )
  TEST_REAL_EQUAL(rd[3], 1.4)
	TEST_EXCEPTION(Exception::IndexOverflow, rd[4])
RESULT

CHECK(TRegularData1D::T& operator [] (Position index))
  rd[3] = 1.5;
	TEST_REAL_EQUAL(rd[3], 1.5)
	TEST_EXCEPTION(Exception::IndexOverflow, rd[4] = 44.4)
RESULT

RegularData1D rd2;
CHECK(TRegularData1D::getSize() const )
  TEST_EQUAL(rd.getSize(), 4)
	TEST_EQUAL(rd2.getSize(), 0)
RESULT

CHECK(TRegularData1D::getLowerBound() const )
	rd.setBoundaries(1.1, 1.5);
	TEST_REAL_EQUAL(rd.getLowerBound(), 1.1)
	TEST_REAL_EQUAL(rd2.getLowerBound(), 0.0)
RESULT

CHECK(TRegularData1D::getUpperBound() const )
	TEST_REAL_EQUAL(rd.getUpperBound(), 1.5)
	TEST_REAL_EQUAL(rd2.getUpperBound(), 0.0)
RESULT

CHECK(TRegularData1D::setLowerBound())
	rd.setBoundaries(-99.9, 99.9);
	TEST_REAL_EQUAL(rd.getLowerBound(), -99.9)
	TEST_REAL_EQUAL(rd.getUpperBound(), 99.9)
	rd.setBoundaries(99.9, -99.9);
	TEST_REAL_EQUAL(rd.getLowerBound(), -99.9)
	TEST_REAL_EQUAL(rd.getUpperBound(), 99.9)
RESULT

CHECK(TRegularData1D::resize(Size new_size))
	TEST_EQUAL(rd.getSize(), 4)
	rd.resize(99);
	TEST_EQUAL(rd.getSize(), 99)
	TEST_REAL_EQUAL(rd[98], 0.0)
	rd.resize(3);
	TEST_EQUAL(rd.getSize(), 3)
	TEST_REAL_EQUAL(rd[2], 1.3)
	TEST_EXCEPTION(Exception::IndexOverflow, rd[3])
RESULT

CHECK(TRegularData1D::rescale(Size new_size))
	TRegularData1D<float>	data;
	TEST_EQUAL(data.getSize(), 0)
	data.rescale(1);
	TEST_EQUAL(data.getSize(), 1)
	TEST_EQUAL(data[0], 0.0)
	data[0] = 2.0;
	data.rescale(2);
	TEST_EQUAL(data.getSize(), 2)
	TEST_EQUAL(data[0], 2.0)
	TEST_EQUAL(data[0], 2.0)
	data[0] = 1.0;
	data.rescale(3);
	TEST_EQUAL(data.getSize(), 3)
	TEST_REAL_EQUAL(data[0], 1.0)
	TEST_REAL_EQUAL(data[1], 1.5)
	TEST_REAL_EQUAL(data[2], 2.0)
	data.rescale(4);
	TEST_EQUAL(data.getSize(), 4)
	TEST_REAL_EQUAL(data[0], 1.0)
	TEST_REAL_EQUAL(data[1], 1.3333333)
	TEST_REAL_EQUAL(data[2], 1.6666667)
	TEST_REAL_EQUAL(data[3], 2.0)
RESULT

CHECK(TRegularData1D::rescale(double lower, double upper, Size new_size))
	TRegularData1D<float>	data;
	data.resize(2);
	data.setBoundaries(0.0, 1.0);
	data[0] = 1.0;
	data[1] = 2.0;
	data.rescale(0.0, 1.0, 3);
	TEST_EQUAL(data.getSize(), 3)
	TEST_REAL_EQUAL(data[0], 1.0)
	TEST_REAL_EQUAL(data[1], 1.5)
	TEST_REAL_EQUAL(data[2], 2.0)
	data.rescale(0.0, 1.0, 4);
	TEST_EQUAL(data.getSize(), 4)
	TEST_REAL_EQUAL(data[0], 1.0)
	TEST_REAL_EQUAL(data[1], 1.3333333)
	TEST_REAL_EQUAL(data[2], 1.6666667)
	TEST_REAL_EQUAL(data[3], 2.0)
	data.rescale(0.0, 1.0, 4);
	TEST_EQUAL(data.getSize(), 4)
	TEST_REAL_EQUAL(data[0], 1.0)
	TEST_REAL_EQUAL(data[1], 1.3333333)
	TEST_REAL_EQUAL(data[2], 1.6666667)
	TEST_REAL_EQUAL(data[3], 2.0)
	data.rescale(-1.0, 2.0, 10);
	TEST_EQUAL(data.getSize(), 10)
	TEST_REAL_EQUAL(data[0], 0.0)
	TEST_REAL_EQUAL(data[1], 0.0)
	TEST_REAL_EQUAL(data[2], 0.0)
	TEST_REAL_EQUAL(data[3], 1.0)
	TEST_REAL_EQUAL(data[4], 1.3333333)
	TEST_REAL_EQUAL(data[5], 1.6666667)
	TEST_REAL_EQUAL(data[6], 2.0)
	TEST_REAL_EQUAL(data[7], 0.0)
	TEST_REAL_EQUAL(data[8], 0.0)
	TEST_REAL_EQUAL(data[9], 0.0)
	data.rescale(0.0, 1.0, 3);
	TEST_EQUAL(data.getSize(), 3)
	TEST_REAL_EQUAL(data[0], 1.0)
	TEST_REAL_EQUAL(data[1], 1.5)
	TEST_REAL_EQUAL(data[2], 2.0)
RESULT

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
END_TEST
<commit_msg>added test for detailled cstr<commit_after>// $Id: RegularData1D_test.C,v 1.7 2001/07/10 17:50:11 amoll Exp $
#include <BALL/CONCEPT/classTest.h>

///////////////////////////

#include <BALL/DATATYPE/regularData1D.h>

///////////////////////////

START_TEST(class_name, "$Id: RegularData1D_test.C,v 1.7 2001/07/10 17:50:11 amoll Exp $")

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////

using namespace BALL;
using namespace std;

RegularData1D* rd_ptr;
CHECK(TRegularData1D::TRegularData1D())
	rd_ptr = new RegularData1D;
	TEST_NOT_EQUAL(rd_ptr, 0)
RESULT

CHECK(TRegularData1D::~TRegularData1D())
  delete rd_ptr;
RESULT

CHECK(TRegularData1D::BALL_CREATE(RegularData1D<T>))

RESULT

RegularData1D rd;
CHECK(TRegularData1D::TRegularData1D(const TRegularData1D& data))
	rd.setBoundaries(1.1, 2.1);
	rd.resize(1);
	rd[0] = 1.2;
	RegularData1D rd2(rd);
	TEST_REAL_EQUAL(rd2.getLowerBound(), 1.1)
	TEST_REAL_EQUAL(rd2.getUpperBound(), 2.1)
	TEST_REAL_EQUAL(rd2[0], 1.2)
	TEST_EQUAL(rd2.getSize(), 1)
RESULT

RegularData1D::VectorType v;
v.push_back(1.1);
v.push_back(1.2);
v.push_back(1.3);
v.push_back(1.4);

CHECK(TRegularData1D(const VectorType& data, double lower, double upper))
	RegularData1D rd2(v, 1.0, 1.5);
	TEST_REAL_EQUAL(rd2.getLowerBound(), 1.0)
	TEST_REAL_EQUAL(rd2.getUpperBound(), 1.5)
	TEST_EQUAL(rd2.getSize(), 4)
	TEST_REAL_EQUAL(rd2[0], 1.1)
	TEST_REAL_EQUAL(rd2[3], 1.4)

	RegularData1D rd3(v);
	TEST_REAL_EQUAL(rd3.getLowerBound(), 0.0)
	TEST_REAL_EQUAL(rd3.getUpperBound(), 0.0)
	TEST_EQUAL(rd3.getSize(), 4)
RESULT

CHECK(TRegularData1D::clear())
	rd.clear();
	TEST_REAL_EQUAL(rd.getLowerBound(), 1.1)
	TEST_REAL_EQUAL(rd.getUpperBound(), 2.1)
	TEST_EQUAL(rd.getSize(), 1)
	TEST_REAL_EQUAL(rd[0], 0.0)
RESULT

CHECK(TRegularData1D::destroy())
	rd[0] = 2.3;
	rd.destroy();
	TEST_REAL_EQUAL(rd.getLowerBound(), 0.0)
	TEST_REAL_EQUAL(rd.getUpperBound(), 0.0)
	TEST_EQUAL(rd.getSize(), 0)
RESULT

CHECK(TRegularData1D::TRegularData1D& operator = (const TRegularData1D& data))
	rd.setBoundaries(1.1, 2.1);
	rd.resize(1);
	rd[0] = 1.2;
	RegularData1D rd2 = rd;
	TEST_REAL_EQUAL(rd2.getLowerBound(), 1.1)
	TEST_REAL_EQUAL(rd2.getUpperBound(), 2.1)
	TEST_REAL_EQUAL(rd2[0], 1.2)
	TEST_EQUAL(rd2.getSize(), 1)
RESULT

CHECK(TRegularData1D::TRegularData1D& operator = (const VectorType& data))
	RegularData1D::VectorType v;
	v.push_back(1.1);
	v.push_back(1.2);
	v.push_back(1.3);
	v.push_back(1.4);
	RegularData1D rd2;
	rd2.setBoundaries(0.0, 1.0);
	rd2 = v;
	TEST_REAL_EQUAL(rd2.getLowerBound(), 0.0)
	TEST_REAL_EQUAL(rd2.getUpperBound(), 1.0)
	TEST_EQUAL(rd2.getSize(), 4)
	TEST_REAL_EQUAL(rd2[0], 1.1)
	TEST_REAL_EQUAL(rd2[1], 1.2)
	TEST_REAL_EQUAL(rd2[2], 1.3)
	TEST_REAL_EQUAL(rd2[3], 1.4)
RESULT

CHECK(TRegularData1D::bool operator == (const TRegularData1D& data) const )
	rd.destroy();
	rd.resize(4);
	rd[0] = 1.1;
	rd[1] = 1.2;
	rd[2] = 1.3;
	rd[3] = 1.4;
	RegularData1D rd2 = rd;
	TEST_EQUAL(rd == rd2, true)
	rd2[3] = 1.41;
	TEST_EQUAL(rd == rd2, false)
	rd2[3] = 1.4;
	TEST_EQUAL(rd == rd2, true)
	rd.setBoundaries(1.1, 1.4);
	TEST_EQUAL(rd == rd2, false)
	rd2.setBoundaries(1.1, 1.4);
	TEST_EQUAL(rd == rd2, true)
RESULT

CHECK(TRegularData1D::T& operator [] (Position index) const )
  TEST_REAL_EQUAL(rd[3], 1.4)
	TEST_EXCEPTION(Exception::IndexOverflow, rd[4])
RESULT

CHECK(TRegularData1D::T& operator [] (Position index))
  rd[3] = 1.5;
	TEST_REAL_EQUAL(rd[3], 1.5)
	TEST_EXCEPTION(Exception::IndexOverflow, rd[4] = 44.4)
RESULT

RegularData1D rd2;
CHECK(TRegularData1D::getSize() const )
  TEST_EQUAL(rd.getSize(), 4)
	TEST_EQUAL(rd2.getSize(), 0)
RESULT

CHECK(TRegularData1D::getLowerBound() const )
	rd.setBoundaries(1.1, 1.5);
	TEST_REAL_EQUAL(rd.getLowerBound(), 1.1)
	TEST_REAL_EQUAL(rd2.getLowerBound(), 0.0)
RESULT

CHECK(TRegularData1D::getUpperBound() const )
	TEST_REAL_EQUAL(rd.getUpperBound(), 1.5)
	TEST_REAL_EQUAL(rd2.getUpperBound(), 0.0)
RESULT

CHECK(TRegularData1D::setLowerBound())
	rd.setBoundaries(-99.9, 99.9);
	TEST_REAL_EQUAL(rd.getLowerBound(), -99.9)
	TEST_REAL_EQUAL(rd.getUpperBound(), 99.9)
	rd.setBoundaries(99.9, -99.9);
	TEST_REAL_EQUAL(rd.getLowerBound(), -99.9)
	TEST_REAL_EQUAL(rd.getUpperBound(), 99.9)
RESULT

CHECK(TRegularData1D::resize(Size new_size))
	TEST_EQUAL(rd.getSize(), 4)
	rd.resize(99);
	TEST_EQUAL(rd.getSize(), 99)
	TEST_REAL_EQUAL(rd[98], 0.0)
	rd.resize(3);
	TEST_EQUAL(rd.getSize(), 3)
	TEST_REAL_EQUAL(rd[2], 1.3)
	TEST_EXCEPTION(Exception::IndexOverflow, rd[3])
RESULT

CHECK(TRegularData1D::rescale(Size new_size))
	TRegularData1D<float>	data;
	TEST_EQUAL(data.getSize(), 0)
	data.rescale(1);
	TEST_EQUAL(data.getSize(), 1)
	TEST_EQUAL(data[0], 0.0)
	data[0] = 2.0;
	data.rescale(2);
	TEST_EQUAL(data.getSize(), 2)
	TEST_EQUAL(data[0], 2.0)
	TEST_EQUAL(data[0], 2.0)
	data[0] = 1.0;
	data.rescale(3);
	TEST_EQUAL(data.getSize(), 3)
	TEST_REAL_EQUAL(data[0], 1.0)
	TEST_REAL_EQUAL(data[1], 1.5)
	TEST_REAL_EQUAL(data[2], 2.0)
	data.rescale(4);
	TEST_EQUAL(data.getSize(), 4)
	TEST_REAL_EQUAL(data[0], 1.0)
	TEST_REAL_EQUAL(data[1], 1.3333333)
	TEST_REAL_EQUAL(data[2], 1.6666667)
	TEST_REAL_EQUAL(data[3], 2.0)
RESULT

CHECK(TRegularData1D::rescale(double lower, double upper, Size new_size))
	TRegularData1D<float>	data;
	data.resize(2);
	data.setBoundaries(0.0, 1.0);
	data[0] = 1.0;
	data[1] = 2.0;
	data.rescale(0.0, 1.0, 3);
	TEST_EQUAL(data.getSize(), 3)
	TEST_REAL_EQUAL(data[0], 1.0)
	TEST_REAL_EQUAL(data[1], 1.5)
	TEST_REAL_EQUAL(data[2], 2.0)
	data.rescale(0.0, 1.0, 4);
	TEST_EQUAL(data.getSize(), 4)
	TEST_REAL_EQUAL(data[0], 1.0)
	TEST_REAL_EQUAL(data[1], 1.3333333)
	TEST_REAL_EQUAL(data[2], 1.6666667)
	TEST_REAL_EQUAL(data[3], 2.0)
	data.rescale(0.0, 1.0, 4);
	TEST_EQUAL(data.getSize(), 4)
	TEST_REAL_EQUAL(data[0], 1.0)
	TEST_REAL_EQUAL(data[1], 1.3333333)
	TEST_REAL_EQUAL(data[2], 1.6666667)
	TEST_REAL_EQUAL(data[3], 2.0)
	data.rescale(-1.0, 2.0, 10);
	TEST_EQUAL(data.getSize(), 10)
	TEST_REAL_EQUAL(data[0], 0.0)
	TEST_REAL_EQUAL(data[1], 0.0)
	TEST_REAL_EQUAL(data[2], 0.0)
	TEST_REAL_EQUAL(data[3], 1.0)
	TEST_REAL_EQUAL(data[4], 1.3333333)
	TEST_REAL_EQUAL(data[5], 1.6666667)
	TEST_REAL_EQUAL(data[6], 2.0)
	TEST_REAL_EQUAL(data[7], 0.0)
	TEST_REAL_EQUAL(data[8], 0.0)
	TEST_REAL_EQUAL(data[9], 0.0)
	data.rescale(0.0, 1.0, 3);
	TEST_EQUAL(data.getSize(), 3)
	TEST_REAL_EQUAL(data[0], 1.0)
	TEST_REAL_EQUAL(data[1], 1.5)
	TEST_REAL_EQUAL(data[2], 2.0)
RESULT

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
END_TEST
<|endoftext|>


<commit_before>// $Id: RegularData2D_test.C,v 1.3 2001/06/22 11:07:50 oliver Exp $

#include <BALL/CONCEPT/classTest.h>
#include <BALL/DATATYPE/regularData2D.h>

START_TEST(RegularData2D, "$Id: RegularData2D_test.C,v 1.3 2001/06/22 11:07:50 oliver Exp $")

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////

using namespace BALL;
using namespace std;

String filename;
using BALL::RegularData2D;
RegularData2D*	grid;

CHECK(RegularData2D())
	grid = new RegularData2D();
	TEST_NOT_EQUAL(grid, 0)
RESULT

CHECK(~RegularData2D())
	delete grid;
RESULT

RegularData2D g;

CHECK(RegularData2D(/2))
	g = RegularData2D(0.0, 0.0, 4.0, 9.0, 2.0, 3.0);
	TEST_EQUAL(g.getSize(), 6)

	TEST_REAL_EQUAL(g.getMinX(), 0.0)
	TEST_REAL_EQUAL(g.getMinY(), 0.0)

	TEST_REAL_EQUAL(g.getMaxX(), 4.0)
	TEST_REAL_EQUAL(g.getMaxY(), 9.0)

	TEST_EQUAL(g.getMaxXIndex(), 1)
	TEST_EQUAL(g.getMaxYIndex(), 2)

	TEST_REAL_EQUAL(g.getXSpacing(), 4.0)
	TEST_REAL_EQUAL(g.getYSpacing(), 4.5)

	Vector2 p(0, 0);
	TEST_EQUAL(g.getOrigin()== p, true)
RESULT

CHECK(RegularData2D(const TRegularData2D<GridDataType>& grid, bool deep = true))
	RegularData2D g2(g);
	TEST_EQUAL(g.getSize(), 6)
RESULT

CHECK(clear())
	RegularData2D g2(g);
	g2[1] = 1.234;
	g2.clear();
	TEST_EQUAL(g2.isValid(), false)
	TEST_EQUAL(g2.getSize(), 0)
RESULT

CHECK(getSize())
	TEST_EQUAL(g.getSize(), 6)
	RegularData2D g2;
	TEST_EQUAL(g2.getSize(), 0)
RESULT

CHECK(set(const RegularData2D& grid))
	g[1] = 1.2345;
	RegularData2D g1;
	g1.set(g);
	TEST_EQUAL(g1.getSize(), 6)
	TEST_REAL_EQUAL(g1[1], 1.2345)
RESULT

CHECK(operator = (const RegularData2D& grid))
	g[1] = 1.2345;
	RegularData2D g1;
	g1 = g;
	TEST_EQUAL(g1.getSize(), 6)
	TEST_REAL_EQUAL(g1[1], 1.2345)
RESULT

CHECK(dump())
  String filename;
	NEW_TMP_FILE(filename)
	std::ofstream outfile(filename.c_str(), File::OUT);
	for (Position k = 0; k < g.getSize(); k++)
	{
		g[k] = k;
	}
	g.dump(outfile);
	outfile.close();
	TEST_FILE(filename.c_str(), "data/RegularData2D_test.txt", true)
RESULT

CHECK(isValid())
	TEST_EQUAL(g.isValid(), true)
RESULT

CHECK(getMaxX())
	TEST_REAL_EQUAL(g.getMaxX(), 4.0)
RESULT

CHECK(getMaxY())
	TEST_REAL_EQUAL(g.getMaxY(), 9.0)
RESULT

CHECK(getMinX())
	TEST_REAL_EQUAL(g.getMinX(), 0.0)
RESULT

CHECK(getMinY())
	TEST_REAL_EQUAL(g.getMinY(), 0.0)
RESULT

CHECK(getMaxXIndex())
	TEST_EQUAL(g.getMaxXIndex(), 1)
RESULT

CHECK(getMaxYIndex())
	TEST_EQUAL(g.getMaxYIndex(), 2)
RESULT

CHECK(getXSpacing())
	TEST_REAL_EQUAL(g.getXSpacing(), 4.0)
RESULT

CHECK(getYSpacing())
	TEST_REAL_EQUAL(g.getYSpacing(), 4.5)
RESULT

BALL::RegularData2D::GridIndex	pp;
Vector2 v;

CHECK(getIndex(const Vector2& vector))
	v = Vector2(2.11, 4.51);
	pp = g.getIndex(v);
	TEST_EQUAL(pp.x, 1)
	TEST_EQUAL(pp.y, 1)
RESULT

CHECK(getIndex(/2))
	pp = g.getIndex(2.11, 4.51);
	TEST_EQUAL(pp.x, 1)
	TEST_EQUAL(pp.y, 1)
RESULT

CHECK(getData(Position))
	*(g.getData(0, 0)) = 5.4321;
	v = g.getOrigin();
	TEST_REAL_EQUAL(*(g.getData(0)), 5.4321);
RESULT

CHECK(operator[]/1/2)
	g[5] = 1.2345;
	v = Vector2(3.0, 8.2);
	TEST_EQUAL(g[5], g[v]);
RESULT

CHECK(getGridCoordinates/1)
	v = g.getGridCoordinates(1, 1);
	TEST_REAL_EQUAL(v.x, 4.0)
	TEST_REAL_EQUAL(v.y, 4.5)
RESULT

CHECK(getGridCoordinates/2)
	v = g.getGridCoordinates(5);
	TEST_REAL_EQUAL(v.x, 4.0)
	TEST_REAL_EQUAL(v.y, 9.0)

	TEST_EXCEPTION(Exception::OutOfGrid, v = g.getGridCoordinates(6))
	TEST_EXCEPTION(Exception::OutOfGrid, g.getGridCoordinates(7))
RESULT

CHECK(getRectangleIndices)
	v = Vector2(3.9, 3.9);
	Position p1, p2, p3, p4;
	g.getRectangleIndices(v, p1, p2, p3, p4);
	TEST_EQUAL(p1, 0);
	TEST_EQUAL(p2, 1);
	TEST_EQUAL(p3, 2);
	TEST_EQUAL(p4, 3);

	v = Vector2(3.1, 4.6);
	g.getRectangleIndices(v, p1, p2, p3, p4);
	TEST_EQUAL(p1, 2);
	TEST_EQUAL(p2, 3);
	TEST_EQUAL(p3, 4);
	TEST_EQUAL(p4, 5);

	v = Vector2(10.1, 2.1);
	TEST_EXCEPTION(Exception::OutOfGrid, g.getRectangleIndices(v, p1, p2, p3, p4))
RESULT

CHECK(getRectangleData)
	v = Vector2(0, 4.2);
	float p1, p2, p3, p4;
	g[0] = 1;
	g[1] = 2;
	g[2] = 3;
	g[3] = 4;
	g.getRectangleData(v, p1, p2, p3, p4);
	TEST_EQUAL(p1, 1);
	TEST_EQUAL(p2, 2);
	TEST_EQUAL(p3, 3);
	TEST_EQUAL(p4, 4);

	v = Vector2(4.1, 2.1);
	TEST_EXCEPTION(Exception::OutOfGrid, g.getRectangleData(v, p1, p2, p3, p4))
RESULT

CHECK(getOrigin)
	v = g.getOrigin();
	TEST_REAL_EQUAL(v.x, 0.0)
	TEST_REAL_EQUAL(v.y, 0.0)
RESULT

CHECK(setOrigin/1)
	g.setOrigin(1.0, 1.0);
	v = g.getOrigin();
	TEST_REAL_EQUAL(v.x, 1.0)
	TEST_REAL_EQUAL(v.y, 1.0)
	pp = g.getIndex(2.49, 5.1);
	TEST_EQUAL(pp.x, 0)
	TEST_EQUAL(pp.y, 1)
RESULT

CHECK(setOrigin/2)
	v = Vector2(2.0, 2.0);
	g.setOrigin(v);
	v = g.getOrigin();
	TEST_REAL_EQUAL(v.x, 2.0)
	TEST_REAL_EQUAL(v.y, 2.0)
	pp = g.getIndex(3.94, 6.41);
	TEST_EQUAL(pp.x, 0)
	TEST_EQUAL(pp.y, 1)
RESULT

CHECK(getDimension)
	TEST_REAL_EQUAL(g.getDimension().x, 4.0)
	TEST_REAL_EQUAL(g.getDimension().y, 9.0)
RESULT

g = RegularData2D(0.0, 0.0, 4.0, 9.0, 2.0, 3.0);

CHECK(getInterpolatedValue)
	for (Position i = 0; i < g.getSize() ; i++)
	{
		g[i] = i;
	}
	v = Vector2(0.0, 0.0);
	TEST_EQUAL(g.getInterpolatedValue(v), 0.0)

	v = Vector2(4.0, 9.0);
	TEST_EQUAL(g.getInterpolatedValue(v), 0.0)

	v = Vector2(2.0, 4.5);
	TEST_EQUAL(g.getInterpolatedValue(v), 2.5)

	v = Vector2(4.0, 2.25);
	TEST_EQUAL(g.getInterpolatedValue(v), 2.0)

	v = Vector2(10.1, 0);
	TEST_EXCEPTION(Exception::OutOfGrid, g.getInterpolatedValue(v))
RESULT

RegularData2D grid2 = g;

CHECK(operator ==)
	grid2 = g;
	TEST_EQUAL(g.isValid(), true)
	TEST_EQUAL(g == g, true)
	grid2[5] = -99.9;
	TEST_EQUAL(g == grid2, false)
RESULT

CHECK(operator !=)
	TEST_EQUAL(g != grid2, true)
	grid2[5] = (g)[5];
	TEST_EQUAL(g != grid2, false)
RESULT

CHECK(has()1/1)
	RegularData2D g(0.0, 0.0, 10.0, 10.0, 10, 10);
	TEST_EQUAL(g.has(0.0, 0.0), true)
	TEST_EQUAL(g.has(10.0, 10.0), true)
	TEST_EQUAL(g.has(10.1, 10.0), false)

	RegularData2D h;
	TEST_EQUAL(h.isValid(), false)
	TEST_EQUAL(h.has(0.0, 0.0), false)
RESULT

CHECK(getMinValue())
	RegularData2D g(0.0, 0.0, 10.0, 10.0, 11, 11);
	g.data[0] = -123.23;
	g.data[1] = +123.23;
	g.data[13] = -123.231;
	g.data[3] = -123.230;
	Vector2 vector2;
	const float* float_ptr = g.getMinValue(vector2);
	TEST_NOT_EQUAL(float_ptr, 0)
	if (float_ptr != 0)
	{
		TEST_REAL_EQUAL(*float_ptr, (float) -123.231)
		TEST_EQUAL(vector2.x, 2)
		TEST_EQUAL(vector2.y, 1)

		g.data[120] = -124.11;
		TEST_REAL_EQUAL(*g.getMinValue(vector2), (float) -124.11)
		TEST_EQUAL(vector2.x, 10)
		TEST_EQUAL(vector2.y, 10)
		g.data[120] = 0.11;

		g.data[13] = -123.11;
		TEST_REAL_EQUAL(*g.getMinValue(vector2), (float) -123.23)
		TEST_EQUAL(vector2.x, 0)
		TEST_EQUAL(vector2.y, 0)
	}
RESULT

CHECK(getMaxValue())
	RegularData2D g(0.0, 0.0, 10.0, 10.0, 11, 11);
	g.data[0] = +123.23;
	g.data[1] = +123.23;
	g.data[13] = +123.231;
	g.data[3] = -123.230;
	Vector2 vector2;
	const float* float_ptr = g.getMaxValue(vector2);
	TEST_NOT_EQUAL(float_ptr, 0)
	if (float_ptr != 0)
	{
		TEST_REAL_EQUAL(*float_ptr, (float) +123.231)
		TEST_EQUAL(vector2.x, 2)
		TEST_EQUAL(vector2.y, 1)

		g.data[120] = +124.11;
		TEST_REAL_EQUAL(*g.getMaxValue(vector2), (float) +124.11)
		TEST_EQUAL(vector2.x, 10)
		TEST_EQUAL(vector2.y, 10)
		g.data[120] = 0.11;

		g.data[13] = +123.11;
		TEST_REAL_EQUAL(*g.getMaxValue(vector2), (float) +123.23)
		TEST_EQUAL(vector2.x, 0)
		TEST_EQUAL(vector2.y, 0)
	}
RESULT

CHECK(rescale)
	RegularData2D g(0.0, 0.0, 9.0, 9.0, 10, 10);
	g.data[0] = -4.5;
	g.data[1] = -2.25;
	g.data[2] = 4.5;
	g.rescale(0, 1);
	TEST_EQUAL(g.data[0], 0)
	TEST_EQUAL(g.data[1], 0.25)
	TEST_EQUAL(g.data[2], 1)
	TEST_EQUAL(g.data[3], 0.5)
RESULT

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
END_TEST
<commit_msg>fixed: incorrect oracle value for test<commit_after>// $Id: RegularData2D_test.C,v 1.4 2001/06/23 02:24:07 oliver Exp $

#include <BALL/CONCEPT/classTest.h>
#include <BALL/DATATYPE/regularData2D.h>

START_TEST(RegularData2D, "$Id: RegularData2D_test.C,v 1.4 2001/06/23 02:24:07 oliver Exp $")

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////

using namespace BALL;
using namespace std;

String filename;
using BALL::RegularData2D;
RegularData2D*	grid;

CHECK(RegularData2D())
	grid = new RegularData2D();
	TEST_NOT_EQUAL(grid, 0)
RESULT

CHECK(~RegularData2D())
	delete grid;
RESULT

RegularData2D g;

CHECK(RegularData2D(/2))
	g = RegularData2D(0.0, 0.0, 4.0, 9.0, 2.0, 3.0);
	TEST_EQUAL(g.getSize(), 6)

	TEST_REAL_EQUAL(g.getMinX(), 0.0)
	TEST_REAL_EQUAL(g.getMinY(), 0.0)

	TEST_REAL_EQUAL(g.getMaxX(), 4.0)
	TEST_REAL_EQUAL(g.getMaxY(), 9.0)

	TEST_EQUAL(g.getMaxXIndex(), 1)
	TEST_EQUAL(g.getMaxYIndex(), 2)

	TEST_REAL_EQUAL(g.getXSpacing(), 4.0)
	TEST_REAL_EQUAL(g.getYSpacing(), 4.5)

	Vector2 p(0, 0);
	TEST_EQUAL(g.getOrigin()== p, true)
RESULT

CHECK(RegularData2D(const TRegularData2D<GridDataType>& grid, bool deep = true))
	RegularData2D g2(g);
	TEST_EQUAL(g.getSize(), 6)
RESULT

CHECK(clear())
	RegularData2D g2(g);
	g2[1] = 1.234;
	g2.clear();
	TEST_EQUAL(g2.isValid(), false)
	TEST_EQUAL(g2.getSize(), 0)
RESULT

CHECK(getSize())
	TEST_EQUAL(g.getSize(), 6)
	RegularData2D g2;
	TEST_EQUAL(g2.getSize(), 0)
RESULT

CHECK(set(const RegularData2D& grid))
	g[1] = 1.2345;
	RegularData2D g1;
	g1.set(g);
	TEST_EQUAL(g1.getSize(), 6)
	TEST_REAL_EQUAL(g1[1], 1.2345)
RESULT

CHECK(operator = (const RegularData2D& grid))
	g[1] = 1.2345;
	RegularData2D g1;
	g1 = g;
	TEST_EQUAL(g1.getSize(), 6)
	TEST_REAL_EQUAL(g1[1], 1.2345)
RESULT

CHECK(dump())
  String filename;
	NEW_TMP_FILE(filename)
	std::ofstream outfile(filename.c_str(), File::OUT);
	for (Position k = 0; k < g.getSize(); k++)
	{
		g[k] = k;
	}
	g.dump(outfile);
	outfile.close();
	TEST_FILE(filename.c_str(), "data/RegularData2D_test.txt", true)
RESULT

CHECK(isValid())
	TEST_EQUAL(g.isValid(), true)
RESULT

CHECK(getMaxX())
	TEST_REAL_EQUAL(g.getMaxX(), 4.0)
RESULT

CHECK(getMaxY())
	TEST_REAL_EQUAL(g.getMaxY(), 9.0)
RESULT

CHECK(getMinX())
	TEST_REAL_EQUAL(g.getMinX(), 0.0)
RESULT

CHECK(getMinY())
	TEST_REAL_EQUAL(g.getMinY(), 0.0)
RESULT

CHECK(getMaxXIndex())
	TEST_EQUAL(g.getMaxXIndex(), 1)
RESULT

CHECK(getMaxYIndex())
	TEST_EQUAL(g.getMaxYIndex(), 2)
RESULT

CHECK(getXSpacing())
	TEST_REAL_EQUAL(g.getXSpacing(), 4.0)
RESULT

CHECK(getYSpacing())
	TEST_REAL_EQUAL(g.getYSpacing(), 4.5)
RESULT

BALL::RegularData2D::GridIndex	pp;
Vector2 v;

CHECK(getIndex(const Vector2& vector))
	v = Vector2(2.11, 4.51);
	pp = g.getIndex(v);
	TEST_EQUAL(pp.x, 1)
	TEST_EQUAL(pp.y, 1)
RESULT

CHECK(getIndex(/2))
	pp = g.getIndex(2.11, 4.51);
	TEST_EQUAL(pp.x, 1)
	TEST_EQUAL(pp.y, 1)
RESULT

CHECK(getData(Position))
	*(g.getData(0, 0)) = 5.4321;
	v = g.getOrigin();
	TEST_REAL_EQUAL(*(g.getData(0)), 5.4321);
RESULT

CHECK(operator[]/1/2)
	g[5] = 1.2345;
	v = Vector2(3.0, 8.2);
	TEST_EQUAL(g[5], g[v]);
RESULT

CHECK(getGridCoordinates/1)
	v = g.getGridCoordinates(1, 1);
	TEST_REAL_EQUAL(v.x, 4.0)
	TEST_REAL_EQUAL(v.y, 4.5)
RESULT

CHECK(getGridCoordinates/2)
	v = g.getGridCoordinates(5);
	TEST_REAL_EQUAL(v.x, 4.0)
	TEST_REAL_EQUAL(v.y, 9.0)

	TEST_EXCEPTION(Exception::OutOfGrid, v = g.getGridCoordinates(6))
	TEST_EXCEPTION(Exception::OutOfGrid, g.getGridCoordinates(7))
RESULT

CHECK(getRectangleIndices)
	v = Vector2(3.9, 3.9);
	Position p1, p2, p3, p4;
	g.getRectangleIndices(v, p1, p2, p3, p4);
	TEST_EQUAL(p1, 0);
	TEST_EQUAL(p2, 1);
	TEST_EQUAL(p3, 2);
	TEST_EQUAL(p4, 3);

	v = Vector2(3.1, 4.6);
	g.getRectangleIndices(v, p1, p2, p3, p4);
	TEST_EQUAL(p1, 2);
	TEST_EQUAL(p2, 3);
	TEST_EQUAL(p3, 4);
	TEST_EQUAL(p4, 5);

	v = Vector2(10.1, 2.1);
	TEST_EXCEPTION(Exception::OutOfGrid, g.getRectangleIndices(v, p1, p2, p3, p4))
RESULT

CHECK(getRectangleData)
	v = Vector2(0, 4.2);
	float p1, p2, p3, p4;
	g[0] = 1;
	g[1] = 2;
	g[2] = 3;
	g[3] = 4;
	g.getRectangleData(v, p1, p2, p3, p4);
	TEST_EQUAL(p1, 1);
	TEST_EQUAL(p2, 2);
	TEST_EQUAL(p3, 3);
	TEST_EQUAL(p4, 4);

	v = Vector2(4.1, 2.1);
	TEST_EXCEPTION(Exception::OutOfGrid, g.getRectangleData(v, p1, p2, p3, p4))
RESULT

CHECK(getOrigin)
	v = g.getOrigin();
	TEST_REAL_EQUAL(v.x, 0.0)
	TEST_REAL_EQUAL(v.y, 0.0)
RESULT

CHECK(setOrigin/1)
	g.setOrigin(1.0, 1.0);
	v = g.getOrigin();
	TEST_REAL_EQUAL(v.x, 1.0)
	TEST_REAL_EQUAL(v.y, 1.0)
	pp = g.getIndex(2.49, 5.1);
	TEST_EQUAL(pp.x, 0)
	TEST_EQUAL(pp.y, 1)
RESULT

CHECK(setOrigin/2)
	v = Vector2(2.0, 2.0);
	g.setOrigin(v);
	v = g.getOrigin();
	TEST_REAL_EQUAL(v.x, 2.0)
	TEST_REAL_EQUAL(v.y, 2.0)
	pp = g.getIndex(3.94, 6.41);
	TEST_EQUAL(pp.x, 0)
	TEST_EQUAL(pp.y, 1)
RESULT

CHECK(getDimension)
	TEST_REAL_EQUAL(g.getDimension().x, 4.0)
	TEST_REAL_EQUAL(g.getDimension().y, 9.0)
RESULT

g = RegularData2D(0.0, 0.0, 4.0, 9.0, 2.0, 3.0);

CHECK(getInterpolatedValue)
	for (Position i = 0; i < g.getSize() ; i++)
	{
		g[i] = i;
	}
	v = Vector2(0.0, 0.0);
	TEST_EQUAL(g.getInterpolatedValue(v), 0.0)

	v = Vector2(4.0, 9.0);
	TEST_EQUAL(g.getInterpolatedValue(v), 5.0)

	v = Vector2(2.0, 4.5);
	TEST_EQUAL(g.getInterpolatedValue(v), 2.5)

	v = Vector2(4.0, 2.25);
	TEST_EQUAL(g.getInterpolatedValue(v), 2.0)

	v = Vector2(10.1, 0);
	TEST_EXCEPTION(Exception::OutOfGrid, g.getInterpolatedValue(v))
RESULT

RegularData2D grid2 = g;

CHECK(operator ==)
	grid2 = g;
	TEST_EQUAL(g.isValid(), true)
	TEST_EQUAL(g == g, true)
	grid2[5] = -99.9;
	TEST_EQUAL(g == grid2, false)
RESULT

CHECK(operator !=)
	TEST_EQUAL(g != grid2, true)
	grid2[5] = (g)[5];
	TEST_EQUAL(g != grid2, false)
RESULT

CHECK(has()1/1)
	RegularData2D g(0.0, 0.0, 10.0, 10.0, 10, 10);
	TEST_EQUAL(g.has(0.0, 0.0), true)
	TEST_EQUAL(g.has(10.0, 10.0), true)
	TEST_EQUAL(g.has(10.1, 10.0), false)

	RegularData2D h;
	TEST_EQUAL(h.isValid(), false)
	TEST_EQUAL(h.has(0.0, 0.0), false)
RESULT

CHECK(getMinValue())
	RegularData2D g(0.0, 0.0, 10.0, 10.0, 11, 11);
	g.data[0] = -123.23;
	g.data[1] = +123.23;
	g.data[13] = -123.231;
	g.data[3] = -123.230;
	Vector2 vector2;
	const float* float_ptr = g.getMinValue(vector2);
	TEST_NOT_EQUAL(float_ptr, 0)
	if (float_ptr != 0)
	{
		TEST_REAL_EQUAL(*float_ptr, (float) -123.231)
		TEST_EQUAL(vector2.x, 2)
		TEST_EQUAL(vector2.y, 1)

		g.data[120] = -124.11;
		TEST_REAL_EQUAL(*g.getMinValue(vector2), (float) -124.11)
		TEST_EQUAL(vector2.x, 10)
		TEST_EQUAL(vector2.y, 10)
		g.data[120] = 0.11;

		g.data[13] = -123.11;
		TEST_REAL_EQUAL(*g.getMinValue(vector2), (float) -123.23)
		TEST_EQUAL(vector2.x, 0)
		TEST_EQUAL(vector2.y, 0)
	}
RESULT

CHECK(getMaxValue())
	RegularData2D g(0.0, 0.0, 10.0, 10.0, 11, 11);
	g.data[0] = +123.23;
	g.data[1] = +123.23;
	g.data[13] = +123.231;
	g.data[3] = -123.230;
	Vector2 vector2;
	const float* float_ptr = g.getMaxValue(vector2);
	TEST_NOT_EQUAL(float_ptr, 0)
	if (float_ptr != 0)
	{
		TEST_REAL_EQUAL(*float_ptr, (float) +123.231)
		TEST_EQUAL(vector2.x, 2)
		TEST_EQUAL(vector2.y, 1)

		g.data[120] = +124.11;
		TEST_REAL_EQUAL(*g.getMaxValue(vector2), (float) +124.11)
		TEST_EQUAL(vector2.x, 10)
		TEST_EQUAL(vector2.y, 10)
		g.data[120] = 0.11;

		g.data[13] = +123.11;
		TEST_REAL_EQUAL(*g.getMaxValue(vector2), (float) +123.23)
		TEST_EQUAL(vector2.x, 0)
		TEST_EQUAL(vector2.y, 0)
	}
RESULT

CHECK(rescale)
	RegularData2D g(0.0, 0.0, 9.0, 9.0, 10, 10);
	g.data[0] = -4.5;
	g.data[1] = -2.25;
	g.data[2] = 4.5;
	g.rescale(0, 1);
	TEST_EQUAL(g.data[0], 0)
	TEST_EQUAL(g.data[1], 0.25)
	TEST_EQUAL(g.data[2], 1)
	TEST_EQUAL(g.data[3], 0.5)
RESULT

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
END_TEST
<|endoftext|>