Beispiel #1
0
LinkList &LinkList::operator=(const LinkList &ll) throw(bad_alloc)
{
	if (this == &ll)
		return *this;
	Clean();
	MakeCopy(ll);
}
Beispiel #2
0
LinkList::LinkList(const LinkList &ll) throw(std::bad_alloc)
	: head_(0)
{
	MakeCopy(ll);
}
int16_t Test_RemoveTimer()
{

    int rep = 1000;				/*number of times that the timer remove
								 *function is being simulated*/

    /*Creating random timers*/

    for(int i = 0; i < NUM_TIMER; i++)
    {
        s_all_timers[i].Handler = DummyHandler;
        s_all_timers[i].auto_repeat = rand() % 2;
        s_all_timers[i].count = rand();
        s_all_timers[i].enable = rand() % 2;
        s_all_timers[i].id = i;
        s_all_timers[i].load_count = rand();
    }

    while(rep)
    {
        u16 removed_id = RAND_ID;
        MakeCopy();
        RemoveTimer(removed_id);

        /*Checking whether the intended timer was removed or not*/

        if(	(s_all_timers[removed_id].Handler == NULL) &&
                (s_all_timers[removed_id].auto_repeat == 0) &&
                (s_all_timers[removed_id].count == 0) &&
                (s_all_timers[removed_id].enable == 0) &&
                (s_all_timers[removed_id].id == 0xFF) &&
                (s_all_timers[removed_id].load_count == 0))
        {

            /*Checking for the other values as to if they have been modified
             *or not*/

            for(int a = 0; a < removed_id; a++)
            {
                if(	(s_all_timers[a].Handler != Temp_Copy[a].Handler) ||
                        (s_all_timers[a].auto_repeat != Temp_Copy[a].auto_repeat) ||
                        (s_all_timers[a].count != Temp_Copy[a].count) ||
                        (s_all_timers[a].enable != Temp_Copy[a].enable) ||
                        (s_all_timers[a].id != Temp_Copy[a].id) ||
                        (s_all_timers[a].load_count != Temp_Copy[a].load_count))
                {

                    xil_printf("Failure in Remove Timer function timers other"
                               " than the intended timer are effected");
                    return ENDO_FAILURE;
                }
            }
            for(int a = (removed_id+1); a < NUM_TIMER; a++)
            {
                if(	(s_all_timers[a].Handler != Temp_Copy[a].Handler) ||
                        (s_all_timers[a].auto_repeat != Temp_Copy[a].auto_repeat) ||
                        (s_all_timers[a].count != Temp_Copy[a].count) ||
                        (s_all_timers[a].enable != Temp_Copy[a].enable) ||
                        (s_all_timers[a].id != Temp_Copy[a].id) ||
                        (s_all_timers[a].load_count != Temp_Copy[a].load_count))
                {

                    xil_printf("Failure in Remove Timer function timers other"
                               " than the intended timer are effected");
                    return ENDO_FAILURE;
                }
            }

            /*test for cases where the passed id is more than max number*/

            removed_id = rand() + NUM_TIMER;
            exp = 0;
            RemoveTimer(removed_id);
            if((rep == 1) && (exp == 1))
            {
                return ENDO_SUCCESS;
            }
        }
        rep--;
    }

    xil_printf("Failure in Remove Timer Function was not able to remove the intended"
               " timer\n\r");
    return ENDO_FAILURE;
}
/*****************************************************************************
	 * Makes a test case where the timer is created 1000 times for statistical
	 * accuracy checks if the other timers are also effected by this function
	 * also checks whether the correct timer with the correct ID is created
	 * @param	None.
	 *
	 * @return	int16_t.
	 *
	 * @note	None.
	 *
****************************************************************************/
int16_t Test_CreateTimer()
{
    /*Creating a simulation for random add and delete the timers*/

    int no_of_repeatations = 1000;
    EndoInitTimer();
    while(no_of_repeatations)
    {

        is_soft_timer_init = rand() % 2;
        u16 is_repeat_on = rand() % 2;
        int remtimer = rand() % 2;
        u16 count = rand();
        CreateTimer(count, is_repeat_on, DummyHandler);
        if(remtimer)
        {
            int random_id = RAND_ID;
            RemoveTimer(random_id);
        }
        no_of_repeatations--;
    }
    no_of_repeatations = 1000;
    while(no_of_repeatations)
    {
        u16 returned_id;
        u16 is_repeat_on = rand() % 2;
        u16 count = rand();
        MakeCopy();
        returned_id = CreateTimer(count, is_repeat_on, DummyHandler);

        /*Note that checking for rid = 0xFFFF is done for exception
         * handling in this case it happens when the given id exceeds the
         *  MAX number of timers*/

        if(returned_id == 0XFFFF)
        {
            u16 i=0;

            /*Search for the first unused  timer*/

            while(i < NUM_TIMER)
            {
                if(s_all_timers[i].id == 0xFF)
                {
                    xil_printf("The timers are not full yet create timer"
                               " function behaving abnormally\n\r");
                    return ENDO_FAILURE;
                }

                i++;
            }

            EndoInitTimer();
            MakeCopy();

        }

        if(!((0 <= returned_id) && (returned_id < NUM_TIMER)))
        {
            if(returned_id != 0XFFFF)
            {
                xil_printf("The return ID for the create timer function not"
                           " working properly\n\r");
                return ENDO_FAILURE;
            }
        }

        /*Check to see if the values have been properly set or not for that
         *first starting the case whether the returned ID is a valid ID or not
         *particular ID*/

        if(returned_id != 0XFFFF)
        {
            if(	(s_all_timers[returned_id].Handler != DummyHandler) ||
                    (s_all_timers[returned_id].auto_repeat != is_repeat_on) ||
                    (s_all_timers[returned_id].count != count) ||
                    (s_all_timers[returned_id].enable != 1) ||
                    (s_all_timers[returned_id].id != returned_id) ||
                    (s_all_timers[returned_id].load_count != count))
            {

                xil_printf("Values not getting initialized "
                           "properly for create timer function\n\r");

                return ENDO_FAILURE;
            }
        }

        /*Checking to see if the other ids were effected by the function use*/

        if(returned_id != 0XFFFF)
        {
            int i = NUM_TIMER - 1;
            while(i != returned_id && i >= 0)
            {
                if(	(s_all_timers[i].Handler != Temp_Copy[i].Handler) ||
                        (s_all_timers[i].auto_repeat != Temp_Copy[i].auto_repeat)||
                        (s_all_timers[i].count != Temp_Copy[i].count) ||
                        (s_all_timers[i].enable != Temp_Copy[i].enable) ||
                        (s_all_timers[i].id != Temp_Copy[i].id) ||
                        (s_all_timers[i].load_count != Temp_Copy[i].load_count))
                {

                    xil_printf("Failure other timers getting effected by Create"
                               " timer function\n\r");

                    return ENDO_FAILURE;
                }
                i--;
            }
        }

        if(no_of_repeatations == 1)
        {
            return ENDO_SUCCESS;
        }

        no_of_repeatations--;
    }



    xil_printf("Unknown failure in Create Timer Function\n\r");
    return ENDO_FAILURE;
}
/*****************************************************************************
	 * Makes a test case where the timer tick every 1 Ms can be checked
	 * mostly checks the callback dummy function for accuracy in repeating
	 * and non repeating timers.
	 * @param	None.
	 *
	 * @return	int16_t.
	 *
	 * @note	None.
	 *
****************************************************************************/
int16_t Test_TimerTickEvery1Ms(void)
{

    /*Create the timers randomly*/

    int no_of_repeatations = 1000;
    is_soft_timer_init = rand() % 2;
    while(no_of_repeatations)
    {


        u16 isrepeaton = rand() % 2;
        int remtimer = rand() % 2;
        u16 count = rand();
        CreateTimer(count, isrepeaton, DummyHandler);
        if(remtimer)
        {
            int Random_ID = RAND_ID;
            RemoveTimer(Random_ID);
        }
        no_of_repeatations--;
    }

    /*Start the timers*/


    MakeCopy();    /* make a copy of the initial state for checking purposes.*/
    for(int a=0; a < NUM_TIMER; a++ )
    {
        call_listened[a] = 0;              /*Initializing the number of
												 times the call has been made
												 to the callback function*/
    }

    static double max = 0;
    for(int a=0; a < NUM_TIMER; a++ )
    {
        if((max <= s_all_timers[a].count) && (s_all_timers[a].enable) )
        {
            max = s_all_timers[a].count;
        }
    }
    max *= 4;
    /*Start the timer tick function*/
    while(max)
    {
        TimerTickEvery1Ms();
        max--;
    }
    /*Starting the testing*/

    for(int16_t i=0; i<NUM_TIMER;  i++)
    {

        /*Check whether it doesn't start the non enabled timers
         This case is checked for all the non enabled timers
         Checks whether the default values for the non enabled timers have
         been set properly or not*/

        if(s_all_timers[i].enable == 0)
        {

            if(	s_all_timers[i].Handler != NULL ||
                    s_all_timers[i].auto_repeat != 0 ||
                    s_all_timers[i].count != 0 || s_all_timers[i].id != 0xFF ||
                    s_all_timers[i].load_count !=0)
            {
                xil_printf(" Failure function started the non intended"
                           "/enabled timers \n\r");
                return ENDO_FAILURE;
            }
        }


        /***********************************************/


        if((s_all_timers[i].auto_repeat) && (s_all_timers[i].Handler != NULL))
        {

            /*Checking whether the repeating timers call their callback only
             *once or less if true then the test fails checked by the
             *once  Call_Listened variable for
             *that ID*/

            if((call_listened[i] == 0) || (call_listened[i] == 1) ||
                    (s_all_timers[i].Handler == NULL))
            {
                xil_printf(" Failure the callback for repeating timers"
                           " is not called or called only once (Repeating"
                           " timer behaving as non repeating)\n\r");
                return ENDO_FAILURE;
            }

        }

        /*Non repeating timers */

        /*Checking whether the non-repeating timers call their callback only
        once if false then test fails also checks that the timer has been
         removed after its completion which makes them go to
          their default values*/

        if(!(s_all_timers[i].auto_repeat))
        {

            if((call_listened[i] == 0) || (call_listened[i] > 1) ||
                    (s_all_timers[i].Handler != NULL) ||
                    (s_all_timers[i].auto_repeat != 0) ||
                    (s_all_timers[i].count != 0) ||
                    (s_all_timers[i].enable != 0) ||
                    (s_all_timers[i].id != 0xFF) ||
                    (s_all_timers[i].load_count !=0) )

            {
                xil_printf(" Failure non repeating timers not working"
                           " callback not even called once or timer "
                           "not deleted after getting over\n\r");

                return ENDO_FAILURE;
            }
        }
    }


    return ENDO_SUCCESS;
}
dNodeInfo* dNodeInfo::MetaFunction(dScene* const world) const
{
	return MakeCopy();
}