<commit_before>/*************************************************************************
 *
 *  $RCSfile: listenercalls.hxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: obo $ $Date: 2003-10-21 08:46:42 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 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
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef SC_LISTENERCALLS_HXX
#define SC_LISTENERCALLS_HXX

#include <list>

#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_
#include <com/sun/star/uno/Reference.hxx>
#endif

namespace com { namespace sun { namespace star {
    namespace util {
        class XModifyListener;
    }
    namespace lang {
        struct EventObject;
    }
} } }

struct ScUnoListenerEntry
{
    ::com::sun::star::uno::Reference<
        ::com::sun::star::util::XModifyListener >   xListener;
    ::com::sun::star::lang::EventObject             aEvent;

    ScUnoListenerEntry( const ::com::sun::star::uno::Reference<
                            ::com::sun::star::util::XModifyListener >& rL,
                        const ::com::sun::star::lang::EventObject& rE ) :
        xListener( rL ),
        aEvent( rE )
    {}
};

/** ScUnoListenerCalls stores notifications to XModifyListener that can't be processed
    during BroadcastUno and calls them together at the end.
*/
class ScUnoListenerCalls
{
private:
    ::std::list<ScUnoListenerEntry> aEntries;

public:
                ScUnoListenerCalls();
                ~ScUnoListenerCalls();

    void        Add( const ::com::sun::star::uno::Reference<
                            ::com::sun::star::util::XModifyListener >& rListener,
                        const ::com::sun::star::lang::EventObject& rEvent );
    void        ExecuteAndClear();
};

#endif

<commit_msg>INTEGRATION: CWS rowlimit (1.2.40); FILE MERGED 2003/11/28 19:47:23 er 1.2.40.1: #i1967# move ScAddress, ScRange from global.hxx to address.hxx<commit_after>/*************************************************************************
 *
 *  $RCSfile: listenercalls.hxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: obo $ $Date: 2004-06-04 10:10:36 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 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
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifndef SC_LISTENERCALLS_HXX
#define SC_LISTENERCALLS_HXX

#include <list>

#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_
#include <com/sun/star/uno/Reference.hxx>
#endif
#ifndef _COM_SUN_STAR_LANG_EVENTOBJECT_HPP_
#include <com/sun/star/lang/EventObject.hpp>
#endif

namespace com { namespace sun { namespace star {
    namespace util {
        class XModifyListener;
    }
    namespace lang {
        struct EventObject;
    }
} } }

struct ScUnoListenerEntry
{
    ::com::sun::star::uno::Reference<
        ::com::sun::star::util::XModifyListener >   xListener;
    ::com::sun::star::lang::EventObject             aEvent;

    ScUnoListenerEntry( const ::com::sun::star::uno::Reference<
                            ::com::sun::star::util::XModifyListener >& rL,
                        const ::com::sun::star::lang::EventObject& rE ) :
        xListener( rL ),
        aEvent( rE )
    {}
};

/** ScUnoListenerCalls stores notifications to XModifyListener that can't be processed
    during BroadcastUno and calls them together at the end.
*/
class ScUnoListenerCalls
{
private:
    ::std::list<ScUnoListenerEntry> aEntries;

public:
                ScUnoListenerCalls();
                ~ScUnoListenerCalls();

    void        Add( const ::com::sun::star::uno::Reference<
                            ::com::sun::star::util::XModifyListener >& rListener,
                        const ::com::sun::star::lang::EventObject& rEvent );
    void        ExecuteAndClear();
};

#endif

<|endoftext|>


<commit_before>// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/browser_notification_observers.h"

#include "chrome/browser/chrome_thread.h"
#include "chrome/common/notification_service.h"

namespace {

// Static function that records uptime in /proc/uptime to tmp for metrics use.
void RecordUptime() {
  system("cat /proc/uptime > /tmp/uptime-chrome-first-render &");
}

}  // namespace

namespace chromeos {

InitialTabNotificationObserver::InitialTabNotificationObserver() {
  registrar_.Add(this, NotificationType::LOAD_START,
                 NotificationService::AllSources());
}

InitialTabNotificationObserver::~InitialTabNotificationObserver() {
}

void InitialTabNotificationObserver::Observe(
    NotificationType type,
    const NotificationSource& source,
    const NotificationDetails& details) {
  // Only log for first tab to render.  Make sure this is only done once.
  if (type == NotificationType::LOAD_START &&
      num_tabs_.GetNext() == 0) {
    // If we can't post it, it doesn't matter.
    ChromeThread::PostTask(
        ChromeThread::FILE, FROM_HERE,
        NewRunnableFunction(RecordUptime));
    registrar_.Remove(this, NotificationType::LOAD_START,
                      NotificationService::AllSources());
  }
}

}  // namespace chromeos
<commit_msg>ChromiumOS: read /proc/uptime without using system().<commit_after>// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/browser_notification_observers.h"

#include <string>

#include "base/file_util.h"
#include "chrome/browser/chrome_thread.h"
#include "chrome/common/notification_service.h"

namespace {

// Static function that records uptime in /proc/uptime to tmp for metrics use.
void RecordUptime() {
  std::string uptime;
  const FilePath proc_uptime = FilePath("/proc/uptime");
  const FilePath uptime_output = FilePath("/tmp/uptime-chrome-first-render");

  if (file_util::ReadFileToString(proc_uptime, &uptime))
    file_util::WriteFile(uptime_output, uptime.data(), uptime.size());
}

}  // namespace

namespace chromeos {

InitialTabNotificationObserver::InitialTabNotificationObserver() {
  registrar_.Add(this, NotificationType::LOAD_START,
                 NotificationService::AllSources());
}

InitialTabNotificationObserver::~InitialTabNotificationObserver() {
}

void InitialTabNotificationObserver::Observe(
    NotificationType type,
    const NotificationSource& source,
    const NotificationDetails& details) {
  // Only log for first tab to render.  Make sure this is only done once.
  if (type == NotificationType::LOAD_START &&
      num_tabs_.GetNext() == 0) {
    // If we can't post it, it doesn't matter.
    ChromeThread::PostTask(
        ChromeThread::FILE, FROM_HERE,
        NewRunnableFunction(RecordUptime));
    registrar_.Remove(this, NotificationType::LOAD_START,
                      NotificationService::AllSources());
  }
}

}  // namespace chromeos
<|endoftext|>


<commit_before>#include "pen.h"
#include "renderer.h"
#include "timer.h"
#include "file_system.h"
#include "pen_string.h"
#include "loader.h"
#include "dev_ui.h"
#include "camera.h"
#include "debug_render.h"
#include "component_entity.h"
#include "layer_controller.h"
#include "render_controller.h"
#include "pmfx.h"
#include "pen_json.h"
#include "hash.h"
#include "str_utilities.h"

pen::window_creation_params pen_window
{
    1280,					//width
    720,					//height
    4,						//MSAA samples
    "model_viewer"		    //window title / process name
};

enum e_camera_mode : s32
{
	CAMERA_MODELLING = 0,
	CAMERA_FLY = 1
};

const c8* camera_mode_names[] =
{
	"Modelling",
	"Fly"
};

struct model_view_controller
{
	put::camera		main_camera;
	e_camera_mode	camera_mode = CAMERA_MODELLING;

};
model_view_controller k_model_view_controller;

using namespace put;

void update_model_viewer_camera(put::camera_controller* cc)
{
    //update camera
    if( !(dev_ui::want_capture() & dev_ui::MOUSE) )
    {
        switch (k_model_view_controller.camera_mode)
        {
            case CAMERA_MODELLING:
                put::camera_update_modelling(cc->camera);
                break;
            case CAMERA_FLY:
                put::camera_update_fly(cc->camera);
                break;
        }
    }

    put::camera_update_shader_constants(cc->camera);
}

void update_model_viewer_scene(put::scene_controller* sc)
{
    static bool open_scene_browser = false;
    static bool open_import = false;
    static bool open_save = false;
    static bool open_camera_menu = false;
    static bool open_resource_menu = false;
    static bool dev_open = false;
    static bool set_project_dir = false;
    static Str project_dir_str = dev_ui::get_program_preference("project_dir").as_str();

    ImGui::BeginMainMenuBar();

    if (ImGui::BeginMenu(ICON_FA_LEMON_O))
    {
        ImGui::MenuItem("Save");
        ImGui::MenuItem("Import", NULL, &open_import);

        if( ImGui::BeginMenu("Project Directory") )
        {
            ImGui::MenuItem("Set..", NULL, &set_project_dir);
            ImGui::Text("Dir: %s", project_dir_str.c_str());

            ImGui::EndMenu();
        }

        ImGui::MenuItem("Dev", NULL, &dev_open);

        ImGui::EndMenu();
    }

    if (ImGui::Button(ICON_FA_FLOPPY_O))
    {
        open_save = true;
    }

    if (ImGui::Button(ICON_FA_FOLDER_OPEN))
    {
        open_import = true;
    }

    if (ImGui::Button(ICON_FA_SEARCH))
    {
        open_scene_browser = true;
    }

    if (ImGui::Button(ICON_FA_VIDEO_CAMERA))
    {
        open_camera_menu = true;
    }

    if (ImGui::Button(ICON_FA_CUBES))
    {
        open_resource_menu = true;
    }

    ImGui::EndMainMenuBar();

    if( open_import )
    {
        const c8* import = put::dev_ui::file_browser(open_import, 2, dev_ui::FB_OPEN, "**.pmm", "**.pms" );

        if( import )
        {
            u32 len = pen::string_length( import );

            if( import[len-1] == 'm' )
            {
                put::ces::load_pmm( import, sc->scene );
            }
            else if( import[len-1] == 's' )
            {
                put::ces::load_scene( import, sc->scene );
            }
        }
    }

    if (open_scene_browser)
    {
        ces::scene_browser_ui(sc->scene, &open_scene_browser);
    }

    if( open_camera_menu )
    {
        if( ImGui::Begin("Camera", &open_camera_menu) )
        {
            ImGui::Combo("Camera Mode", (s32*)&k_model_view_controller.camera_mode, (const c8**)&camera_mode_names, 2);

            ImGui::End();
        }
    }

    if( open_resource_menu )
    {
        put::ces::enumerate_resources( &open_resource_menu );
    }

    if( set_project_dir )
    {
        const c8* set_proj = put::dev_ui::file_browser(set_project_dir, dev_ui::FB_OPEN, 1, "**." );

        if(set_proj)
        {
            project_dir_str = set_proj;
            dev_ui::set_program_preference("project_dir", project_dir_str);
        }
    }

    if( open_save )
    {
        const c8* save_file = put::dev_ui::file_browser(open_save, dev_ui::FB_SAVE, 1, "**.pms" );

        if(save_file)
        {
            put::ces::save_scene(save_file, sc->scene);
        }
    }

    if( dev_open )
    {
        if( ImGui::Begin("Dev", &dev_open) )
        {
            if( ImGui::CollapsingHeader("Icons") )
            {
                debug_show_icons();
            }

            ImGui::End();
        }
    }

    static u32 timer_index = pen::timer_create("scene_update_timer");

    pen::timer_accum(timer_index);
    f32 dt_ms = pen::timer_get_ms(timer_index);
    pen::timer_reset(timer_index);
    pen::timer_start(timer_index);

    //update render data
    put::ces::update_scene(sc->scene, dt_ms);
}

void update_model_view(put::layer* layer)
{

}

