I made simple StringReverse C project in eclipse-cdt (ubuntu 14.0) and made to .so (shared library). I made test cases for StringReverse C project in eclipse-cdt. Tests runs successfully.
But, these C project and test cases I wants to run in Socket-Client Programming in eclipse-cdt. Suppose, I wants to pass test cases in Client side and that test cases find the C function in Server side. How can I make this..?
references for Server-Client Project :
http://www.cs.cf.ac.uk/Dave/C/node28.html#SECTION002800000000000000000
My StringReverse C code :
Include :
#define LENGTH_OF_STRING 20
#include <stdio.h>
#include <string.h>
#include "error.h"
int StringReverse (char *ptrToDestination, char *ptrToSource);
Source :
#include "StringReverse.h"
#include "error.h"
int StringReverse(char *ptrToDestination,char *ptrToSource)
{
int i,j;
if(NULL == (void *)ptrToSource) {
return ERR_NULL_POINTER;
}
if (LENGTH_OF_STRING <= strlen(ptrToSource)) {
return ERR_STRING_LENGTH;
}
if(NULL == (void *)ptrToDestination) {
return ERR_NULL_POINTER;
}
for(i=0; ptrToSource[i]; i++) {
}
for(i=i-1,j=0; i>=0; i--,j++) {
ptrToDestination[j] = ptrToSource[i];
}
ptrToDestination[j] ='\0';
if(strlen(ptrToSource) != strlen(ptrToDestination)) {
return ERR_STRING_LENGTH;
}
return SUCCESS;
}
My test case :
AllTests.cpp :
#include "CommandLineTestRunner.h"
int main(int ac, char** av)
{
int result = RUN_ALL_TESTS(ac, av);
return result;
}
StringReverse_Test.cpp :
extern "C"
{
#include "StringReverse.h"
#include "error.h"
}
#define COUNT_FOR_NULL 1
#include "TestHarness.h"
#include "TestHarness_c.h"
#include <string.h>
int StatusOfStringReverseFunction;
TEST_GROUP(StringReverse)
{
void setup()
{
/**
* This method is used to initialize the test. It is runs before each test.
*
*/
printf("Tests start here...\n");
}
void teardown()
{
/**
* This method is used to finalized the test. It is runs after each test.
*/
printf("Tests end here...\n");
}
};
/**
* \brief
* I require a test which can check the StringReverse function is capable to return the reverse a string,
* if I assigned string to pointer.
*
* \details
* I require two character pointers for the test.
* char *ptrToSource contains input as string.
* char *ptrToDestination contains the result of StringReverse function.
* I extend StringReverse function to reverse the string assigned by pointer.
* I check the StringReverse function is capable to return the reverse a string or not, using LONGS_EQUAL macro.
*/
TEST(StringReverse, tst_StringReverse_PointerToString)
{
char *ptrToSource = "abcdefghijkl";
char *ptrToDestination = NULL;
CHECK(NULL != ptrToSource);
ptrToDestination = (char *) malloc((strlen(ptrToSource)+COUNT_FOR_NULL)*sizeof(char));
CHECK(NULL != ptrToDestination);
StatusOfStringReverseFunction = StringReverse(ptrToDestination, ptrToSource);
CHECK(strlen(ptrToDestination) == strlen(ptrToSource));
LONGS_EQUAL(SUCCESS, StatusOfStringReverseFunction);
free ((void *)ptrToDestination);
}
/**
* \brief
* I require a test by which can I check that function StringReverse is capable to make the null string is reverse or not.
*
* \details
* I require two character arrays.
* char source[LENGTH_OF_STRING] contains input as a null string.
* char destination[LENGTH_OF_STRING] contains the result of StringReverse function.
* I extend StringReverse function to check the null string is reverse or not.
* I check the StringReverse function is capable to return null string or not, using macro LONGS_EQUAL.
*/
TEST(StringReverse, tst_StringReverse_Null)
{
char source[LENGTH_OF_STRING] = "";
char destination[LENGTH_OF_STRING];
StatusOfStringReverseFunction = StringReverse (destination, source);
LONGS_EQUAL(SUCCESS, StatusOfStringReverseFunction);
}
What is the solution ?