Example #1
0
void TestSTL::test_adaptors()
{
	/**
	*  bind1st function template: constructs an unary function object from a binary function object,
	*  by binding the first parameter to a certain value.
	*/

	int array[] = { 1, -99, 2, -100 };
	int arraySize = sizeof(array)/sizeof(array[0]);

	std::vector<int> vec1(array, array + arraySize);
	std::vector<int>::iterator newEnd;
	//Calls std::less(0, element). If less(0,element) returns true => remove that element
	newEnd = std::remove_if(vec1.begin(), vec1.end(), bind1st(std::less<int>(), 0));

	for(std::vector<int>::iterator it = vec1.begin(); it != newEnd; ++it)
	{
		TESTIFY_ASSERT(*it < 0);
	}

	/**
	*  bind2nd function template: constructs an unary function object from a binary function object,
	*  by binding the second parameter to a certain value.
	*/
	std::vector<int> vec2(array, array + arraySize);

	//Calls std::greater(element, 0). If element greater(element, 0) returns true => remove that element
	newEnd = std::remove_if(vec2.begin(), vec2.end(), bind2nd(std::greater<int>(), 0));
	for(std::vector<int>::iterator it = vec2.begin(); it != newEnd; ++it)
	{
		TESTIFY_ASSERT(*it < 0);
	}
}
Example #2
0
/**
 * Tests to insert an element at a bad index.
 */
void testBadInsert()
{
	int listView = maWidgetCreate( MAW_LIST_VIEW );
	TESTIFY_ASSERT( listView > 0 );

	int firstChild = maWidgetCreate( MAW_LABEL );
	TESTIFY_ASSERT( firstChild > 0 );
	TESTIFY_ASSERT_EQUAL( maWidgetInsertChild( listView, firstChild, -515 ), MAW_RES_INVALID_INDEX );

	maWidgetDestroy( listView );
}
Example #3
0
/**
 * Tests to insert an element at the end of a list.
 */
void testInsertLast()
{
	int listView = maWidgetCreate( MAW_LIST_VIEW );
	TESTIFY_ASSERT( listView > 0 );

	int firstChild = maWidgetCreate( MAW_LABEL );
	TESTIFY_ASSERT( firstChild > 0 );
	TESTIFY_ASSERT_EQUAL( maWidgetInsertChild( listView, firstChild, 0 ), MAW_RES_OK );

	int secondChild = maWidgetCreate( MAW_LABEL );
	TESTIFY_ASSERT( secondChild > 0 );
	TESTIFY_ASSERT_EQUAL( maWidgetInsertChild( listView, secondChild, -1 ), MAW_RES_OK );

	maWidgetDestroy( listView );
}
    /**
     * The purpose of this test is to test the creation and destruction
     * of a screen.
     */
    void createWidget(const char *type)
    {
        int widgetHandle = maWidgetCreate( type );
        TESTIFY_ASSERT_NOT_EQUAL( widgetHandle, MAW_RES_INVALID_TYPE_NAME );
        TESTIFY_ASSERT( widgetHandle >= 0 );

        int destroyStatus = maWidgetDestroy( widgetHandle );
        TESTIFY_ASSERT_EQUAL( destroyStatus, MAW_RES_OK );
    }