PEN_THREAD_RETURN pen::game_entry( void* params )
{
    //unpack the params passed to the thread and signal to the engine it ok to proceed
    pen::job_thread_params* job_params = (pen::job_thread_params*)params;
    pen::job_thread* p_thread_info = job_params->job_thread_info;
    pen::threads_semaphore_signal(p_thread_info->p_sem_continue, 1);

	//init systems
	put::layer_controller_init();

	put::dev_ui::init();
	put::dbg::init();

	//create main camera and controller
	put::camera main_camera;
	put::camera_create_perspective( &main_camera, 60.0f, (f32)pen_window.width / (f32)pen_window.height, 0.1f, 1000.0f );

    put::camera_controller cc;
    cc.camera = &main_camera;
    cc.update_function = &update_model_viewer_camera;
    cc.name = "model_viewer_camera";
    cc.id_name = PEN_HASH(cc.name.c_str());

    //create the main scene and controller
    put::ces::entity_scene* main_scene = put::ces::create_scene("main_scene");

    put::scene_controller sc;
    sc.scene = main_scene;
    sc.update_function = &update_model_viewer_scene;
    sc.name = "main_scene";
    sc.id_name = PEN_HASH(sc.name.c_str());

    put::render_controller::register_scene(sc);
    put::render_controller::register_camera(cc);

    put::render_controller::init("data/configs/renderer.json");

    put::built_in_handles handles = put::layer_controller_built_in_handles();

	//create model viewer layer
	put::layer main_layer;

	//layer scene view and update
	main_layer.view.scene = main_scene;
	main_layer.camera = main_camera;
	main_layer.update_function = &update_model_view;

	//render targets and states
	main_layer.clear_state = handles.default_clear_state;
	main_layer.colour_targets[0] = PEN_DEFAULT_RT;
	main_layer.depth_target = PEN_DEFAULT_DS;
	main_layer.viewport = handles.back_buffer_vp;
	main_layer.scissor_rect = handles.back_buffer_scissor_rect;
	main_layer.depth_stencil_state = handles.depth_stencil_state_write_less;
	main_layer.raster_state = handles.raster_state_fill_cull_back;
	main_layer.blend_state = handles.blend_disabled;

	//add main layer to the viewer
	put::layer_controller_add_layer(main_layer);

    while( 1 )
    {
		put::dev_ui::new_frame();

		put::layer_controller_update();

        put::render_controller::update();

        put::render_controller::render();

        put::render_controller::show_dev_ui();

		put::dev_ui::render();

        pen::renderer_present();

        pen::renderer_consume_cmd_buffer();

		pmfx::poll_for_changes();

        //msg from the engine we want to terminate
        if( pen::threads_semaphore_try_wait( p_thread_info->p_sem_exit ) )
        {
            break;
        }
    }

    //clean up mem here
	put::layer_controller_shutdown();
	put::dbg::shutdown();
	put::dev_ui::shutdown();

    pen::renderer_consume_cmd_buffer();

    //signal to the engine the thread has finished
    pen::threads_semaphore_signal( p_thread_info->p_sem_terminated, 1);

    return PEN_THREAD_OK;
}
<commit_msg>resource read back functionality in renderer api +gl backend<commit_after>#include "pen.h"
#include "renderer.h"
#include "timer.h"
#include "file_system.h"
#include "pen_string.h"
#include "loader.h"
#include "dev_ui.h"
#include "camera.h"
#include "debug_render.h"
#include "component_entity.h"
#include "layer_controller.h"
#include "render_controller.h"
#include "pmfx.h"
#include "pen_json.h"
#include "hash.h"
#include "str_utilities.h"
#include "input.h"

pen::window_creation_params pen_window
{
    1280,					//width
    720,					//height
    4,						//MSAA samples
    "model_viewer"		    //window title / process name
};

enum e_camera_mode : s32
{
	CAMERA_MODELLING = 0,
	CAMERA_FLY = 1
};

const c8* camera_mode_names[] =
{
	"Modelling",
	"Fly"
};

struct model_view_controller
{
	put::camera		main_camera;
	e_camera_mode	camera_mode = CAMERA_MODELLING;

};
model_view_controller k_model_view_controller;

using namespace put;

void update_model_viewer_camera(put::camera_controller* cc)
{
    //update camera
    if( !(dev_ui::want_capture() & dev_ui::MOUSE) )
    {
        switch (k_model_view_controller.camera_mode)
        {
            case CAMERA_MODELLING:
                put::camera_update_modelling(cc->camera);
                break;
            case CAMERA_FLY:
                put::camera_update_fly(cc->camera);
                break;
        }
    }

    put::camera_update_shader_constants(cc->camera);
}

void update_model_viewer_scene(put::scene_controller* sc)
{
    static bool open_scene_browser = false;
    static bool open_import = false;
    static bool open_save = false;
    static bool open_camera_menu = false;
    static bool open_resource_menu = false;
    static bool dev_open = false;
    static bool set_project_dir = false;
    static bool picking_mode = false;
    static Str project_dir_str = dev_ui::get_program_preference("project_dir").as_str();

    ImGui::BeginMainMenuBar();

    if (ImGui::BeginMenu(ICON_FA_LEMON_O))
    {
        ImGui::MenuItem("Save");
        ImGui::MenuItem("Import", NULL, &open_import);

        if( ImGui::BeginMenu("Project Directory") )
        {
            ImGui::MenuItem("Set..", NULL, &set_project_dir);
            ImGui::Text("Dir: %s", project_dir_str.c_str());

            ImGui::EndMenu();
        }

        ImGui::MenuItem("Dev", NULL, &dev_open);

        ImGui::EndMenu();
    }

    if (ImGui::Button(ICON_FA_FLOPPY_O))
    {
        open_save = true;
    }

    if (ImGui::Button(ICON_FA_FOLDER_OPEN))
    {
        open_import = true;
    }

    if (ImGui::Button(ICON_FA_SEARCH))
    {
        open_scene_browser = true;
    }

    if (ImGui::Button(ICON_FA_VIDEO_CAMERA))
    {
        open_camera_menu = true;
    }

    if (ImGui::Button(ICON_FA_CUBES))
    {
        open_resource_menu = true;
    }

    if (ImGui::Button(ICON_FA_MOUSE_POINTER))
    {
        picking_mode = true;
    }

    ImGui::EndMainMenuBar();

    if( open_import )
    {
        const c8* import = put::dev_ui::file_browser(open_import, 2, dev_ui::FB_OPEN, "**.pmm", "**.pms" );

        if( import )
        {
            u32 len = pen::string_length( import );

            if( import[len-1] == 'm' )
            {
                put::ces::load_pmm( import, sc->scene );
            }
            else if( import[len-1] == 's' )
            {
                put::ces::load_scene( import, sc->scene );
            }
        }
    }

    if (open_scene_browser)
    {
        ces::scene_browser_ui(sc->scene, &open_scene_browser);
    }

    if( open_camera_menu )
    {
        if( ImGui::Begin("Camera", &open_camera_menu) )
        {
            ImGui::Combo("Camera Mode", (s32*)&k_model_view_controller.camera_mode, (const c8**)&camera_mode_names, 2);

            ImGui::End();
        }
    }

    if( open_resource_menu )
    {
        put::ces::enumerate_resources( &open_resource_menu );
    }

    if( set_project_dir )
    {
        const c8* set_proj = put::dev_ui::file_browser(set_project_dir, dev_ui::FB_OPEN, 1, "**." );

        if(set_proj)
        {
            project_dir_str = set_proj;
            dev_ui::set_program_preference("project_dir", project_dir_str);
        }
    }

    if( open_save )
    {
        const c8* save_file = put::dev_ui::file_browser(open_save, dev_ui::FB_SAVE, 1, "**.pms" );

        if(save_file)
        {
            put::ces::save_scene(save_file, sc->scene);
        }
    }

    if( dev_open )
    {
        if( ImGui::Begin("Dev", &dev_open) )
        {
            if( ImGui::CollapsingHeader("Icons") )
            {
                debug_show_icons();
            }

            ImGui::End();
        }
    }

    static bool picking_debug = false;
    static u8 pick_res[4];

    if( picking_mode )
    {
        static u32 picking_state = 0;

        if( picking_state == 1 )
        {
            if( put::render_controller::get_picking_result(pick_res) )
            {
                picking_state = 0;
                picking_debug = true;
            }
        }
        else
        {
            if( !(dev_ui::want_capture() & dev_ui::MOUSE) )
            {
                pen::mouse_state ms = pen::input_get_mouse_state();

                if (ms.buttons[PEN_MOUSE_L])
                {
                    put::render_controller::perform_picking(ms.x, ms.y);
                    picking_state = 1;
                }
            }
        }
    }

    if( picking_debug )
    {
        if( ImGui::Begin("picking") )
        {
            f32 col[4];
            for( s32 i = 0; i < 4; ++i )
                col[i] = (f32)pick_res[i] / (255.0f);

            ImGui::ColorEdit4("pick result", col );
            ImGui::End();
        }
    }

    static u32 timer_index = pen::timer_create("scene_update_timer");

    pen::timer_accum(timer_index);
    f32 dt_ms = pen::timer_get_ms(timer_index);
    pen::timer_reset(timer_index);
    pen::timer_start(timer_index);

    //update render data
    put::ces::update_scene(sc->scene, dt_ms);
}

void update_model_view(put::layer* layer)
{

}

PEN_THREAD_RETURN pen::game_entry( void* params )
{
    //unpack the params passed to the thread and signal to the engine it ok to proceed
    pen::job_thread_params* job_params = (pen::job_thread_params*)params;
    pen::job_thread* p_thread_info = job_params->job_thread_info;
    pen::threads_semaphore_signal(p_thread_info->p_sem_continue, 1);

	//init systems
	put::layer_controller_init();

	put::dev_ui::init();
	put::dbg::init();

	//create main camera and controller
	put::camera main_camera;
	put::camera_create_perspective( &main_camera, 60.0f, (f32)pen_window.width / (f32)pen_window.height, 0.1f, 1000.0f );

    put::camera_controller cc;
    cc.camera = &main_camera;
    cc.update_function = &update_model_viewer_camera;
    cc.name = "model_viewer_camera";
    cc.id_name = PEN_HASH(cc.name.c_str());

    //create the main scene and controller
    put::ces::entity_scene* main_scene = put::ces::create_scene("main_scene");

    put::scene_controller sc;
    sc.scene = main_scene;
    sc.update_function = &update_model_viewer_scene;
    sc.name = "main_scene";
    sc.id_name = PEN_HASH(sc.name.c_str());

    put::render_controller::register_scene(sc);
    put::render_controller::register_camera(cc);

    put::render_controller::init("data/configs/renderer.json");

    put::built_in_handles handles = put::layer_controller_built_in_handles();

	//create model viewer layer
	put::layer main_layer;

	//layer scene view and update
	main_layer.view.scene = main_scene;
	main_layer.camera = main_camera;
	main_layer.update_function = &update_model_view;

	//render targets and states
	main_layer.clear_state = handles.default_clear_state;
	main_layer.colour_targets[0] = PEN_DEFAULT_RT;
	main_layer.depth_target = PEN_DEFAULT_DS;
	main_layer.viewport = handles.back_buffer_vp;
	main_layer.scissor_rect = handles.back_buffer_scissor_rect;
	main_layer.depth_stencil_state = handles.depth_stencil_state_write_less;
	main_layer.raster_state = handles.raster_state_fill_cull_back;
	main_layer.blend_state = handles.blend_disabled;

	//add main layer to the viewer
	put::layer_controller_add_layer(main_layer);

    while( 1 )
    {
		put::dev_ui::new_frame();

		put::layer_controller_update();

        put::render_controller::update();

        put::render_controller::render();

        put::render_controller::show_dev_ui();

		put::dev_ui::render();

        pen::renderer_present();

        pen::renderer_consume_cmd_buffer();

		pmfx::poll_for_changes();

        //msg from the engine we want to terminate
        if( pen::threads_semaphore_try_wait( p_thread_info->p_sem_exit ) )
        {
            break;
        }
    }

    //clean up mem here
	put::layer_controller_shutdown();
	put::dbg::shutdown();
	put::dev_ui::shutdown();

    pen::renderer_consume_cmd_buffer();

    //signal to the engine the thread has finished
    pen::threads_semaphore_signal( p_thread_info->p_sem_terminated, 1);

    return PEN_THREAD_OK;
}
<|endoftext|>


