/*
 * This file is part of the Owl Positioning System (OwlPS) project.
 * It is subject to the copyright notice and license terms in the
 * COPYRIGHT.t2t file found in the top-level directory of this
 * distribution and at
 *   https://code.lm7.fr/mcy/owlps/src/master/COPYRIGHT.t2t
 * No part of the OwlPS Project, including this file, may be copied,
 * modified, propagated, or distributed except according to the terms
 * contained in the COPYRIGHT.t2t file; the COPYRIGHT.t2t file must be
 * distributed along with this file, either separately or by replacing
 * this notice by the COPYRIGHT.t2t file's contents.
 */

#include <cxxtest/TestSuite.h>

#include "calibrationrequest.hh"

class CalibrationRequest_test: public CxxTest::TestSuite
{
public:

  void test_constructors(void)
  {
    // We can't test the default constructor with two different objects
    // like we usually do because the reception time is initialised by
    // the Request constructor.

    // Copy constructor
    Mobile mobile1 ;
    Timestamp timestamp1 ;
    timestamp1.now() ;
    Request request1(&mobile1, timestamp1) ;
    ReferencePoint referencepoint1 ;
    CalibrationRequest calibrationrequest1(request1, &referencepoint1) ;
    CalibrationRequest calibrationrequest2(calibrationrequest1) ;
    TS_ASSERT_EQUALS(calibrationrequest1, calibrationrequest2) ;

    // Request copy constructor
    /* We must force the request type to be the same in the Request and
     * in the CalibrationRequest, because by default it is set to
     * OWL_REQUEST_UNDEFINED for the Request and to
     * OWL_REQUEST_AUTOCALIBRATION for the CalibrationRequest. */
    request1.set_type(OWL_REQUEST_CALIBRATION) ;
    CalibrationRequest
    calibrationrequest3(request1, &referencepoint1, Direction(1),
                        OWL_REQUEST_CALIBRATION) ;
    TS_ASSERT_EQUALS(request1, calibrationrequest3) ;
  }


  void test_accessors(void)
  {
    // Note: for the moment, I leave the test of get_measurements() and
    // set_measurements() to Request_test.

    // Simple read accessors
    Mobile mobile1 ;
    Timestamp timestamp1 ;
    timestamp1.now() ;
    Request request1(&mobile1, timestamp1) ;
    Direction direction1(1) ;
    ReferencePoint referencepoint1(1,2,3) ;
    CalibrationRequest
    calibrationrequest1(request1, &referencepoint1, direction1) ;
    TS_ASSERT_EQUALS(calibrationrequest1.get_mobile(), &mobile1) ;
    TS_ASSERT_EQUALS(calibrationrequest1.get_time_sent(), timestamp1) ;
    TS_ASSERT_EQUALS(calibrationrequest1.get_direction(), direction1) ;
    TS_ASSERT_EQUALS(calibrationrequest1.get_reference_point(),
                     &referencepoint1) ;

    // Write & read accessors
    Mobile mobile2 ;
    calibrationrequest1.set_mobile(&mobile2) ;
    TS_ASSERT_EQUALS(calibrationrequest1.get_mobile(), &mobile2) ;

    timestamp1 = 42 ;
    calibrationrequest1.set_time_sent(timestamp1) ;
    TS_ASSERT_EQUALS(calibrationrequest1.get_time_sent(), timestamp1) ;

    Direction direction2(2) ;
    calibrationrequest1.set_direction(direction2) ;
    TS_ASSERT_EQUALS(calibrationrequest1.get_direction(), direction2) ;

    ReferencePoint referencepoint2(4,3,2) ;
    calibrationrequest1.set_reference_point(&referencepoint2) ;
    TS_ASSERT_EQUALS(calibrationrequest1.get_reference_point(),
                     &referencepoint2) ;

    calibrationrequest1.clear() ;
    CalibrationRequest calibrationrequest2 ;
    calibrationrequest2.clear() ;
    TS_ASSERT_EQUALS(calibrationrequest1, calibrationrequest2) ;
  }


  void test_operators(void)
  {
    // ==
    Mobile mobile1 ;
    Timestamp timestamp1 ;
    timestamp1.now() ;
    Request request1(&mobile1, timestamp1) ;
    Direction direction1(1) ;
    ReferencePoint referencepoint1 ;
    CalibrationRequest
    calibrationrequest1(request1, &referencepoint1,
                        direction1, OWL_REQUEST_CALIBRATION) ;
    CalibrationRequest
    calibrationrequest2(request1, &referencepoint1,
                        direction1, OWL_REQUEST_CALIBRATION) ;
    TS_ASSERT_EQUALS(calibrationrequest1, calibrationrequest2) ;

    // != and ==
    Direction direction2(2) ;
    calibrationrequest2.set_direction(direction2) ;
    TS_ASSERT(calibrationrequest1 != calibrationrequest2) ;

    calibrationrequest2.set_direction(direction1) ;
    TS_ASSERT_EQUALS(calibrationrequest1, calibrationrequest2) ;

    calibrationrequest2.set_type(OWL_REQUEST_AUTOCALIBRATION) ;
    TS_ASSERT(calibrationrequest1 != calibrationrequest2) ;

    calibrationrequest2.set_type(OWL_REQUEST_CALIBRATION) ;
    TS_ASSERT_EQUALS(calibrationrequest1, calibrationrequest2) ;

    timestamp1.now() ;
    Request request2(&mobile1, timestamp1) ;
    ReferencePoint referencepoint2 ;
    Direction direction3(3) ;
    CalibrationRequest
    calibrationrequest3(request2, &referencepoint2,
                        direction3, OWL_REQUEST_AUTOCALIBRATION) ;
    TS_ASSERT(calibrationrequest1 != calibrationrequest3) ;

    // =
    calibrationrequest2 = calibrationrequest3 ;
    TS_ASSERT_EQUALS(calibrationrequest2, calibrationrequest3) ;
  }

} ;