Example #5
0
void
WidgetTest::testTearDown(void)
{
	TESTIFY_ASSERT( m_testWidgetHandle >= 0 );
	TESTIFY_ASSERT_EQUAL( maWidgetDestroy( m_testWidgetHandle ), MAW_RES_OK );
	m_testWidgetHandle = -1;

	// Keep default behavior
	Testify::TestCase::testTearDown( );
}
Example #6
0
void
WidgetTest::testSetUp(void)
{
	// Keep default behavior
	Testify::TestCase::testSetUp( );

	MAWidgetHandle widgetHandle = maWidgetCreate( m_type );
	TESTIFY_ASSERT( widgetHandle >= 0 );
	m_testWidgetHandle = widgetHandle;
}
Example #7
0
void TestSTL::predicate_example()
{

	// unary predicate example
	int array[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
	int sizeArray = sizeof(array)/sizeof(array[0]);
	std::vector<int> myVector(array, array + sizeArray); //fill a vector

	/**
	* std::countf_if algorithm: counts the number of elements that satisfy the
	* condition we supply (e.g isEven, isNegative)
	*/

	int res = std::count_if(myVector.begin(), myVector.end(), NumericUtilities::isEven);		//returns the how many numbers are even
	TESTIFY_ASSERT(res == 6);

	res = std::count_if(myVector.begin(), myVector.end(), NumericUtilities::isNegative);		//returns how many numbers are negative
	TESTIFY_ASSERT( res == 0);

	//binary predicates:

	Employee staff[] = { Employee(3, "Jonny"), Employee(2, "Bob"), Employee(20, "Filomela")};

	int staffSize = sizeof(staff)/sizeof(staff[0]);
	std::vector<Employee> myStaff( staff, staff + staffSize);		//fill a vector with these employees

	/**
	* std::sort algorithm: sorts the elements, from a range, into ascending order
	*/

	//sort by experience
	std::sort(myStaff.begin(), myStaff.end(), lessExperience); //supply a binary predicate for comparing employees

	TESTIFY_ASSERT( myStaff[0].getExperience() == 2);
	TESTIFY_ASSERT( myStaff[1].getExperience() == 3);
	TESTIFY_ASSERT( myStaff[2].getExperience() == 20);
}
Example #8
0
	/**
	 * Tests to add and remove children from the layout.
	 */
	void testAddAndRemoveChildren()
	{
		MAWidgetHandle children[ 10 ];
		for(int i = 0; i < NUM_CHILDREN; i++)
		{
			children[ i ] = maWidgetCreate( MAW_LABEL );
			TESTIFY_ASSERT( children[ i ] >= 0 );

			TESTIFY_ASSERT_EQUAL( maWidgetAddChild( getTestWidgetHandle( ), children[ i ] ), MAW_RES_OK );
		}

		for(int i = 0; i < NUM_CHILDREN; i++)
		{
			TESTIFY_ASSERT_EQUAL( maWidgetRemoveChild( children[ i ] ), MAW_RES_OK );
			TESTIFY_ASSERT_EQUAL( maWidgetDestroy( children[ i ] ), MAW_RES_OK );
		}
	}
Example #9
0
void TestSTL::example_iterators()
{
	/**
	*  Input iterators: allow only reading elements from a sequence and moving forward, one step,
	*  using operator++. The elements are read with operator*.
	*  Provides also operator== and operator!=.
	*  An input iterator implemented in STL is for example the one provided by std::istream.
	*/

	/**
	*  Output iterators: allow only writing elements from a sequence and only moving forward, one step,
	*  using operator++. They elements are written with operator*.
	*  Provides also operator== and operator!=.
	*  An input iterator implemented in STL is for example the one provided by std::ostream.
	*/

	/**
	*  Forward iterators: allow reading and writing elements from a sequence. Only moving forward, one step,
	*  using operator++ is possible. They elements are read and written with operator*.
	*  Provides also operator== and operator!=.
	*  An input iterator implemented in STL is for example the one provided by std::ostream.
	*/

	/**
	*  Bidirectional iterators: allow reading and writing elements from a sequence. Allows moving forward and backward,
	*  one step,using operator++/operator--. Their elements are read and written with operator*.
	*  Provides also operator== and operator!=.
	*  An input iterator implemented in STL is for example the ones provided by list, multiset, map, multimap.
	*/

	int sArray[] = { 0, 11, 22, 33, 44 };
	int sArraySize = sizeof(sArray)/sizeof(sArray[0]);
	std::list<int> myList(sArray, sArray + sArraySize);

	//create an bidirectional iterator
	std::list<int>::iterator iter;
	iter = myList.begin();
	//read
	TESTIFY_ASSERT( 0 == *iter );

	//write
	*iter = 99;
//
//	operator++
	iter++;
    TESTIFY_ASSERT( 11 ==  *iter );

//    operator--
    --iter;
    TESTIFY_ASSERT( 99 ==  *iter );

    /**
	*  Random access iterators: allows all operations a normal pointer does: add and subtract integral values,
	*  move forward and backward, one or more steps, use operator[] on it, subtract one iterator from another.
	*  It overloads operator<, operator>, operator==, operator!=.
	*  An input iterator implemented in STL is for example the ones provided by vector, deque, string.
	*/

    std::vector<int> myVector(sArray, sArray + sArraySize);	//myVector contains now: 0, 11, 22, 33, 44

    //create an random iterator
	std::vector<int>::iterator randomAcessIter;
	randomAcessIter = myVector.begin();

	//read
	TESTIFY_ASSERT( 0 == *randomAcessIter );

	//write
	*randomAcessIter = 99;										//myVector contains now: 99, 11, 22, 33, 44

	//operator++
	randomAcessIter++;
	TESTIFY_ASSERT( 11 ==  *randomAcessIter );

	//operator--
	--randomAcessIter;
	TESTIFY_ASSERT( 99 ==  *randomAcessIter );

	//move two steps forward
	randomAcessIter += 2;
	TESTIFY_ASSERT( 22 ==  *randomAcessIter );

	std::vector<int>::iterator start = myVector.begin();
	TESTIFY_ASSERT( start != randomAcessIter );

	//operator <
	for( std::vector<int>::iterator it = start; it < (myVector.end() - 1); ++it)
	{
		*it = *(it + 1);
	}
	TESTIFY_ASSERT( 11 == myVector[0] &&
					22 == myVector[1] &&
					33 == myVector[2] &&
					44 == myVector[3]);
}