<commit_before>//  Boost online_test.cpp  ---------------------------------------------------//

//  (C) Copyright Gennadiy Rozental 2001.
//  Permission to copy, use, modify, sell and distribute this software is
//  granted provided this copyright notice appears in all copies.
//  This software is provided "as is" without express or implied warranty,
//  and with no claim as to its suitability for any purpose.

//  See http://www.boost.org for updates, documentation, and revision history.

#include <libs/test/src/unit_test_result.cpp>
#include <libs/test/src/unit_test_suite.cpp>

#include <boost/test/test_tools.hpp>

int
test_main( int argc, char * argv[] )
{
    return 0;
}

#include <libs/test/src/execution_monitor.cpp>
#include <libs/test/src/test_main.cpp>
#include <libs/test/src/test_tools.cpp>
#include <libs/test/src/unit_test_parameters.cpp>
#include <libs/test/src/unit_test_log.cpp>
#include <libs/test/src/unit_test_monitor.cpp>

//  Revision History
//  25 Nov 01  Initial  version (Gennadiy Rozental)

// EOF
<commit_msg>try to commit from new location<commit_after>//  Boost online_test.cpp  ---------------------------------------------------//

//  (C) Copyright Gennadiy Rozental 2001-2002.
//  Permission to copy, use, modify, sell and distribute this software is
//  granted provided this copyright notice appears in all copies.
//  This software is provided "as is" without express or implied warranty,
//  and with no claim as to its suitability for any purpose.

//  See http://www.boost.org for updates, documentation, and revision history.

#include <libs/test/src/unit_test_result.cpp>
#include <libs/test/src/unit_test_suite.cpp>

#include <boost/test/test_tools.hpp>

int
test_main( int argc, char * argv[] )
{
    return 0;
}

#include <libs/test/src/execution_monitor.cpp>
#include <libs/test/src/test_main.cpp>
#include <libs/test/src/test_tools.cpp>
#include <libs/test/src/unit_test_parameters.cpp>
#include <libs/test/src/unit_test_log.cpp>
#include <libs/test/src/unit_test_monitor.cpp>

//  Revision History
//  25 Nov 01  Initial  version (Gennadiy Rozental)

// EOF
<|endoftext|>


<commit_before>#include <gtest/gtest.h>

#include "robots.h"

TEST(RobotsTest, DisallowFirst)
{
    // Disallow must be preceeded by a User-Agent line
    ASSERT_THROW(Rep::Robots("Disallow: /path"), std::invalid_argument);
}

TEST(RobotsTest, AllowFirst)
{
    // Allow must be preceeded by a User-Agent line
    ASSERT_THROW(Rep::Robots("Allow: /path"), std::invalid_argument);
}

TEST(RobotsTest, CrawlDelayFirst)
{
    // Crawl-delay must be preceeded by a User-Agent line
    ASSERT_THROW(Rep::Robots("Crawl-delay: 1"), std::invalid_argument);
}

TEST(RobotsTest, WellFormedCrawlDelay)
{
    std::string content =
        "User-agent: *\n"
        "Crawl-delay: 5.2\n";
    Rep::Robots robot(content);
    EXPECT_NEAR(robot.agent("any").delay(), 5.2, 0.000001);
}

TEST(RobotsTest, MalformedCrawlDelay)
{
    std::string content =
        "User-agent: *\n"
        "Crawl-delay: word\n";
    Rep::Robots robot(content);
    EXPECT_EQ(robot.agent("any").delay(), -1.0);
}

TEST(RobotsTest, HonorsDefaultAgent)
{
    std::string content =
        "User-agent: *\n"
        "Disallow: /tmp\n"
        "\n"
        "User-agent: other-agent\n"
        "Allow: /tmp\n";
    Rep::Robots robot(content);
    EXPECT_FALSE(robot.allowed("/tmp", "agent"));
    EXPECT_TRUE(robot.allowed("/path", "agent"));
}

TEST(RobotsTest, HonorsSpecificAgent)
{
    std::string content =
        "User-agent: *\n"
        "Disallow: /tmp\n"
        "\n"
        "User-agent: agent\n"
        "Allow: /tmp\n";
    Rep::Robots robot(content);
    EXPECT_TRUE(robot.allowed("/tmp", "agent"));
    EXPECT_TRUE(robot.allowed("/path", "agent"));
}

TEST(RobotsTest, Grouping)
{
    std::string content =
        "User-agent: one\n"
        "User-agent: two\n"
        "Disallow: /tmp\n";
    Rep::Robots robot(content);
    EXPECT_FALSE(robot.allowed("/tmp", "one"));
    EXPECT_FALSE(robot.allowed("/tmp", "two"));
}

TEST(RobotsTest, GroupingUnknownKeys)
{
    // When we encounter unknown keys, we should disregard any grouping that may have
    // happened between user agent rules.
    //
    // This is an example from the wild. Despite `Noindex` not being a valid directive,
    // we'll not consider the "*" and "ia_archiver" rules together.
    std::string content =
        "User-agent: *\n"
        "Disallow: /content/2/\n"
        "User-agent: *\n"
        "Noindex: /gb.html\n"
        "Noindex: /content/2/\n"
        "User-agent: ia_archiver\n"
        "Disallow: /\n";
    Rep::Robots robot(content);
    EXPECT_TRUE(robot.allowed("/foo", "agent"));
    EXPECT_FALSE(robot.allowed("/bar", "ia_archiver"));
}

TEST(RobotsTest, SeparatesAgents)
{
    std::string content =
        "User-agent: one\n"
        "Crawl-delay: 1\n"
        "\n"
        "User-agent: two\n"
        "Crawl-delay: 2\n";
    Rep::Robots robot(content);
    EXPECT_NE(robot.agent("one").delay(), robot.agent("two").delay());
}

TEST(RobotsTest, ExposesSitemaps)
{
    std::string content =
        "Sitemap: http://a.com/sitemap.xml\n"
        "Sitemap: http://b.com/sitemap.xml\n";
    Rep::Robots robot(content);
    std::vector<std::string> expected = {
        "http://a.com/sitemap.xml", "http://b.com/sitemap.xml"
    };
    EXPECT_EQ(robot.sitemaps(), expected);
}

TEST(RobotsTest, CaseInsensitivity)
{
    std::string content =
        "User-agent: Agent\n"
        "Disallow: /path\n";
    Rep::Robots robot(content);
    EXPECT_FALSE(robot.allowed("/path", "agent"));
    EXPECT_FALSE(robot.allowed("/path", "aGeNt"));
}

TEST(RobotsTest, Empty)
{
    std::string content;
    Rep::Robots robot(content);
    EXPECT_TRUE(robot.sitemaps().empty());
    EXPECT_TRUE(robot.allowed("/", "agent"));
}

TEST(RobotsTest, Comments)
{
    std::string content =
        "User-Agent: *  # comment saying it's the default agent\n"
        "Disallow: /\n";
    Rep::Robots robot(content);
    EXPECT_FALSE(robot.allowed("/path", "agent"));
}

TEST(RobotsTest, AcceptsFullUrl)
{
    std::string content =
        "User-Agent: agent\n"
        "Disallow: /path;params?query\n";
    Rep::Robots robot(content);
    EXPECT_FALSE(robot.allowed(
        "http://userinfo@exmaple.com:10/path;params?query#fragment", "agent"));
}

TEST(RobotsTest, SkipMalformedLine)
{
    std::string content =
        "User-Agent: agent\n"
        "Disallow /no/colon/in/this/line\n";
    Rep::Robots robot(content);
    EXPECT_TRUE(robot.allowed("/no/colon/in/this/line", "agent"));
}

TEST(RobotsTest, RobotsUrlHttp)
{
    std::string url("http://user@example.com:80/path;params?query#fragment");
    std::string expected("http://example.com/robots.txt");
    EXPECT_EQ(expected, Rep::Robots::robotsUrl(url));
}

TEST(RobotsTest, RobotsUrlHttps)
{
    std::string url("https://user@example.com:443/path;params?query#fragment");
    std::string expected("https://example.com/robots.txt");
    EXPECT_EQ(expected, Rep::Robots::robotsUrl(url));
}

TEST(RobotsTest, RobotsUrlNonDefaultPort)
{
    std::string url("http://user@example.com:8080/path;params?query#fragment");
    std::string expected("http://example.com:8080/robots.txt");
    EXPECT_EQ(expected, Rep::Robots::robotsUrl(url));
}

TEST(RobotsTest, RfcExample)
{
    std::string content =
        "# /robots.txt for http://www.fict.org/\n"
        "# comments to webmaster@fict.org\n"
        "\n"
        "User-agent: unhipbot\n"
        "Disallow: /\n"
        "\n"
        "User-agent: webcrawler\n"
        "User-agent: excite\n"
        "Disallow:\n"
        "\n"
        "User-agent: *\n"
        "Disallow: /org/plans.html\n"
        "Allow: /org/\n"
        "Allow: /serv\n"
        "Allow: /~mak\n"
        "Disallow: /\n";
    Rep::Robots robot(content);

    // The unhip bot
    EXPECT_FALSE(robot.allowed("/", "unhipbot"));
    EXPECT_FALSE(robot.allowed("/index.html", "unhipbot"));
    EXPECT_TRUE(robot.allowed("/robots.txt", "unhipbot"));
    EXPECT_FALSE(robot.allowed("/server.html", "unhipbot"));
    EXPECT_FALSE(robot.allowed("/services/fast.html", "unhipbot"));
    EXPECT_FALSE(robot.allowed("/services/slow.html", "unhipbot"));
    EXPECT_FALSE(robot.allowed("/orgo.gif", "unhipbot"));
    EXPECT_FALSE(robot.allowed("/org/about.html", "unhipbot"));
    EXPECT_FALSE(robot.allowed("/org/plans.html", "unhipbot"));
    EXPECT_FALSE(robot.allowed("/%7Ejim/jim.html", "unhipbot"));
    EXPECT_FALSE(robot.allowed("/%7Emak/mak.html", "unhipbot"));

    // The webcrawler agent
    EXPECT_TRUE(robot.allowed("/", "webcrawler"));
    EXPECT_TRUE(robot.allowed("/index.html", "webcrawler"));
    EXPECT_TRUE(robot.allowed("/robots.txt", "webcrawler"));
    EXPECT_TRUE(robot.allowed("/server.html", "webcrawler"));
    EXPECT_TRUE(robot.allowed("/services/fast.html", "webcrawler"));
    EXPECT_TRUE(robot.allowed("/services/slow.html", "webcrawler"));
    EXPECT_TRUE(robot.allowed("/orgo.gif", "webcrawler"));
    EXPECT_TRUE(robot.allowed("/org/about.html", "webcrawler"));
    EXPECT_TRUE(robot.allowed("/org/plans.html", "webcrawler"));
    EXPECT_TRUE(robot.allowed("/%7Ejim/jim.html", "webcrawler"));
    EXPECT_TRUE(robot.allowed("/%7Emak/mak.html", "webcrawler"));

    // The excite agent
    EXPECT_TRUE(robot.allowed("/", "excite"));
    EXPECT_TRUE(robot.allowed("/index.html", "excite"));
    EXPECT_TRUE(robot.allowed("/robots.txt", "excite"));
    EXPECT_TRUE(robot.allowed("/server.html", "excite"));
    EXPECT_TRUE(robot.allowed("/services/fast.html", "excite"));
    EXPECT_TRUE(robot.allowed("/services/slow.html", "excite"));
    EXPECT_TRUE(robot.allowed("/orgo.gif", "excite"));
    EXPECT_TRUE(robot.allowed("/org/about.html", "excite"));
    EXPECT_TRUE(robot.allowed("/org/plans.html", "excite"));
    EXPECT_TRUE(robot.allowed("/%7Ejim/jim.html", "excite"));
    EXPECT_TRUE(robot.allowed("/%7Emak/mak.html", "excite"));

    // All others
    EXPECT_FALSE(robot.allowed("/", "anything"));
    EXPECT_FALSE(robot.allowed("/index.html", "anything"));
    EXPECT_TRUE(robot.allowed("/robots.txt", "anything"));
    EXPECT_TRUE(robot.allowed("/server.html", "anything"));
    EXPECT_TRUE(robot.allowed("/services/fast.html", "anything"));
    EXPECT_TRUE(robot.allowed("/services/slow.html", "anything"));
    EXPECT_FALSE(robot.allowed("/orgo.gif", "anything"));
    EXPECT_TRUE(robot.allowed("/org/about.html", "anything"));
    EXPECT_FALSE(robot.allowed("/org/plans.html", "anything"));
    EXPECT_FALSE(robot.allowed("/%7Ejim/jim.html", "anything"));
    EXPECT_TRUE(robot.allowed("/%7Emak/mak.html", "anything"));
}
<commit_msg>Drop trailing whitespace.<commit_after>#include <gtest/gtest.h>

