<commit_before>/*=========================================================================

Program:   Medical Imaging & Interaction Toolkit
Language:  C++
Date:      $Date: 2009-02-25 18:43:22 +0100 (Mi, 25 Feb 2009) $
Version:   $Revision: 16010 $

Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.

This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

#include "mitkTimeStamp.h"

#if defined (WIN32) || defined (_WIN32)
#include "mitkWindowsRealTimeClock.h"
#else
#include "mitkLinuxRealTimeClock.h"
#endif

#include "mitkTestingMacros.h"
#include "itkObject.h"

#include <time.h>


/**
 *  test for the class "mitkTimeStamp"
 */
int mitkTimeStampTest(int /* argc */, char* /*argv*/[])
{
  MITK_TEST_BEGIN("TimeStamp")

  // let's create an object of our class  
  
  
  // first test: did this work?
  // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since
  // it makes no sense to continue without an object.
  MITK_TEST_CONDITION_REQUIRED(mitk::TimeStamp::GetInstance() != (0), "Testing GetInstance() of Singleton" );

  itk::Object::Pointer tester = itk::Object::New();
  itk::Object::Pointer tester2 = itk::Object::New();

  //start-tracking sets the reference-time, timestamps are relative to this time
  mitk::TimeStamp::GetInstance()->StartTracking(tester);

  //sleeps for 20 ms
  #if defined (WIN32) || defined (_WIN32)
  Sleep(20);
  #else
  usleep(20000);
  #endif

  double time_elapsed;

  //gets time elapsed since start
  time_elapsed = mitk::TimeStamp::GetInstance()->GetElapsed();

  //elapsed time is not allowed to be too far from 20 ms (+-10ms)-> debugging "destroys" the correct value of course
  MITK_TEST_CONDITION_REQUIRED((time_elapsed-20) > -10 , "Testing if elapsed time is correct (-10)");
  MITK_TEST_CONDITION_REQUIRED((time_elapsed-20) < 10 , "Testing if elapsed time is correct (+10)");

  //second "device" starts tracking
  mitk::TimeStamp::GetInstance()->StartTracking(tester2);
  //first device stops
  mitk::TimeStamp::GetInstance()->StopTracking(tester);

  time_elapsed = mitk::TimeStamp::GetInstance()->GetElapsed();

  //timestamp still has to be valid (tester2 still tracking), and has to be larger than 20ms
  MITK_TEST_CONDITION_REQUIRED( time_elapsed > 15 , "testing if second device is still keeping the TimeStamp \"alive\"");

  mitk::TimeStamp::GetInstance()->StopTracking(tester2);
  time_elapsed = mitk::TimeStamp::GetInstance()->GetElapsed();

  //when all devices have stopped, -1 has to be returned
  MITK_TEST_CONDITION_REQUIRED( time_elapsed == -1 , "testing if -1 is returned after all devices have stopped");

  // always end with this!
  MITK_TEST_END();
<commit_msg>ENH (#1888): test now writes results to console<commit_after>/*=========================================================================

Program:   Medical Imaging & Interaction Toolkit
Language:  C++
Date:      $Date: 2009-02-25 18:43:22 +0100 (Mi, 25 Feb 2009) $
Version:   $Revision: 16010 $

Copyright (c) German Cancer Research Center, Division of Medical and
Biological Informatics. All rights reserved.
See MITKCopyright.txt or http://www.mitk.org/copyright.html for details.

This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

#include "mitkTimeStamp.h"

#if defined (WIN32) || defined (_WIN32)
#include "mitkWindowsRealTimeClock.h"
#else
#include "mitkLinuxRealTimeClock.h"
#endif

#include "mitkTestingMacros.h"
#include "itkObject.h"

//#include <time.h>



/**
 *  test for the class "mitkTimeStamp"
 */
int mitkTimeStampTest(int /* argc */, char* /*argv*/[])
{
  MITK_TEST_BEGIN("TimeStamp")

  // let's create an object of our class  
  
  
  // first test: did this work?
  // using MITK_TEST_CONDITION_REQUIRED makes the test stop after failure, since
  // it makes no sense to continue without an object.
  MITK_TEST_CONDITION_REQUIRED(mitk::TimeStamp::GetInstance() != (0), "Testing GetInstance() of Singleton" );

  itk::Object::Pointer tester = itk::Object::New();
  itk::Object::Pointer tester2 = itk::Object::New();

  //start-tracking sets the reference-time, timestamps are relative to this time
  mitk::TimeStamp::GetInstance()->StartTracking(tester);
  std::cout << "first device has started tracking\n";

  //sleeps for 20 ms
  #if defined (WIN32) || defined (_WIN32)
  Sleep(20);
  #else
  usleep(20000);
  #endif

  std::cout << "supposed to have waited 20ms \n";

  double time_elapsed;

  //gets time elapsed since start
  time_elapsed = mitk::TimeStamp::GetInstance()->GetElapsed();

  std::cout << "have actually waited : " << time_elapsed << "ms \n";

  //elapsed time is not allowed to be too far from 20 ms (+-10ms)-> debugging "destroys" the correct value of course
  MITK_TEST_CONDITION_REQUIRED((time_elapsed-20) > -10 , "Testing if elapsed time is correct (-10)");
  MITK_TEST_CONDITION_REQUIRED((time_elapsed-20) < 10 , "Testing if elapsed time is correct (+10)");

  //second "device" starts tracking
  mitk::TimeStamp::GetInstance()->StartTracking(tester2);
  std::cout << "second device has started\n";
  //first device stops
  mitk::TimeStamp::GetInstance()->StopTracking(tester);
  std::cout << "first device has stopped tracking\n";

  time_elapsed = mitk::TimeStamp::GetInstance()->GetElapsed();

  std::cout << "time elapsed supposed to be greater than 20 ms\n";
  std::cout << time_elapsed << " actually elapsed\n";

  //timestamp still has to be valid (tester2 still tracking), and has to be larger than 20ms
  MITK_TEST_CONDITION_REQUIRED( time_elapsed > 15 , "testing if second device is still keeping the TimeStamp \"alive\"");

  mitk::TimeStamp::GetInstance()->StopTracking(tester2);
  std::cout << "sedond device has stopped tracking\n";
  time_elapsed = mitk::TimeStamp::GetInstance()->GetElapsed();

  //when all devices have stopped, -1 has to be returned
  MITK_TEST_CONDITION_REQUIRED( time_elapsed == -1 , "testing if -1 is returned after all devices have stopped");

  // always end with this!
  MITK_TEST_END();

{'fraction_non_alphanumeric': 0.1625978811607554, 'fraction_numerical': 0.023952095808383235, 'mean_word_length': 4.852650494159928, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5873699', 'n_tokens_mistral': 2128, 'n_tokens_neox': 1962, 'n_words': 624}