#include "robots.h"

TEST(RobotsTest, DisallowFirst)
{
    // Disallow must be preceeded by a User-Agent line
    ASSERT_THROW(Rep::Robots("Disallow: /path"), std::invalid_argument);
}

TEST(RobotsTest, AllowFirst)
{
    // Allow must be preceeded by a User-Agent line
    ASSERT_THROW(Rep::Robots("Allow: /path"), std::invalid_argument);
}

TEST(RobotsTest, CrawlDelayFirst)
{
    // Crawl-delay must be preceeded by a User-Agent line
    ASSERT_THROW(Rep::Robots("Crawl-delay: 1"), std::invalid_argument);
}

TEST(RobotsTest, WellFormedCrawlDelay)
{
    std::string content =
        "User-agent: *\n"
        "Crawl-delay: 5.2\n";
    Rep::Robots robot(content);
    EXPECT_NEAR(robot.agent("any").delay(), 5.2, 0.000001);
}

TEST(RobotsTest, MalformedCrawlDelay)
{
    std::string content =
        "User-agent: *\n"
        "Crawl-delay: word\n";
    Rep::Robots robot(content);
    EXPECT_EQ(robot.agent("any").delay(), -1.0);
}

TEST(RobotsTest, HonorsDefaultAgent)
{
    std::string content =
        "User-agent: *\n"
        "Disallow: /tmp\n"
        "\n"
        "User-agent: other-agent\n"
        "Allow: /tmp\n";
    Rep::Robots robot(content);
    EXPECT_FALSE(robot.allowed("/tmp", "agent"));
    EXPECT_TRUE(robot.allowed("/path", "agent"));
}

TEST(RobotsTest, HonorsSpecificAgent)
{
    std::string content =
        "User-agent: *\n"
        "Disallow: /tmp\n"
        "\n"
        "User-agent: agent\n"
        "Allow: /tmp\n";
    Rep::Robots robot(content);
    EXPECT_TRUE(robot.allowed("/tmp", "agent"));
    EXPECT_TRUE(robot.allowed("/path", "agent"));
}

TEST(RobotsTest, Grouping)
{
    std::string content =
        "User-agent: one\n"
        "User-agent: two\n"
        "Disallow: /tmp\n";
    Rep::Robots robot(content);
    EXPECT_FALSE(robot.allowed("/tmp", "one"));
    EXPECT_FALSE(robot.allowed("/tmp", "two"));
}

TEST(RobotsTest, GroupingUnknownKeys)
{
    // When we encounter unknown keys, we should disregard any grouping that may have
    // happened between user agent rules.
    //
    // This is an example from the wild. Despite `Noindex` not being a valid directive,
    // we'll not consider the "*" and "ia_archiver" rules together.
    std::string content =
        "User-agent: *\n"
        "Disallow: /content/2/\n"
        "User-agent: *\n"
        "Noindex: /gb.html\n"
        "Noindex: /content/2/\n"
        "User-agent: ia_archiver\n"
        "Disallow: /\n";
    Rep::Robots robot(content);
    EXPECT_TRUE(robot.allowed("/foo", "agent"));
    EXPECT_FALSE(robot.allowed("/bar", "ia_archiver"));
}

TEST(RobotsTest, SeparatesAgents)
{
    std::string content =
        "User-agent: one\n"
        "Crawl-delay: 1\n"
        "\n"
        "User-agent: two\n"
        "Crawl-delay: 2\n";
    Rep::Robots robot(content);
    EXPECT_NE(robot.agent("one").delay(), robot.agent("two").delay());
}

TEST(RobotsTest, ExposesSitemaps)
{
    std::string content =
        "Sitemap: http://a.com/sitemap.xml\n"
        "Sitemap: http://b.com/sitemap.xml\n";
    Rep::Robots robot(content);
    std::vector<std::string> expected = {
        "http://a.com/sitemap.xml", "http://b.com/sitemap.xml"
    };
    EXPECT_EQ(robot.sitemaps(), expected);
}

TEST(RobotsTest, CaseInsensitivity)
{
    std::string content =
        "User-agent: Agent\n"
        "Disallow: /path\n";
    Rep::Robots robot(content);
    EXPECT_FALSE(robot.allowed("/path", "agent"));
    EXPECT_FALSE(robot.allowed("/path", "aGeNt"));
}

TEST(RobotsTest, Empty)
{
    std::string content;
    Rep::Robots robot(content);
    EXPECT_TRUE(robot.sitemaps().empty());
    EXPECT_TRUE(robot.allowed("/", "agent"));
}

TEST(RobotsTest, Comments)
{
    std::string content =
        "User-Agent: *  # comment saying it's the default agent\n"
        "Disallow: /\n";
    Rep::Robots robot(content);
    EXPECT_FALSE(robot.allowed("/path", "agent"));
}

TEST(RobotsTest, AcceptsFullUrl)
{
    std::string content =
        "User-Agent: agent\n"
        "Disallow: /path;params?query\n";
    Rep::Robots robot(content);
    EXPECT_FALSE(robot.allowed(
        "http://userinfo@exmaple.com:10/path;params?query#fragment", "agent"));
}

TEST(RobotsTest, SkipMalformedLine)
{
    std::string content =
        "User-Agent: agent\n"
        "Disallow /no/colon/in/this/line\n";
    Rep::Robots robot(content);
    EXPECT_TRUE(robot.allowed("/no/colon/in/this/line", "agent"));
}

TEST(RobotsTest, RobotsUrlHttp)
{
    std::string url("http://user@example.com:80/path;params?query#fragment");
    std::string expected("http://example.com/robots.txt");
    EXPECT_EQ(expected, Rep::Robots::robotsUrl(url));
}

TEST(RobotsTest, RobotsUrlHttps)
{
    std::string url("https://user@example.com:443/path;params?query#fragment");
    std::string expected("https://example.com/robots.txt");
    EXPECT_EQ(expected, Rep::Robots::robotsUrl(url));
}

TEST(RobotsTest, RobotsUrlNonDefaultPort)
{
    std::string url("http://user@example.com:8080/path;params?query#fragment");
    std::string expected("http://example.com:8080/robots.txt");
    EXPECT_EQ(expected, Rep::Robots::robotsUrl(url));
}

TEST(RobotsTest, RfcExample)
{
    std::string content =
        "# /robots.txt for http://www.fict.org/\n"
        "# comments to webmaster@fict.org\n"
        "\n"
        "User-agent: unhipbot\n"
        "Disallow: /\n"
        "\n"
        "User-agent: webcrawler\n"
        "User-agent: excite\n"
        "Disallow:\n"
        "\n"
        "User-agent: *\n"
        "Disallow: /org/plans.html\n"
        "Allow: /org/\n"
        "Allow: /serv\n"
        "Allow: /~mak\n"
        "Disallow: /\n";
    Rep::Robots robot(content);

    // The unhip bot
    EXPECT_FALSE(robot.allowed("/", "unhipbot"));
    EXPECT_FALSE(robot.allowed("/index.html", "unhipbot"));
    EXPECT_TRUE(robot.allowed("/robots.txt", "unhipbot"));
    EXPECT_FALSE(robot.allowed("/server.html", "unhipbot"));
    EXPECT_FALSE(robot.allowed("/services/fast.html", "unhipbot"));
    EXPECT_FALSE(robot.allowed("/services/slow.html", "unhipbot"));
    EXPECT_FALSE(robot.allowed("/orgo.gif", "unhipbot"));
    EXPECT_FALSE(robot.allowed("/org/about.html", "unhipbot"));
    EXPECT_FALSE(robot.allowed("/org/plans.html", "unhipbot"));
    EXPECT_FALSE(robot.allowed("/%7Ejim/jim.html", "unhipbot"));
    EXPECT_FALSE(robot.allowed("/%7Emak/mak.html", "unhipbot"));

    // The webcrawler agent
    EXPECT_TRUE(robot.allowed("/", "webcrawler"));
    EXPECT_TRUE(robot.allowed("/index.html", "webcrawler"));
    EXPECT_TRUE(robot.allowed("/robots.txt", "webcrawler"));
    EXPECT_TRUE(robot.allowed("/server.html", "webcrawler"));
    EXPECT_TRUE(robot.allowed("/services/fast.html", "webcrawler"));
    EXPECT_TRUE(robot.allowed("/services/slow.html", "webcrawler"));
    EXPECT_TRUE(robot.allowed("/orgo.gif", "webcrawler"));
    EXPECT_TRUE(robot.allowed("/org/about.html", "webcrawler"));
    EXPECT_TRUE(robot.allowed("/org/plans.html", "webcrawler"));
    EXPECT_TRUE(robot.allowed("/%7Ejim/jim.html", "webcrawler"));
    EXPECT_TRUE(robot.allowed("/%7Emak/mak.html", "webcrawler"));

    // The excite agent
    EXPECT_TRUE(robot.allowed("/", "excite"));
    EXPECT_TRUE(robot.allowed("/index.html", "excite"));
    EXPECT_TRUE(robot.allowed("/robots.txt", "excite"));
    EXPECT_TRUE(robot.allowed("/server.html", "excite"));
    EXPECT_TRUE(robot.allowed("/services/fast.html", "excite"));
    EXPECT_TRUE(robot.allowed("/services/slow.html", "excite"));
    EXPECT_TRUE(robot.allowed("/orgo.gif", "excite"));
    EXPECT_TRUE(robot.allowed("/org/about.html", "excite"));
    EXPECT_TRUE(robot.allowed("/org/plans.html", "excite"));
    EXPECT_TRUE(robot.allowed("/%7Ejim/jim.html", "excite"));
    EXPECT_TRUE(robot.allowed("/%7Emak/mak.html", "excite"));

    // All others
    EXPECT_FALSE(robot.allowed("/", "anything"));
    EXPECT_FALSE(robot.allowed("/index.html", "anything"));
    EXPECT_TRUE(robot.allowed("/robots.txt", "anything"));
    EXPECT_TRUE(robot.allowed("/server.html", "anything"));
    EXPECT_TRUE(robot.allowed("/services/fast.html", "anything"));
    EXPECT_TRUE(robot.allowed("/services/slow.html", "anything"));
    EXPECT_FALSE(robot.allowed("/orgo.gif", "anything"));
    EXPECT_TRUE(robot.allowed("/org/about.html", "anything"));
    EXPECT_FALSE(robot.allowed("/org/plans.html", "anything"));
    EXPECT_FALSE(robot.allowed("/%7Ejim/jim.html", "anything"));
    EXPECT_TRUE(robot.allowed("/%7Emak/mak.html", "anything"));
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: BPreparedStatement.cxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: hr $ $Date: 2006-06-20 01:10:07 $
 *
 *  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 CONNECTIVITY_ADABAS_PREPAREDSTATEMENT_HXX
#include "adabas/BPreparedStatement.hxx"
#endif
#ifndef CONNECTIVITY_ADABAS_RESULTSET_HXX
#include "adabas/BResultSet.hxx"
#endif
#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
#include <com/sun/star/lang/DisposedException.hpp>
#endif
#ifndef _DBHELPER_DBEXCEPTION_HXX_
#include <connectivity/dbexception.hxx>
#endif

using namespace connectivity;
using namespace connectivity::adabas;
using namespace connectivity::odbc;
//------------------------------------------------------------------------------
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::beans;
using namespace com::sun::star::sdbc;
using namespace com::sun::star::sdbcx;
using namespace com::sun::star::container;
using namespace com::sun::star::io;
using namespace com::sun::star::util;

OAdabasPreparedStatement::OAdabasPreparedStatement( OAdabasConnection* _pConnection,const ::std::vector<OTypeInfo>& _TypeInfo,const ::rtl::OUString& sql)
: ::connectivity::odbc::OPreparedStatement( _pConnection,_TypeInfo,sql)
{
    m_aSelectColumns = _pConnection->createSelectColumns(sql);
}
// -----------------------------------------------------------------------------
OResultSet* OAdabasPreparedStatement::createResulSet()
{
    return new OAdabasResultSet(m_aStatementHandle,this,m_aSelectColumns);
}
// -----------------------------------------------------------------------------
void OAdabasPreparedStatement::setUsingBookmarks(sal_Bool /*_bUseBookmark*/)
{
    ::dbtools::throwFeatureNotImplementedException( "bookmarks", *this );
    // adabas doesn't support bookmarks
}
// -----------------------------------------------------------------------------
void OAdabasPreparedStatement::setResultSetConcurrency(sal_Int32 /*_par0*/)
{
    ::dbtools::throwFeatureNotImplementedException( "non-standard result set concurrencies: ", *this );
}
// -----------------------------------------------------------------------------
void OAdabasPreparedStatement::setResultSetType(sal_Int32 /*_par0*/)
{
    ::dbtools::throwFeatureNotImplementedException( "non-standard result set types: ", *this );
}
// -----------------------------------------------------------------------------

<commit_msg>INTEGRATION: CWS pchfix02 (1.7.60); FILE MERGED 2006/09/01 17:21:52 kaib 1.7.60.1: #i68856# Added header markers and pch files<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: BPreparedStatement.cxx,v $
 *
 *  $Revision: 1.8 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 02:08:21 $
 *
 *  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
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_connectivity.hxx"
#ifndef CONNECTIVITY_ADABAS_PREPAREDSTATEMENT_HXX
#include "adabas/BPreparedStatement.hxx"
#endif
#ifndef CONNECTIVITY_ADABAS_RESULTSET_HXX
#include "adabas/BResultSet.hxx"
#endif
#ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
#include <com/sun/star/lang/DisposedException.hpp>
#endif
#ifndef _DBHELPER_DBEXCEPTION_HXX_
#include <connectivity/dbexception.hxx>
#endif

using namespace connectivity;
using namespace connectivity::adabas;
using namespace connectivity::odbc;
//------------------------------------------------------------------------------
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::beans;
using namespace com::sun::star::sdbc;
using namespace com::sun::star::sdbcx;
using namespace com::sun::star::container;
using namespace com::sun::star::io;
using namespace com::sun::star::util;

OAdabasPreparedStatement::OAdabasPreparedStatement( OAdabasConnection* _pConnection,const ::std::vector<OTypeInfo>& _TypeInfo,const ::rtl::OUString& sql)
: ::connectivity::odbc::OPreparedStatement( _pConnection,_TypeInfo,sql)
{
    m_aSelectColumns = _pConnection->createSelectColumns(sql);
}
// -----------------------------------------------------------------------------
OResultSet* OAdabasPreparedStatement::createResulSet()
{
    return new OAdabasResultSet(m_aStatementHandle,this,m_aSelectColumns);
}
// -----------------------------------------------------------------------------
void OAdabasPreparedStatement::setUsingBookmarks(sal_Bool /*_bUseBookmark*/)
{
    ::dbtools::throwFeatureNotImplementedException( "bookmarks", *this );
    // adabas doesn't support bookmarks
}
// -----------------------------------------------------------------------------
void OAdabasPreparedStatement::setResultSetConcurrency(sal_Int32 /*_par0*/)
{
    ::dbtools::throwFeatureNotImplementedException( "non-standard result set concurrencies: ", *this );
}
// -----------------------------------------------------------------------------
void OAdabasPreparedStatement::setResultSetType(sal_Int32 /*_par0*/)
{
    ::dbtools::throwFeatureNotImplementedException( "non-standard result set types: ", *this );
}
// -----------------------------------------------------------------------------

<|endoftext|>


<commit_before>#include <gtest/gtest.h>
#include <stdlib.h>
#include <cmath>
#include <vmath.h>

namespace {

	void vectorCompare(VEC vector, float x, float y, float z, float w) {
		float values[4];
		VectorGet(values, vector);
		EXPECT_FLOAT_EQ(x, values[0]);
		EXPECT_FLOAT_EQ(y, values[1]);
		EXPECT_FLOAT_EQ(z, values[2]);
		EXPECT_FLOAT_EQ(w, values[3]);
	}

	TEST(Vector, SettingAndGetting) {
		float x = rand(), y = rand(), z = rand(), w = rand();
		VEC vector = VectorSet(x, y, z, w);
		vectorCompare(vector, x, y, z, w);
	}

	TEST(Vector, Replicating) {
		float f = rand();
		VEC vector = VectorReplicate(f);
		vectorCompare(vector, f, f, f, f);
	}

	TEST(Vector, Loading) {
		float v[] = { rand(), rand(), rand(), rand() };
		VEC vector = VectorLoad(v);
		vectorCompare(vector, v[0], v[1], v[2], v[3]);
	}

	TEST(Vector, Arithmetic) {
		float x1, y1, z1, w1, x2, y2, z2, w2;
		x1 = rand();
		y1 = rand();
		z1 = rand();
		w1 = rand();
		x2 = rand();
		y2 = rand();
		z2 = rand();
		w2 = rand();
		VEC v1 = VectorSet(x1, y1, z1, w1), v2 = VectorSet(x2, y2, z2, w2);
		vectorCompare(VectorAdd(v1, v2), x1 + x2, y1 + y2, z1 + z2, w1 + w2);
		vectorCompare(VectorSubtract(v1, v2), x1 - x2, y1 - y2, z1 - z2, w1 - w2);
		vectorCompare(VectorMultiply(v1, v2), x1 * x2, y1 * y2, z1 * z2, w1 * w2);
		vectorCompare(VectorDivide(v1, v2), x1 / x2, y1 / y2, z1 / z2, w1 / w2);
	}

	TEST(Vector, Length) {
		VEC vector = VectorSet(3, 4, 6, 0);
		EXPECT_FLOAT_EQ(std::sqrt(61), VectorLength(vector)) << "The vector's length doesn't equal the square root of 61";
	}

	TEST(Vector, Comparison) {
		float x = rand(), y = rand(), z = rand(), w = rand();
		VEC v1 = VectorSet(x, y, z, w), v2 = VectorSet(x, y, z, w), v3 = VectorSet(-x, -y, -z, -w);
		EXPECT_NE(0, VectorEqual(v1, v2)) << "Vectors [" << x << ", " << y << ", " << z << ", " << w << "] and [" << x << ", " << y << ", " << z << ", " << w << "] differ";
		EXPECT_EQ(0, VectorEqual(v1, v3)) << "Vectors [" << x << ", " << y << ", " << z << ", " << w << "] and [" << -x << ", " << -y << ", " << -z << ", " << -w << "] do not differ";
	}

}<commit_msg>Casting result of rand() to float.<commit_after>#include <gtest/gtest.h>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vmath.h>

namespace {

	float frand() {
		return static_cast <float> (rand());
	}

	void vectorCompare(VEC vector, float x, float y, float z, float w) {
		float values[4];
		VectorGet(values, vector);
		EXPECT_FLOAT_EQ(x, values[0]);
		EXPECT_FLOAT_EQ(y, values[1]);
		EXPECT_FLOAT_EQ(z, values[2]);
		EXPECT_FLOAT_EQ(w, values[3]);
	}

	TEST(Vector, SettingAndGetting) {
		srand (static_cast <unsigned> (time(0)))
		float x = frand(), y = frand(), z = frand(), w = frand();
		VEC vector = VectorSet(x, y, z, w);
		vectorCompare(vector, x, y, z, w);
	}

	TEST(Vector, Replicating) {
		float f = frand();
		VEC vector = VectorReplicate(f);
		vectorCompare(vector, f, f, f, f);
	}

	TEST(Vector, Loading) {
		float v[] = { frand(), frand(), frand(), frand() };
		VEC vector = VectorLoad(v);
		vectorCompare(vector, v[0], v[1], v[2], v[3]);
	}

	TEST(Vector, Arithmetic) {
		float x1, y1, z1, w1, x2, y2, z2, w2;
		x1 = frand();
		y1 = frand();
		z1 = frand();
		w1 = frand();
		x2 = frand();
		y2 = frand();
		z2 = frand();
		w2 = frand();
		VEC v1 = VectorSet(x1, y1, z1, w1), v2 = VectorSet(x2, y2, z2, w2);
		vectorCompare(VectorAdd(v1, v2), x1 + x2, y1 + y2, z1 + z2, w1 + w2);
		vectorCompare(VectorSubtract(v1, v2), x1 - x2, y1 - y2, z1 - z2, w1 - w2);
		vectorCompare(VectorMultiply(v1, v2), x1 * x2, y1 * y2, z1 * z2, w1 * w2);
		vectorCompare(VectorDivide(v1, v2), x1 / x2, y1 / y2, z1 / z2, w1 / w2);
	}

	TEST(Vector, Length) {
		VEC vector = VectorSet(3, 4, 6, 0);
		EXPECT_FLOAT_EQ(std::sqrt(61), VectorLength(vector)) << "The vector's length doesn't equal the square root of 61";
	}

	TEST(Vector, Comparison) {
		float x = frand(), y = frand(), z = frand(), w = frand();
		VEC v1 = VectorSet(x, y, z, w), v2 = VectorSet(x, y, z, w), v3 = VectorSet(-x, -y, -z, -w);
		EXPECT_NE(0, VectorEqual(v1, v2)) << "Vectors [" << x << ", " << y << ", " << z << ", " << w << "] and [" << x << ", " << y << ", " << z << ", " << w << "] differ";
		EXPECT_EQ(0, VectorEqual(v1, v3)) << "Vectors [" << x << ", " << y << ", " << z << ", " << w << "] and [" << -x << ", " << -y << ", " << -z << ", " << -w << "] do not differ";
	}

}<|endoftext|>


<commit_before>#include "libtorrent/natpmp.hpp"
#include "libtorrent/socket.hpp"
#include "libtorrent/connection_queue.hpp"
#include <boost/bind.hpp>
#include <boost/ref.hpp>
#include <boost/intrusive_ptr.hpp>
#include <iostream>

using namespace libtorrent;

void callback(int mapping, address extip, int port, error_code const& err)
{
	std::cerr
		<< "mapping: " << mapping
		<< ", port: " << port
		<< ", external-IP: " << print_address(extip)
		<< ", error: \"" << err.message() << "\"\n";
}

void log_callback(char const* line)
{
	std::cerr << line << std::endl;
}

int main(int argc, char* argv[])
{
	io_service ios;
	std::string user_agent = "test agent";

	if (argc != 3)
	{
		std::cerr << "usage: " << argv[0] << " tcp-port udp-port" << std::endl;
		return 1;
	}

	connection_queue cc(ios);
	boost::intrusive_ptr<natpmp> natpmp_handler = new natpmp(ios, address_v4()
		, &callback, &log_callback);

	deadline_timer timer(ios);

	int tcp_map = natpmp_handler->add_mapping(natpmp::tcp, atoi(argv[1]), atoi(argv[1]));
	int udp_map = natpmp_handler->add_mapping(natpmp::udp, atoi(argv[2]), atoi(argv[2]));

	error_code ec;
	timer.expires_from_now(seconds(2), ec);
	timer.async_wait(boost::bind(&io_service::stop, boost::ref(ios)));
	std::cerr << "mapping ports TCP: " << argv[1]
		<< " UDP: " << argv[2] << std::endl;

	ios.reset();
	ios.run(ec);
	timer.expires_from_now(seconds(2), ec);
	timer.async_wait(boost::bind(&io_service::stop, boost::ref(ios)));
	std::cerr << "removing mapping " << tcp_map << std::endl;
	natpmp_handler->delete_mapping(tcp_map);

	ios.reset();
	ios.run(ec);
	std::cerr << "removing mappings" << std::endl;
	natpmp_handler->close();

	ios.reset();
	ios.run(ec);
	std::cerr << "closing" << std::endl;
}

<commit_msg>build fix for test_natpmp<commit_after>#include "libtorrent/natpmp.hpp"
#include "libtorrent/socket.hpp"
#include "libtorrent/socket_io.hpp"
#include "libtorrent/connection_queue.hpp"
#include <boost/bind.hpp>
#include <boost/ref.hpp>
#include <boost/intrusive_ptr.hpp>
#include <iostream>

using namespace libtorrent;

void callback(int mapping, address extip, int port, error_code const& err)
{
	std::cerr
		<< "mapping: " << mapping
		<< ", port: " << port
		<< ", external-IP: " << print_address(extip)
		<< ", error: \"" << err.message() << "\"\n";
}

void log_callback(char const* line)
{
	std::cerr << line << std::endl;
}

int main(int argc, char* argv[])
{
	io_service ios;
	std::string user_agent = "test agent";

	if (argc != 3)
	{
		std::cerr << "usage: " << argv[0] << " tcp-port udp-port" << std::endl;
		return 1;
	}

	connection_queue cc(ios);
	boost::intrusive_ptr<natpmp> natpmp_handler = new natpmp(ios, address_v4()
		, &callback, &log_callback);

	deadline_timer timer(ios);

	int tcp_map = natpmp_handler->add_mapping(natpmp::tcp, atoi(argv[1]), atoi(argv[1]));
	int udp_map = natpmp_handler->add_mapping(natpmp::udp, atoi(argv[2]), atoi(argv[2]));

	error_code ec;
	timer.expires_from_now(seconds(2), ec);
	timer.async_wait(boost::bind(&io_service::stop, boost::ref(ios)));
	std::cerr << "mapping ports TCP: " << argv[1]
		<< " UDP: " << argv[2] << std::endl;

	ios.reset();
	ios.run(ec);
	timer.expires_from_now(seconds(2), ec);
	timer.async_wait(boost::bind(&io_service::stop, boost::ref(ios)));
	std::cerr << "removing mapping " << tcp_map << std::endl;
	natpmp_handler->delete_mapping(tcp_map);

	ios.reset();
	ios.run(ec);
	std::cerr << "removing mappings" << std::endl;
	natpmp_handler->close();

	ios.reset();
	ios.run(ec);
	std::cerr << "closing" << std::endl;
}

<|endoftext|>


<commit_before>#include "libtorrent/natpmp.hpp"
#include "libtorrent/socket.hpp"
#include "libtorrent/connection_queue.hpp"
#include <boost/bind.hpp>
#include <boost/ref.hpp>
#include <boost/intrusive_ptr.hpp>

using namespace libtorrent;

void callback(int mapping, int port, std::string const& err)
{
	std::cerr << "mapping: " << mapping << ", port: " << port << ", error: \"" << err << "\"\n";
}

int main(int argc, char* argv[])
{
	io_service ios;
	std::string user_agent = "test agent";

	if (argc != 3)
	{
		std::cerr << "usage: " << argv[0] << " tcp-port udp-port" << std::endl;
		return 1;
	}

	connection_queue cc(ios);
	boost::intrusive_ptr<natpmp> natpmp_handler = new natpmp(ios, address_v4(), &callback);

	deadline_timer timer(ios);

	int tcp_map = natpmp_handler->add_mapping(natpmp::tcp, atoi(argv[1]), atoi(argv[1]));
	int udp_map = natpmp_handler->add_mapping(natpmp::udp, atoi(argv[2]), atoi(argv[2]));

	error_code ec;
	timer.expires_from_now(seconds(2), ec);
	timer.async_wait(boost::bind(&io_service::stop, boost::ref(ios)));
	std::cerr << "mapping ports TCP: " << argv[1]
		<< " UDP: " << argv[2] << std::endl;

	ios.reset();
	ios.run(ec);
	timer.expires_from_now(seconds(2), ec);
	timer.async_wait(boost::bind(&io_service::stop, boost::ref(ios)));
	std::cerr << "removing mapping " << tcp_map << std::endl;
	natpmp_handler->delete_mapping(tcp_map);

	ios.reset();
	ios.run(ec);
	std::cerr << "removing mappings" << std::endl;
	natpmp_handler->close();

	ios.reset();
	ios.run(ec);
	std::cerr << "closing" << std::endl;
}

<commit_msg>fixed test_natpmp build<commit_after>#include "libtorrent/natpmp.hpp"
#include "libtorrent/socket.hpp"
#include "libtorrent/connection_queue.hpp"
#include <boost/bind.hpp>
#include <boost/ref.hpp>
#include <boost/intrusive_ptr.hpp>
#include <iostream>

using namespace libtorrent;

void callback(int mapping, int port, error_code const& err)
{
	std::cerr
		<< "mapping: " << mapping
		<< ", port: " << port
		<< ", error: \"" << err.message() << "\"\n";
}

void log_callback(char const* line)
{
	std::cerr << line << std::endl;
}

int main(int argc, char* argv[])
{
	io_service ios;
	std::string user_agent = "test agent";

	if (argc != 3)
	{
		std::cerr << "usage: " << argv[0] << " tcp-port udp-port" << std::endl;
		return 1;
	}

	connection_queue cc(ios);
	boost::intrusive_ptr<natpmp> natpmp_handler = new natpmp(ios, address_v4()
		, &callback, &log_callback);

	deadline_timer timer(ios);

	int tcp_map = natpmp_handler->add_mapping(natpmp::tcp, atoi(argv[1]), atoi(argv[1]));
	int udp_map = natpmp_handler->add_mapping(natpmp::udp, atoi(argv[2]), atoi(argv[2]));

	error_code ec;
	timer.expires_from_now(seconds(2), ec);
	timer.async_wait(boost::bind(&io_service::stop, boost::ref(ios)));
	std::cerr << "mapping ports TCP: " << argv[1]
		<< " UDP: " << argv[2] << std::endl;

	ios.reset();
	ios.run(ec);
	timer.expires_from_now(seconds(2), ec);
	timer.async_wait(boost::bind(&io_service::stop, boost::ref(ios)));
	std::cerr << "removing mapping " << tcp_map << std::endl;
	natpmp_handler->delete_mapping(tcp_map);

	ios.reset();
	ios.run(ec);
	std::cerr << "removing mappings" << std::endl;
	natpmp_handler->close();

	ios.reset();
	ios.run(ec);
	std::cerr << "closing" << std::endl;
}

<|endoftext|>


<commit_before>#include "McMaker/TofEffFitter.h"
#include "Common.h"

// ROOT
#include "TGraphAsymmErrors.h"
#include "TFile.h"

#include "Reporter.h"
#include "RooPlotLib.h"
using namespace jdb;

void TofEffFitter::initialize( ){

	outputPath = config.getString( nodePath + ".output:path" );
	book = unique_ptr<HistoBook>(
				new HistoBook(
					outputPath + config.getString( nodePath +  ".output.data", "TofEff.root" ),
					config,
					"",
					""
				)
			);

}

void TofEffFitter::make(){

	RooPlotLib rpl;

	string params_file =  config.getString( nodePath + ".output.params" );
	if ( "" == params_file ){
		ERROR( "Specifiy an output params file for the parameters" )
		return;
	}

	ofstream out( params_file.c_str() );

	out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
	out << "<config>" << endl;

	vector<string> labels = config.getStringVector( nodePath + ".CentralityLabels" );
	vector< int> cbins = config.getIntVector( nodePath + ".CentralityBins" );
	Reporter rp( config, nodePath + ".Reporter." );

	for ( string plc : Common::species ){
		string fn = config.getString( nodePath + ".input:url" ) + "TofEff_" + plc + ".root";
		TFile * f = new TFile( fn.c_str(), "READ" );

		if ( !f->IsOpen() )
			continue;

		for ( string cs : Common::sCharges ) {

			out << "\t<" << plc << "_" << cs << ">" << endl;

			// build an efficiency for each centrality
			for ( int b : cbins ){

				TH1 * hAll = (TH1*)f->Get( ("inclusive/pt_" + ts( b ) + "_" + cs).c_str() );
				TH1 * hPass = (TH1*)f->Get( ("inclusiveTof/pt_" + ts( b ) + "_" + cs ).c_str() );

				hAll->Sumw2();
				hPass->Sumw2();

				TGraphAsymmErrors g;

				g.SetName( (plc + "_" + cs + "_" + ts(b)).c_str() );
				g.BayesDivide( hPass, hAll );

				book->add( plc + "_" + cs + "_" + ts(b),  &g );

				rp.newPage();
				rpl.style( &g ).set( "title", Common::plc_label( plc, cs ) + " : " + labels[ b ] ).set( "yr", 0.4, 0.85 ).set( "optfit", 111 )
					.set("y", "Efficiency").set( "x", "p_{T} [GeV/c]" )
					.set( &config, nodePath + "Style.TofEff" )
					.set( "lw", 3 )
					.set( "ms", 3 )
					.draw();

				gStyle->SetStatY( 0.9 );
				gStyle->SetStatX( 0.65 );

				rp.savePage();

				string imgName = outputPath + "/img/TofEff_" + plc + "_" + cs + "_" + ts(b) + ".png";
				INFO( classname(), "Exporting image to : " << imgName );
				rp.saveImage( imgName );

				exportParams( b, &g, out );

			} // loop centrality bins
			out << "\t</" << plc << "_" << cs << ">" << endl;
		}
	} // loop over species

	out << "</config>" << endl;
	out.close();

}

void TofEffFitter::exportParams( int bin, TGraphAsymmErrors * g, ofstream &out ){
	out << "\t\t<TofEffParams bin=\"" << bin << "\" >\n";
	out << Common::toXml( g, "\t\t\t" );
	out << "\n\t\t</TofEffParams>" << endl;
}<commit_msg>TofEff Style<commit_after>#include "McMaker/TofEffFitter.h"
#include "Common.h"

// ROOT
#include "TGraphAsymmErrors.h"
#include "TFile.h"

#include "Reporter.h"
#include "RooPlotLib.h"
using namespace jdb;

void TofEffFitter::initialize( ){

	outputPath = config.getString( nodePath + ".output:path" );
	book = unique_ptr<HistoBook>(
				new HistoBook(
					outputPath + config.getString( nodePath +  ".output.data", "TofEff.root" ),
					config,
					"",
					""
				)
			);

}

void TofEffFitter::make(){

	RooPlotLib rpl;

	string params_file =  config.getString( nodePath + ".output.params" );
	if ( "" == params_file ){
		ERROR( "Specifiy an output params file for the parameters" )
		return;
	}

	ofstream out( params_file.c_str() );

	out << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
	out << "<config>" << endl;

	vector<string> labels = config.getStringVector( nodePath + ".CentralityLabels" );
	vector< int> cbins = config.getIntVector( nodePath + ".CentralityBins" );
	Reporter rp( config, nodePath + ".Reporter." );

	for ( string plc : Common::species ){
		string fn = config.getString( nodePath + ".input:url" ) + "TofEff_" + plc + ".root";
		TFile * f = new TFile( fn.c_str(), "READ" );

		if ( !f->IsOpen() )
			continue;

		for ( string cs : Common::sCharges ) {

			out << "\t<" << plc << "_" << cs << ">" << endl;

			// build an efficiency for each centrality
			for ( int b : cbins ){

				TH1 * hAll = (TH1*)f->Get( ("inclusive/pt_" + ts( b ) + "_" + cs).c_str() );
				TH1 * hPass = (TH1*)f->Get( ("inclusiveTof/pt_" + ts( b ) + "_" + cs ).c_str() );

				hAll->Sumw2();
				hPass->Sumw2();

				TGraphAsymmErrors g;

				g.SetName( (plc + "_" + cs + "_" + ts(b)).c_str() );
				g.BayesDivide( hPass, hAll );

				book->add( plc + "_" + cs + "_" + ts(b),  &g );

				rp.newPage();
				rpl.style( &g )
					.set( "title", Common::plc_label( plc, cs ) + " : " + labels[ b ] )
					.set( "yr", 0.0, 0.85 )
					.set( "optfit", 111 )
					.set("y", "TOF Matching Efficiency")
					.set( "x", "p_{T} [GeV/c]" )
					.set( &config, nodePath + ".Style.TofEff" )
					.draw();

				gStyle->SetStatY( 0.9 );
				gStyle->SetStatX( 0.65 );

				rp.savePage();

				string imgName = outputPath + "/img/TofEff_" + plc + "_" + cs + "_" + ts(b) + ".png";
				INFO( classname(), "Exporting image to : " << imgName );
				rp.saveImage( imgName );

				exportParams( b, &g, out );

			} // loop centrality bins
			out << "\t</" << plc << "_" << cs << ">" << endl;
		}
	} // loop over species

	out << "</config>" << endl;
	out.close();

}

void TofEffFitter::exportParams( int bin, TGraphAsymmErrors * g, ofstream &out ){
	out << "\t\t<TofEffParams bin=\"" << bin << "\" >\n";
	out << Common::toXml( g, "\t\t\t" );
	out << "\n\t\t</TofEffParams>" << endl;
}<|endoftext|>


<commit_before>/*
 * Copyright (c) 2011-2012 by Michael Berlin, Zuse Institute Berlin
 *
 * Licensed under the BSD License, see LICENSE file for details.
 *
 */

#include <gtest/gtest.h>

#include <boost/thread/thread.hpp>
#include <cstdio>
#include <sys/stat.h>
#include <sys/types.h>

#include <fstream>
#include <list>
#include <string>

#include "libxtreemfs/user_mapping.h"
#include "libxtreemfs/user_mapping_gridmap_globus.h"
#include "util/logging.h"
#include "pbrpc/RPC.pb.h"

using namespace std;
using namespace xtreemfs;
using namespace xtreemfs::pbrpc;
using namespace xtreemfs::util;

class UserMappingGridmapGlobusTest : public ::testing::Test {
 protected:
  virtual void SetUp() {
    initialize_logger(LEVEL_WARN);

    gridmap_file_path_ = "gridmap_file_globus";

    // Check if file already exists.
    struct stat stat_buf;
    if (!stat(gridmap_file_path_.c_str(), &stat_buf)) {
      ASSERT_FALSE("The temporary gridmap file does already exist");
    }

    // Create a temporary gridmap file in the working directory.
    ofstream out(gridmap_file_path_.c_str());
    out << "\"/C=DE/O=GridGermany/OU=Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB)/OU=CSR/CN=Michael Berlin\" root\n";
    out.close();

    user_mapping_.reset(new UserMappingGridmapGlobus(
        gridmap_file_path_,
        1));  // Check every second for changes.
    user_mapping_->Start();
  }

  virtual void TearDown() {
    user_mapping_->Stop();

    // Delete gridmap file.
    remove(gridmap_file_path_.c_str());

    shutdown_logger();
    atexit(google::protobuf::ShutdownProtobufLibrary);
  }
  std::string gridmap_file_path_;

  boost::scoped_ptr<UserMapping> user_mapping_;
};

TEST_F(UserMappingGridmapGlobusTest, TestBasicDNAndOUResolving) {
  string result;
  user_mapping_->LocalToGlobalUsername("root", &result);
  EXPECT_EQ("CN=Michael Berlin,OU=CSR,OU=Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB),O=GridGermany,C=DE",  // NOLINT
            result);
  user_mapping_->GlobalToLocalUsername("CN=Michael Berlin,OU=CSR,OU=Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB),O=GridGermany,C=DE",
                                       &result);
  EXPECT_EQ("root",
            result);

  // All OUs will be returned as list of groups of UserCredentials.
  UserCredentials uc;
  user_mapping_->GetGroupnames("root", &uc);
  ASSERT_EQ(2, uc.groups_size());
  EXPECT_EQ("CSR", uc.groups(0));
  EXPECT_EQ("Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB)",
            uc.groups(1));

  // Groups in general do not work and always return "root" or 0.
  user_mapping_->LocalToGlobalGroupname("CSR", &result);
  EXPECT_EQ("root", result);
  user_mapping_->LocalToGlobalGroupname("Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB)", &result);  // NOLINT
  EXPECT_EQ("root", result);
  user_mapping_->GlobalToLocalGroupname("unknowngroup", &result);
  EXPECT_EQ("root", result);

  // List of groups is empty for unknown users.
  UserCredentials uc2;
  user_mapping_->GetGroupnames("nobody", &uc2);
  ASSERT_EQ(0, uc2.groups_size());
}

TEST_F(UserMappingGridmapGlobusTest, GridmapFileReload) {
  string result;
  user_mapping_->LocalToGlobalUsername("root", &result);
  EXPECT_EQ("CN=Michael Berlin,OU=CSR,OU=Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB),O=GridGermany,C=DE",  // NOLINT
            result);
  user_mapping_->GlobalToLocalUsername("CN=Michael Berlin,OU=CSR,OU=Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB),O=GridGermany,C=DE", &result);  // NOLINT
  EXPECT_EQ("root", result);

  UserCredentials uc;
  user_mapping_->GetGroupnames("root", &uc);
  ASSERT_EQ(2, uc.groups_size());
  EXPECT_EQ("CSR", uc.groups(0));
  EXPECT_EQ("Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB)",
            uc.groups(1));

  // Rewrite file with another entry.
  boost::this_thread::sleep(boost::posix_time::seconds(1));
  ofstream out(gridmap_file_path_.c_str());
  out << "\"/C=DE/O=GridGermany/OU=Dummy OU 1/CN=Dummy Username\" root\n";
  out.close();
  // Wait for reload.
  boost::this_thread::sleep(boost::posix_time::seconds(2));

  // Old entry is no longer visible.
  string dn = "CN=Michael Berlin,OU=CSR,OU=Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB),O=GridGermany,C=DE";  // NOLINT
  user_mapping_->GlobalToLocalUsername(dn, &result);
  EXPECT_EQ(dn, result);
  // New entry can be seen.
  string new_dn = "CN=Dummy Username,OU=Dummy OU 1,O=GridGermany,C=DE";
  user_mapping_->LocalToGlobalUsername("root", &result);
  EXPECT_EQ(new_dn, result);
  user_mapping_->GlobalToLocalUsername(new_dn, &result);
  EXPECT_EQ("root", result);
  UserCredentials uc2;
  user_mapping_->GetGroupnames("root", &uc2);
  ASSERT_EQ(1, uc2.groups_size());
  EXPECT_EQ("Dummy OU 1", uc2.groups(0));
}<commit_msg>client: UserMappingGridmapGlobus unit test: Added check if gridmap was successfully written. Removed initial wait of 1 second because the synchronization of the monitor thread was improved in a previous commit.<commit_after>/*
 * Copyright (c) 2011-2012 by Michael Berlin, Zuse Institute Berlin
 *
 * Licensed under the BSD License, see LICENSE file for details.
 *
 */

#include <gtest/gtest.h>

#include <boost/thread/thread.hpp>
#include <cstdio>
#include <sys/stat.h>
#include <sys/types.h>

#include <fstream>
#include <list>
#include <string>

#include "libxtreemfs/user_mapping.h"
#include "libxtreemfs/user_mapping_gridmap_globus.h"
#include "util/logging.h"
#include "pbrpc/RPC.pb.h"

using namespace std;
using namespace xtreemfs;
using namespace xtreemfs::pbrpc;
using namespace xtreemfs::util;

class UserMappingGridmapGlobusTest : public ::testing::Test {
 protected:
  virtual void SetUp() {
    initialize_logger(LEVEL_WARN);

    gridmap_file_path_ = "gridmap_file_globus";

    // Check if file already exists.
    struct stat stat_buf;
    if (!stat(gridmap_file_path_.c_str(), &stat_buf)) {
      ASSERT_FALSE("The temporary gridmap file does already exist");
    }

    // Create a temporary gridmap file in the working directory.
    ofstream out(gridmap_file_path_.c_str());
    out << "\"/C=DE/O=GridGermany/OU=Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB)/OU=CSR/CN=Michael Berlin\" root\n";
    out.close();
    ASSERT_FALSE(out.fail());

    user_mapping_.reset(new UserMappingGridmapGlobus(
        gridmap_file_path_,
        1));  // Check every second for changes.
    user_mapping_->Start();
  }

  virtual void TearDown() {
    user_mapping_->Stop();

    // Delete gridmap file.
    remove(gridmap_file_path_.c_str());

    shutdown_logger();
    atexit(google::protobuf::ShutdownProtobufLibrary);
  }
  std::string gridmap_file_path_;

  boost::scoped_ptr<UserMapping> user_mapping_;
};

TEST_F(UserMappingGridmapGlobusTest, TestBasicDNAndOUResolving) {
  string result;
  user_mapping_->LocalToGlobalUsername("root", &result);
  EXPECT_EQ("CN=Michael Berlin,OU=CSR,OU=Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB),O=GridGermany,C=DE",  // NOLINT
            result);
  user_mapping_->GlobalToLocalUsername("CN=Michael Berlin,OU=CSR,OU=Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB),O=GridGermany,C=DE",
                                       &result);
  EXPECT_EQ("root",
            result);

  // All OUs will be returned as list of groups of UserCredentials.
  UserCredentials uc;
  user_mapping_->GetGroupnames("root", &uc);
  ASSERT_EQ(2, uc.groups_size());
  EXPECT_EQ("CSR", uc.groups(0));
  EXPECT_EQ("Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB)",
            uc.groups(1));

  // Groups in general do not work and always return "root" or 0.
  user_mapping_->LocalToGlobalGroupname("CSR", &result);
  EXPECT_EQ("root", result);
  user_mapping_->LocalToGlobalGroupname("Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB)", &result);  // NOLINT
  EXPECT_EQ("root", result);
  user_mapping_->GlobalToLocalGroupname("unknowngroup", &result);
  EXPECT_EQ("root", result);

  // List of groups is empty for unknown users.
  UserCredentials uc2;
  user_mapping_->GetGroupnames("nobody", &uc2);
  ASSERT_EQ(0, uc2.groups_size());
}

TEST_F(UserMappingGridmapGlobusTest, GridmapFileReload) {
  string result;
  user_mapping_->LocalToGlobalUsername("root", &result);
  EXPECT_EQ("CN=Michael Berlin,OU=CSR,OU=Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB),O=GridGermany,C=DE",  // NOLINT
            result);
  user_mapping_->GlobalToLocalUsername("CN=Michael Berlin,OU=CSR,OU=Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB),O=GridGermany,C=DE", &result);  // NOLINT
  EXPECT_EQ("root", result);

  UserCredentials uc;
  user_mapping_->GetGroupnames("root", &uc);
  ASSERT_EQ(2, uc.groups_size());
  EXPECT_EQ("CSR", uc.groups(0));
  EXPECT_EQ("Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB)",
            uc.groups(1));

  // Rewrite file with another entry.
  ofstream out(gridmap_file_path_.c_str());
  out << "\"/C=DE/O=GridGermany/OU=Dummy OU 1/CN=Dummy Username\" root\n";
  out.close();
  ASSERT_FALSE(out.fail());
  // Wait for reload.
  boost::this_thread::sleep(boost::posix_time::seconds(2));

  // Old entry is no longer visible.
  string dn = "CN=Michael Berlin,OU=CSR,OU=Konrad-Zuse-Zentrum fuer Informationstechnik Berlin (ZIB),O=GridGermany,C=DE";  // NOLINT
  user_mapping_->GlobalToLocalUsername(dn, &result);
  EXPECT_EQ(dn, result);
  // New entry can be seen.
  string new_dn = "CN=Dummy Username,OU=Dummy OU 1,O=GridGermany,C=DE";
  user_mapping_->LocalToGlobalUsername("root", &result);
  EXPECT_EQ(new_dn, result);
  user_mapping_->GlobalToLocalUsername(new_dn, &result);
  EXPECT_EQ("root", result);
  UserCredentials uc2;
  user_mapping_->GetGroupnames("root", &uc2);
  ASSERT_EQ(1, uc2.groups_size());
  EXPECT_EQ("Dummy OU 1", uc2.groups(0));
}
<|endoftext|>


<commit_before>#include <config.h>

#include <gtest/gtest.h>
#include <primitiv/cpu_device.h>
#include <primitiv/error.h>
#include <primitiv/parameter.h>
#include <primitiv/trainer_impl.h>
#include <test_utils.h>

using std::vector;
using test_utils::vector_match;

namespace primitiv {

class TrainerTest : public testing::Test {
protected:
  CPUDevice dev;
};

TEST_F(TrainerTest, CheckAddParameter) {
  trainers::SGD trainer;
  Parameter param1("param1", {2, 2}, &dev);
  Parameter param2("param2", {2, 2}, &dev);
  Parameter param3("param3", {2, 2}, &dev);

  EXPECT_NO_THROW(trainer.add_parameter(&param1));
  EXPECT_THROW(trainer.add_parameter(&param1), Error);

  EXPECT_NO_THROW(trainer.add_parameter(&param2));
  EXPECT_THROW(trainer.add_parameter(&param1), Error);
  EXPECT_THROW(trainer.add_parameter(&param2), Error);

  EXPECT_NO_THROW(trainer.add_parameter(&param3));
  EXPECT_THROW(trainer.add_parameter(&param1), Error);
  EXPECT_THROW(trainer.add_parameter(&param2), Error);
  EXPECT_THROW(trainer.add_parameter(&param3), Error);

  // Different object but same name
  Parameter param4("param1", {}, &dev);
  EXPECT_THROW(trainer.add_parameter(&param4), Error);
}

TEST_F(TrainerTest, CheckWeightDecay) {
  trainers::SGD trainer;
  trainer.set_weight_decay(.1);

  Parameter param("param1", {2, 2}, {1, 2, 3, 4}, &dev);
  trainer.add_parameter(&param);

  trainer.reset_gradients();
  trainer.update(1);
  EXPECT_TRUE(vector_match(
        vector<float> {.99, 1.98, 2.97, 3.96}, param.value().to_vector()));
  EXPECT_TRUE(vector_match(
        vector<float> {.1, .2, .3, .4}, param.gradient().to_vector()));
}

TEST_F(TrainerTest, CheckGradkentClipping) {
  trainers::SGD trainer;
  trainer.set_gradient_clipping(4);

  Parameter param("param1", {2, 2}, &dev);
  trainer.add_parameter(&param);

  // Norm: 2 = sqrt(4*1^2) ... no clipping
  param.value().reset_by_vector({1, 2, 3, 4});
  param.gradient().reset_by_vector({1, 1, -1, -1});
  trainer.update(1);
  EXPECT_TRUE(vector_match(
        vector<float> {.9, 1.9, 3.1, 4.1}, param.value().to_vector()));
  EXPECT_TRUE(vector_match(
        vector<float> {1, 1, -1, -1}, param.gradient().to_vector()));

  // Norm: 4 = sqrt(4*2^2) ... threshold
  param.value().reset_by_vector({1, 2, 3, 4});
  param.gradient().reset_by_vector({2, 2, -2, -2});
  trainer.update(1);
  EXPECT_TRUE(vector_match(
        vector<float> {.8, 1.8, 3.2, 4.2}, param.value().to_vector()));
  EXPECT_TRUE(vector_match(
        vector<float> {2, 2, -2, -2}, param.gradient().to_vector()));

  // Norm: 6 = sqrt(4*3^2) ... clipping
  param.value().reset_by_vector({1, 2, 3, 4});
  param.gradient().reset_by_vector({3, 3, -3, -3});
  trainer.update(1);
  EXPECT_TRUE(vector_match(
        vector<float> {.8, 1.8, 3.2, 4.2}, param.value().to_vector()));
  EXPECT_TRUE(vector_match(
        vector<float> {2, 2, -2, -2}, param.gradient().to_vector()));
}

}  // namespace primitiv
<commit_msg>fix typo<commit_after>#include <config.h>

#include <gtest/gtest.h>
#include <primitiv/cpu_device.h>
#include <primitiv/error.h>
#include <primitiv/parameter.h>
#include <primitiv/trainer_impl.h>
#include <test_utils.h>

using std::vector;
using test_utils::vector_match;

namespace primitiv {

class TrainerTest : public testing::Test {
protected:
  CPUDevice dev;
};

TEST_F(TrainerTest, CheckAddParameter) {
  trainers::SGD trainer;
  Parameter param1("param1", {2, 2}, &dev);
  Parameter param2("param2", {2, 2}, &dev);
  Parameter param3("param3", {2, 2}, &dev);

  EXPECT_NO_THROW(trainer.add_parameter(&param1));
  EXPECT_THROW(trainer.add_parameter(&param1), Error);

  EXPECT_NO_THROW(trainer.add_parameter(&param2));
  EXPECT_THROW(trainer.add_parameter(&param1), Error);
  EXPECT_THROW(trainer.add_parameter(&param2), Error);

  EXPECT_NO_THROW(trainer.add_parameter(&param3));
  EXPECT_THROW(trainer.add_parameter(&param1), Error);
  EXPECT_THROW(trainer.add_parameter(&param2), Error);
  EXPECT_THROW(trainer.add_parameter(&param3), Error);

  // Different object but same name
  Parameter param4("param1", {}, &dev);
  EXPECT_THROW(trainer.add_parameter(&param4), Error);
}

TEST_F(TrainerTest, CheckWeightDecay) {
  trainers::SGD trainer;
  trainer.set_weight_decay(.1);

  Parameter param("param1", {2, 2}, {1, 2, 3, 4}, &dev);
  trainer.add_parameter(&param);

  trainer.reset_gradients();
  trainer.update(1);
  EXPECT_TRUE(vector_match(
        vector<float> {.99, 1.98, 2.97, 3.96}, param.value().to_vector()));
  EXPECT_TRUE(vector_match(
        vector<float> {.1, .2, .3, .4}, param.gradient().to_vector()));
}

TEST_F(TrainerTest, CheckGradientClipping) {
  trainers::SGD trainer;
  trainer.set_gradient_clipping(4);

  Parameter param("param1", {2, 2}, &dev);
  trainer.add_parameter(&param);

  // Norm: 2 = sqrt(4*1^2) ... no clipping
  param.value().reset_by_vector({1, 2, 3, 4});
  param.gradient().reset_by_vector({1, 1, -1, -1});
  trainer.update(1);
  EXPECT_TRUE(vector_match(
        vector<float> {.9, 1.9, 3.1, 4.1}, param.value().to_vector()));
  EXPECT_TRUE(vector_match(
        vector<float> {1, 1, -1, -1}, param.gradient().to_vector()));

  // Norm: 4 = sqrt(4*2^2) ... threshold
  param.value().reset_by_vector({1, 2, 3, 4});
  param.gradient().reset_by_vector({2, 2, -2, -2});
  trainer.update(1);
  EXPECT_TRUE(vector_match(
        vector<float> {.8, 1.8, 3.2, 4.2}, param.value().to_vector()));
  EXPECT_TRUE(vector_match(
        vector<float> {2, 2, -2, -2}, param.gradient().to_vector()));

  // Norm: 6 = sqrt(4*3^2) ... clipping
  param.value().reset_by_vector({1, 2, 3, 4});
  param.gradient().reset_by_vector({3, 3, -3, -3});
  trainer.update(1);
  EXPECT_TRUE(vector_match(
        vector<float> {.8, 1.8, 3.2, 4.2}, param.value().to_vector()));
  EXPECT_TRUE(vector_match(
        vector<float> {2, 2, -2, -2}, param.gradient().to_vector()));
}

}  // namespace primitiv
<|endoftext|>


<commit_before><commit_msg>Don't forget data from recalibration when error, just don't change frequency<commit_after><|endoftext|>