Ejemplo n.º 1
0
   void testPresencePackageParser()
      {
         const char *package = 
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
            "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" entity=\"[email protected]\">\n"
            "<tuple id=\"1\">\n"
            "<status>\n"
            "<basic>open</basic>\n"
            "</status>\n"
            "<contact>tel:+0123456789</contact>\n"
            "</tuple>\n"
            "</presence>\n"
            ;
       
         SipPresenceEvent body("*****@*****.**", package);

         UtlString bodyString;
         int bodyLength;
       
         body.getBytes(&bodyString, &bodyLength);
         //printf("body = \n%s\n", bodyString.data());
       
         CPPUNIT_ASSERT(strcmp(bodyString.data(), package) == 0);

         int otherLength = body.getLength();
         CPPUNIT_ASSERT_EQUAL_MESSAGE("content length is not equal",
                                      bodyLength, otherLength);
      }
Ejemplo n.º 2
0
void CloneObjectsTest::testCloneString() {
    VMString* orig = GetUniverse()->NewString("foobar");
    VMString* clone = orig->Clone();

    CPPUNIT_ASSERT((intptr_t)orig != (intptr_t)clone);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("class differs!!", orig->GetClass(),
            clone->GetClass());
    CPPUNIT_ASSERT_EQUAL_MESSAGE("objectSize differs!!", orig->GetObjectSize(),
            clone->GetObjectSize());
    //CPPUNIT_ASSERT_EQUAL_MESSAGE("numberOfFields differs!!", orig->numberOfFields, clone->numberOfFields);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("string differs!!!", orig->GetStdString(), clone->GetStdString());
    //CPPUNIT_ASSERT_MESSAGE("internal string was not copied", (intptr_t)orig->chars != (intptr_t)clone->chars);
    orig->chars[0] = 'm';
    CPPUNIT_ASSERT_MESSAGE("string differs!!!", orig->GetStdString() != clone->GetStdString());

}
Ejemplo n.º 3
0
void ZipTest::test_replaceFile_WhenFileNotExistsOnFileSystem(){
    bool expected = false;
    std::string zipFileName = tempFolder + "/" + zipFileFor_deleteAndReplace;

    createFolder(zipFileName);
    copyFile(zipFileFor_deleteAndReplace, zipFileName);

    zip->open(zipFileName, OpenFlags::OpenExisting);
    std::string fileToReplace = folderNameInsideZip + "/file2.txt";
    bool actual = zip->replaceFile(notExistingFileName, fileToReplace);
    zip->close();

    CPPUNIT_ASSERT_EQUAL(expected, actual);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("count", 7, numFilesInZip(zipFileName));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("contains", false, containsFile(zipFileName, fileToReplace));
}
Ejemplo n.º 4
0
void KDTreeTestCase::checkInsert() {

    //this vector can't possibly be in the array because it
    //has a value above the _MAX_PT_VAL_
    std::vector<double> arr;
    arr.push_back(_MAX_PT_VAL_ * 2);
    for (int i=1; i<_N_; i++) {
        arr.push_back(i);
    }

    Point<_N_, double, std::string> pt(arr, "sup");

    size_t n = tree->size() + 1;
    tree->insert(pt);

    CPPUNIT_ASSERT_EQUAL_MESSAGE("check if size increased when adding a point",
            n, tree->size());

    CPPUNIT_ASSERT_MESSAGE("check if tree can insert point",
            tree->contains(pt));

    Point<_N_, double, std::string> pt_b(arr, "sup");
    emptyTree->insert(pt);

    CPPUNIT_ASSERT_MESSAGE("check inserting point into an empty tree",
            emptyTree->contains(pt));
}
Ejemplo n.º 5
0
void NutClientTest::test_stringset_to_strarr()
{
	std::set<std::string> strset;
	strset.insert("test");
	strset.insert("hello");
	strset.insert("world");

	strarr arr = stringset_to_strarr(strset);
	CPPUNIT_ASSERT_MESSAGE("stringset_to_strarr(...) result is null", arr!=NULL);

	std::set<std::string> res;

	char** ptr = arr;
	while(*ptr!=NULL)
	{
		res.insert(std::string(*ptr));
		ptr++;
	}

	CPPUNIT_ASSERT_EQUAL_MESSAGE("stringset_to_strarr(...) result has not 3 items", (size_t)3, res.size());
	CPPUNIT_ASSERT_MESSAGE("stringset_to_strarr(...) result has not item \"test\"", res.find("test")!=res.end());
	CPPUNIT_ASSERT_MESSAGE("stringset_to_strarr(...) result has not item \"hello\"", res.find("hello")!=res.end());
	CPPUNIT_ASSERT_MESSAGE("stringset_to_strarr(...) result has not item \"world\"", res.find("world")!=res.end());
	
	strarr_free(arr);
}
Ejemplo n.º 6
0
void ClusterAStarFactoryTest::newClusterAStarShouldReturnANewInstanceOfClusterAStar()
{	
	ClusterAStarFactory caf;
	ClusterAStar* ac = dynamic_cast<ClusterAStar*>(caf.newClusterAStar());
	CPPUNIT_ASSERT_EQUAL_MESSAGE("factory failed to return an instance of ClusterAStar", true, ac!=0);
	delete ac;
}
Ejemplo n.º 7
0
    void testCreators()
    {
        PtCallEvent* pTempPtCallEvent;
        PtCallEvent* pTempPtCallEvent_1;
        PtCallEvent::PtEventId*   pTempPtEventId;

        pTempPtCallEvent = new PtCallEvent();
        pTempPtEventId = new PtEvent::PtEventId(PtEvent::PROVIDER_IN_SERVICE);
        pTempPtCallEvent->getId(*pTempPtEventId);
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Should be invalid event", PtEvent::EVENT_INVALID, *pTempPtEventId);
        delete pTempPtEventId;
        delete pTempPtCallEvent;
                                                                                
        pTempPtCallEvent = new PtCallEvent(PtEvent::PROVIDER_IN_SERVICE);
        // mCallId is protected and no accessor method my be for better encapsulation
        // CPPUNIT_ASSERT_EQUAL_MESSAGE("callid label", 0, 
        //        strcmp(pTempPtCallEvent->mCallId, "callId"));
        delete pTempPtCallEvent;
                                                                                
        pTempPtCallEvent = new PtCallEvent(PtEvent::CALL_INVALID);
        pTempPtCallEvent_1 = new PtCallEvent(*pTempPtCallEvent);
        // mCallId is protected and no accessor method my be for better encapsulation
        // CPPUNIT_ASSERT_EQUAL_MESSAGE("callid label", 0, 
        //        strcmp(pTempPtCallEvent->mCallId, "callId"));
        delete pTempPtCallEvent;
        delete pTempPtCallEvent_1;
    }
Ejemplo n.º 8
0
void ZipTest::test_deleteFolder() {
    bool expected = true;
    std::string zipFileName = tempFolder + "/" + zipFileFor_deleteAndReplace;

    createFolder(zipFileName);
    copyFile(zipFileFor_deleteAndReplace, zipFileName);

    zip->open(zipFileName, OpenFlags::OpenExisting);
    std::string folderToDelete = folderNameInsideZip + "/folder1";
    bool actual = zip->deleteFolder(folderToDelete);
    zip->close();

    CPPUNIT_ASSERT_EQUAL(expected, actual);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("count", 5, numFilesInZip(zipFileName));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("contains", false, containsFolder(zipFileName, folderToDelete));
}
    void check_Advancing_Operator_IntList()
    {
        UtlSortedListIterator slIter(intList) ; 

        for (int i = 0 ; i < intListCount ; i++)
        {
            UtlContainable* uNext = slIter() ; 
            CPPUNIT_ASSERT_EQUAL_MESSAGE(testDataForIntList[i].testDescription, \
               testDataForIntList[i].item, uNext) ; 
        }
        // Verify that the iterator returns null after the last advancing has been called
        UtlContainable* uNext = slIter() ; 
       
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Null is returned after all items have been " \
            "advanced ", (void*)NULL, (void*)uNext) ; 
    } 
Ejemplo n.º 10
0
void FilesystemTest::testFile() {
#ifdef _WIN32
	const string test_file = test_dir->Path() + "\\test-file.txt";
#else
	const string test_file = test_dir->Path() + "/test-file";
#endif

	CPPUNIT_ASSERT_MESSAGE(
		"inexistant file is file",
		!is_file(test_file));
	CPPUNIT_ASSERT_EQUAL_MESSAGE(
		"mtime of inexistant file should be zero",
		time_t(0), file_mtime(test_file));
	CPPUNIT_ASSERT_MESSAGE(
		"inexistant file is a directory",
		!is_dir(test_file));

	{ // create file
		ofstream file(test_file);
		file << "hello" << endl;
	}
	time_t now = time(nullptr);
	CPPUNIT_ASSERT_MESSAGE(
		"existing file not a file",
		is_file(test_file));
	CPPUNIT_ASSERT_MESSAGE(
		"mtime of existing file should be somewhere around now",
		// let's assume that creating the file takes less than five seconds
		abs(now - file_mtime(test_file) < 5));
	CPPUNIT_ASSERT_MESSAGE(
		"regular file is a directory",
		!is_dir(test_file));

	CPPUNIT_ASSERT_MESSAGE(
		"failed to remove test file",
		remove_file(test_file));

	CPPUNIT_ASSERT_MESSAGE(
		"removed file is still a file",
		!is_file(test_file));
	CPPUNIT_ASSERT_EQUAL_MESSAGE(
		"mtime of removed file should be zero",
		time_t(0), file_mtime(test_file));
	CPPUNIT_ASSERT_MESSAGE(
		"removed file became a directory",
		!is_dir(test_file));
}
void AnnotatedHierarchicalAStarTest::logStatsShouldRecordAllMetricsToStatsCollection()
{
	statCollection sc;
	Map *m = new Map(maplocation.c_str());
	AnnotatedClusterAbstraction* aca = new AnnotatedClusterAbstraction(m, new AnnotatedAStar(), TESTCLUSTERSIZE);
	AnnotatedClusterFactory* acfactory = new AnnotatedClusterFactory();
	aca->buildClusters(acfactory);
	aca->buildEntrances();

	node *start = aca->getNodeFromMap(1,5);
	node* goal = aca->getNodeFromMap(16,8);
	
	int capability = kGround;
	int size = 1;
	
	ahastar->setGraphAbstraction(aca);
	ahastar->setClearance(size);
	ahastar->setCapability(capability);
		
	path* p = ahastar->getPath(aca, start, goal);
	assert(p != 0);
	
	ahastar->logFinalStats(&sc);
	
	statValue result;
	int lookupResult = sc.lookupStat("nodesExpanded", ahastar->getName() , result);
	CPPUNIT_ASSERT_MESSAGE("couldn't find nodesExpanded metric in statsCollection", lookupResult != -1);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("nodesExpanded metric in statsCollection doesn't match expected result", (long)ahastar->getNodesExpanded(), result.lval);

	lookupResult = sc.lookupStat("nodesTouched", ahastar->getName() , result);
	CPPUNIT_ASSERT_MESSAGE("couldn't find nodesTouched metric in statsCollection", lookupResult != -1);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("nodesTouched metric in statsCollection doesn't match expected result", (long)ahastar->getNodesTouched(), result.lval);

	lookupResult = sc.lookupStat("peakMemory", ahastar->getName() , result);
	CPPUNIT_ASSERT_MESSAGE("couldn't find peakMemory metric in statsCollection", lookupResult != -1);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("peakMemory metric in statsCollection doesn't match expected result", (long)ahastar->getPeakMemory(), result.lval);

	lookupResult = sc.lookupStat("searchTime", ahastar->getName() , result);
	CPPUNIT_ASSERT_MESSAGE("couldn't find searchTime metric in statsCollection", lookupResult != -1);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("searchTime metric in statsCollection doesn't match expected result", (double)ahastar->getSearchTime(), result.fval);

	lookupResult = sc.lookupStat("insNodesExpanded", ahastar->getName() , result);
	CPPUNIT_ASSERT_MESSAGE("couldn't find nodesExpanded metric in statsCollection", lookupResult != -1);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("nodesExpanded metric in statsCollection doesn't match expected result", (long)ahastar->getInsertNodesExpanded(), result.lval);

	lookupResult = sc.lookupStat("insNodesTouched", ahastar->getName() , result);
	CPPUNIT_ASSERT_MESSAGE("couldn't find nodesTouched metric in statsCollection", lookupResult != -1);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("nodesTouched metric in statsCollection doesn't match expected result", (long)ahastar->getInsertNodesTouched(), result.lval);

	lookupResult = sc.lookupStat("insPeakMemory", ahastar->getName() , result);
	CPPUNIT_ASSERT_MESSAGE("couldn't find peakMemory metric in statsCollection", lookupResult != -1);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("peakMemory metric in statsCollection doesn't match expected result", (long)ahastar->getInsertPeakMemory(), result.lval);

	lookupResult = sc.lookupStat("insSearchTime", ahastar->getName() , result);
	CPPUNIT_ASSERT_MESSAGE("couldn't find searchTime metric in statsCollection", lookupResult != -1);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("searchTime metric in statsCollection doesn't match expected result", (double)ahastar->getInsertSearchTime(), result.fval);
}
Ejemplo n.º 12
0
void ZipTest::test_addFile_Content_WithSubFoldersFileName() {
    std::vector<unsigned char> content;
    content.push_back('a');
    content.push_back('z');
    content.push_back('7');

    bool expected = true;
    std::string zipFileName = tempFolder + "/" + zipFile;

    zip->open(zipFileName);
    bool actual = zip->addFile("folder/subfolder/test.txt", content);
    zip->close();

    CPPUNIT_ASSERT_EQUAL(expected, actual);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("count", 1, numFilesInZip(zipFileName));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("contains", true, containsFile(zipFileName, "folder/subfolder/test.txt"));
}
Ejemplo n.º 13
0
void ClusterAStarTest::getPathReturnNullWhenStartOrGoalNull()
{	
	HPAClusterAbstraction hpamap(new Map(maplocation.c_str()), new HPAClusterFactory(), 
		new ClusterNodeFactory(), new EdgeFactory());
	hpamap.setClusterSize(TESTCLUSTERSIZE);

	ClusterAStar castar;
	castar.setGraphAbstraction(&hpamap);
		
	ClusterNode* n = getNode(0,0,hpamap);

	p = castar.getPath(&hpamap, NULL, n); 
	CPPUNIT_ASSERT_EQUAL_MESSAGE("getPath() failed to return null when start node is null", true, p == 0);

	p = castar.getPath(&hpamap, n, NULL); 
	CPPUNIT_ASSERT_EQUAL_MESSAGE("getPath() failed to return null when goal node is null", true, p == 0);
}
Ejemplo n.º 14
0
 void ThreadTest::test_thread_run( void )
 {
     TThread tt(23);
     tt.start();
     tt.join();
     
     CPPUNIT_ASSERT_EQUAL_MESSAGE("thread result", 24, tt.get_iter( ) );
 }
Ejemplo n.º 15
0
    void TestEnumLANEndpointInstances(void)
    {
        std::wstring errMsg;
        TestableContext context;
        StandardTestEnumerateInstances<mi::SCX_LANEndpoint_Class_Provider>(
            m_keyNamesLANE, context, CALL_LOCATION(errMsg));
        CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MESSAGE, 2u, context.Size());

        CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MESSAGE, L"eth0",
            context[0].GetKey(L"Name", CALL_LOCATION(errMsg)));
        CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MESSAGE, L"SCX_ComputerSystem",
            context[0].GetKey(L"SystemCreationClassName", CALL_LOCATION(errMsg)));
        CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MESSAGE, GetFQHostName(CALL_LOCATION(errMsg)),
            context[0].GetKey(L"SystemName", CALL_LOCATION(errMsg)));
        CPPUNIT_ASSERT_EQUAL_MESSAGE(ERROR_MESSAGE, L"SCX_LANEndpoint",
            context[0].GetKey(L"CreationClassName", CALL_LOCATION(errMsg)));
    }
Ejemplo n.º 16
0
// setBPtr
void FirstOrderLinearDSTest::testSetBPtr()
{
  std::cout << "--> Test: setBPtr." <<std::endl;
  SP::FirstOrderLinearDS ds1(new FirstOrderLinearDS(x0));
  ds1->setb(b0);
  CPPUNIT_ASSERT_EQUAL_MESSAGE("testSetBPtr : ", ds1->b() == b0, true);
  std::cout << "--> setBPtr test ended with success." <<std::endl;
}
Ejemplo n.º 17
0
void ZipTest::test_addFiles_WhenOneFileNotExists() {
    bool expected = false;
    std::string zipFileName = tempFolder + "/" + zipFile;

    zip->open(zipFileName);
    std::string dataDir = "data/test/";
    std::list<std::string> fileNames;
    fileNames.push_back(notExistingFileName);
    fileNames.push_back(dataDir + fileInsideZip);

    bool actual = zip->addFiles(fileNames);
    zip->close();

    CPPUNIT_ASSERT_EQUAL_MESSAGE("add", expected, actual);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("count", 1, numFilesInZip(zipFileName));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("contains", true, containsFile(zipFileName, dataDir + fileInsideZip));
}
Ejemplo n.º 18
0
// setFPtr
void FirstOrderLinearTIRTest::testSetFPtr()
{
  std::cout << "--> Test: setFPtr." <<std::endl;
  SP::FirstOrderLinearTIR folr(new FirstOrderLinearTIR(C, B));
  folr->setFPtr(F);
  CPPUNIT_ASSERT_EQUAL_MESSAGE("testSetFPtr: ", folr->F() == F, true);
  std::cout << "--> setFPtr test ended with success." <<std::endl;
}
void AnnotatedHierarchicalAStarTest::evaluateShouldReturnFalseIfEdgeDoesNotConnectParameterNodes()
{
	ahastar->e = new edge(10,11,7);
	bool expectedResult = false;
	bool actualResult = ahastar->evaluate(n, p); // initialised by null in AA* constructor

	CPPUNIT_ASSERT_EQUAL_MESSAGE("evaluate failed to return false when edge being traversed does not connect parameter nodes", expectedResult, actualResult);	
}
// insertDynamicalSystem
void NonSmoothDynamicalSystemTest::testinsertDynamicalSystem()
{
  SP::NonSmoothDynamicalSystem  nsds(new NonSmoothDynamicalSystem(tmpxml));
  xmlNode *node2 = SiconosDOMTreeTools::findNodeChild(node, "DS_Definition");
  xmlNode * node3 = SiconosDOMTreeTools::findNodeChild(node2, "LagrangianLinearTIDS");
  SP::DynamicalSystemXML tmpdsxml(new LagrangianLinearTIDSXML(node3, false));

  SP::DynamicalSystem ltids(new LagrangianLinearTIDS(tmpdsxml));
  ltids ->setNumber(23);

  nsds->insertDynamicalSystem(ltids);
  CPPUNIT_ASSERT_EQUAL_MESSAGE("testinsertDynamicalSystemA : ", nsds->getDSVectorSize() == 3, true);
  CPPUNIT_ASSERT_EQUAL_MESSAGE(" testinsertDynamicalSystemB: ", nsds->dynamicalSystem(0)->number() == 3, true);
  CPPUNIT_ASSERT_EQUAL_MESSAGE("testinsertDynamicalSystemC : ", nsds->dynamicalSystem(1)->number() == 8, true);
  CPPUNIT_ASSERT_EQUAL_MESSAGE("testinsertDynamicalSystemC : ", nsds->dynamicalSystem(2)->number() == 23, true);
  std::cout << "------- test insertDynamicalSystem ok -------" <<std::endl;
}
Ejemplo n.º 21
0
// constructor from data
void FirstOrderLinearDSTest::testBuildFirstOrderLinearDS1()
{
  std::cout << "--> Test: constructor 1." <<std::endl;
  SP::FirstOrderLinearDS ds(new FirstOrderLinearDS(x0, "TestPlugin:computeA", "TestPlugin:computeb"));

  CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildFirstOrderLinearDS1A : ", Type::value(*ds) == Type::FirstOrderLinearDS, true);
  CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildFirstOrderLinearDS1B : ", ds->n() == 3, true);
  CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildFirstOrderLinearDS1C : ", ds->x0() == x0, true);

  double time = 1.5;
  ds->initialize(time);
  ds->computeA(time);
  ds->computeb(time);
  ds->computeRhs(time);
  SP::SiconosVector x01(new SiconosVector(3));
  (*x01)(0) = 0;
  (*x01)(1) = 1;
  (*x01)(2) = 2;

  CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildFirstOrderLinearDS1D : ", *(ds->b()) == time* *x01, true);
  CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildFirstOrderLinearDS1E : ", *(ds->A()) == 2 * *A0, true);
  //  ds->rhs()->display();
  CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildFirstOrderLinearDS1F : ", *(ds->rhs()) == (time* *x01 + 2 * prod(*A0, *x0)) , true);

  ds->computeRhs(time);

  CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildFirstOrderLinearDS2M : ", *(ds->rhs()) == (2 * prod(*A0 , *x0) + * (ds->b())), true);
  std::cout << "--> Constructor 3 test ended with success." <<std::endl;
}
Ejemplo n.º 22
0
// constructor from data
void NewtonEulerDSTest::testBuildNewtonEulerDS1()
{
  std::cout << "--> Test: constructor 1." <<std::endl;

  SP::NewtonEulerDS ds(new NewtonEulerDS(q0, velocity0, mass,  inertia ));
  double time = 1.5;
  ds->initialize(time);
  CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildNewtonEulerDS1A : ", Type::value(*ds) == Type::NewtonEulerDS, true);
  CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildNewtonEulerDS1B : ", ds->number() == 0, true);
  CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildNewtonEulerDS1D : ", ds->dimension() == 6, true);
  CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildNewtonEulerDS1D : ", ds->getqDim() == 7, true);
  CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildNewtonEulerDS1D : ", ds->scalarMass() == mass, true);

  SP::SimpleMatrix massMatrix(new SimpleMatrix(6,6));
  massMatrix->setValue(0, 0, mass);
  massMatrix->setValue(1, 1, mass);
  massMatrix->setValue(2, 2, mass);

  Index dimIndex(2);
  dimIndex[0] = 3;
  dimIndex[1] = 3;
  Index startIndex(4);
  startIndex[0] = 0;
  startIndex[1] = 0;
  startIndex[2] = 3;
  startIndex[3] = 3;
  setBlock(inertia, massMatrix, dimIndex, startIndex);

  CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildNewtonEulerDS1D : ", *(ds->mass()) == *(massMatrix), true);

  CPPUNIT_ASSERT_EQUAL_MESSAGE("testBuildNewtonEulerDS1D : ", ds->computeKineticEnergy() == 595.0, true);

  std::cout << "--> Constructor 1 test ended with success." <<std::endl;
}
    /** Test the resize() method for a string. 
    *   The test data for this test are :- 
    *    1) When the string is empty, resize to 0
    *    2) When the string is empty, resize to non-zero
    *    3) When the string is not empty, resize to n > current size
    *    4) When the string is not empty, resize to n = current size
    *    5) When the string is empty, resize to n < current size
    */
    void testResize()
    {
        struct TestResizeStruct 
        {
            const char* testDescription ; 
            const char* stringData ; 
            int resizeLength ; 
            const char* expectedString ; 
            int expectedLength ; 
        } ; 

        const char* prefix = "Test the resize(n) method for " ; 
        const char* suffix1 = " - Verify modified string data" ;
        const char* suffix2 = " - Verify modified string length" ;  
        string Message ; 
        
        TestResizeStruct testData[] = { \
            { "an empty string. Set n to 0", "", 0, "", 0 }, \
            { "an empty string. Set n to > 0", "", 5, "", 5 }, \
            { "a non-empty string. Set n > current size", "Test String", 14, \
              "Test String", 14 }, \
            { "a non-empty string. Set n = current size", "Test String", 11, \
              "Test String", 11 }, \
            { "a non-empty string. Set n < current size", "Test String", 6, \
              "Test S", 6 } \
        } ; 

        int testCount = sizeof(testData)/sizeof(testData[0]) ; 
        for (int i = 0 ; i < testCount; i++)
        {
            UtlString testString(testData[i].stringData) ; 
            testString.resize(testData[i].resizeLength) ; 
            //Verify target string's data
            TestUtilities::createMessage(3, &Message, prefix, testData[i].testDescription,\
                 suffix1) ; 
            CPPUNIT_ASSERT_EQUAL_MESSAGE(Message.data(), string(testData[i].expectedString), \
                string(testString.data())) ;
            //Verify target string's length
            TestUtilities::createMessage(3, &Message, prefix, testData[i].testDescription,\
                 suffix2) ; 
            CPPUNIT_ASSERT_EQUAL_MESSAGE(Message.data(), testData[i].expectedLength, \
                (int)testString.length()) ;
             
        }
    }
Ejemplo n.º 24
0
    void testManipulators()
    {
        const char* a1 = "john.salesman:sales@www/example.com:5+5=10";
        const char* a2 = "GET:/private/prices.html";
        const char* a1Encoded = "806d252e3788478d0cebb3c079f515bc";
        const char* a2Encoded = "254bd53db6966fa1387fa1973bb5e53c";

        UtlString a1EncodedString;
        UtlString a2EncodedString;
                                                                                
        NetMd5Codec::encode(a1, a1EncodedString);
        CPPUNIT_ASSERT_EQUAL_MESSAGE("md5 encode test 1", 
            0, a1EncodedString.compareTo(a1Encoded));
                                                                                
        NetMd5Codec::encode(a2, a2EncodedString);
        CPPUNIT_ASSERT_EQUAL_MESSAGE("md5 encode test 2", 
            0, a2EncodedString.compareTo(a2Encoded));
    }
void
DriverSettingsMessageAdapterTest::TestParent()
{
	const settings_template kSubTemplate[] = {
		{B_STRING_TYPE, "name", NULL, true},
		{B_BOOL_TYPE, "bool", NULL},
		{}
	};
	const settings_template kTemplate[] = {
		{B_MESSAGE_TYPE, "message", kSubTemplate},
		{}
	};
	Settings settingsA("message first {\n"
		"    bool\n"
		"}\n");
	BMessage message;
	CPPUNIT_ASSERT_EQUAL(B_OK, settingsA.ToMessage(kTemplate, message));
	BMessage subMessage;
	CPPUNIT_ASSERT_EQUAL(B_OK, message.FindMessage("message", &subMessage));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("bool", true, subMessage.GetBool("bool"));
	CPPUNIT_ASSERT_EQUAL(BString("first"),
		BString(subMessage.GetString("name")));

	Settings settingsB("message second\n");
	CPPUNIT_ASSERT_EQUAL(B_OK, settingsB.ToMessage(kTemplate, message));
	CPPUNIT_ASSERT_EQUAL(B_OK, message.FindMessage("message", &subMessage));
	CPPUNIT_ASSERT_EQUAL(false, subMessage.HasBool("bool"));
	CPPUNIT_ASSERT_EQUAL(BString("second"),
		BString(subMessage.GetString("name", "-/-")));

	const settings_template kSubSubTemplateC[] = {
		{B_STRING_TYPE, "subname", NULL, true},
		{B_BOOL_TYPE, "bool", NULL},
		{}
	};
	const settings_template kSubTemplateC[] = {
		{B_STRING_TYPE, "name", NULL, true},
		{B_MESSAGE_TYPE, "sub", kSubSubTemplateC},
		{}
	};
	const settings_template kTemplateC[] = {
		{B_MESSAGE_TYPE, "message", kSubTemplateC},
		{}
	};

	Settings settingsC("message other {\n"
		"    sub third {\n"
		"        hun audo\n"
		"    }\n"
		"    sub fourth\n"
		"}");
	CPPUNIT_ASSERT_EQUAL(B_OK, settingsC.ToMessage(kTemplateC, message));
	CPPUNIT_ASSERT_EQUAL(B_OK, message.FindMessage("message", &subMessage));
	CPPUNIT_ASSERT_EQUAL(false, subMessage.HasBool("bool"));
	CPPUNIT_ASSERT_EQUAL(BString("other"),
		BString(subMessage.GetString("name", "-/-")));
}
Ejemplo n.º 26
0
void PlayerTest::testFire()
{
	_player->Ammo = 0;
	_player->fire(0);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("test 1", 0, _player->Ammo);

	_player->Ammo = 1;
	_player->fire(0);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("test 2", 0, _player->Ammo);

	_player->Ammo = 2;
	_player->fire(0);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("test 3", 1, _player->Ammo);

	_playerFalse->Ammo = 2;
	_playerFalse->fire(0);
	CPPUNIT_ASSERT_EQUAL_MESSAGE("test 4", 2, _playerFalse->Ammo);
}
Ejemplo n.º 27
0
void compareSimplePropertyValue(::fwData::Object::sptr obj,
                                const std::string& propertyPath,
                                const std::string& value)
{
    ::fwData::GenericFieldBase::sptr field;
    field = ::fwDataCamp::getObject< ::fwData::GenericFieldBase >(obj, propertyPath);
    CPPUNIT_ASSERT_MESSAGE("Retrieve failed for property "+propertyPath, field);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("Retrieve property "+propertyPath+" not equal with value.", value, field->toString());
}
Ejemplo n.º 28
0
void TestUtils::format()
{
	CPPUNIT_ASSERT_EQUAL(std::string("texttext"), Utils::format("texttext", 1, 2, "", 0.1));
	CPPUNIT_ASSERT_EQUAL(std::string("a1,2"), Utils::format("a{0},{1}", 1, 2, "", 0.1));
	CPPUNIT_ASSERT_EQUAL(std::string(""), Utils::format("{2}", 1, 2, "", 0.1));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("No arguments", std::string("{0}"), Utils::format("{0}"));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("No arguments", std::string("{-1}"), Utils::format("{-1}"));
	CPPUNIT_ASSERT_THROW_MESSAGE("Not enough arguments", Utils::format("{1}", 0), std::invalid_argument);
	CPPUNIT_ASSERT_THROW_MESSAGE("Negative argument", Utils::format("{-1}", 0), std::invalid_argument);
	CPPUNIT_ASSERT_THROW_MESSAGE("Unclosed brace 1", Utils::format("{0", 0, 1), std::invalid_argument);
	CPPUNIT_ASSERT_THROW_MESSAGE("Unclosed brace 2", Utils::format("{0}}", 0, 1), std::invalid_argument);
	CPPUNIT_ASSERT_THROW_MESSAGE("Unopened brace 1", Utils::format("0}", 0, 1), std::invalid_argument);
	CPPUNIT_ASSERT_THROW_MESSAGE("Unopened brace 2", Utils::format("{{0}", 0, 1), std::invalid_argument);

	CPPUNIT_ASSERT_EQUAL_MESSAGE("Double braces 1", std::string("{0}"), Utils::format("{{0}}", 0));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Double braces 2", std::string("{0"), Utils::format("{{0", 0));
	CPPUNIT_ASSERT_EQUAL_MESSAGE("Double braces 3", std::string("0}"), Utils::format("0}}", 0));
}
Ejemplo n.º 29
0
void ZipTest::test_openAppendToZip() {
    bool expected = true;
    std::string zipFileName = tempFolder + "/" + zipFile;

    createFolder(zipFileName);
    copyFile(zipFile, zipFileName);

    zip->open(zipFileName, OpenFlags::OpenExisting);
    std::string theString("Lorem Ipsum...");
    std::vector<unsigned char> content;
    content.insert(content.end(), theString.begin(), theString.end());
    bool actual = zip->addFile("file1.txt", content);
    zip->close();

    CPPUNIT_ASSERT_EQUAL_MESSAGE("add", expected, actual);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("contains", true, containsFile(zipFileName, "file1.txt"));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("count", 7, numFilesInZip(zipFileName));
}
Ejemplo n.º 30
0
void ZipTest::test_addFiles_WithNotPreservePath() {
    bool expected = true;
    std::string zipFileName = tempFolder + "/" + zipFile;

    zip->open(zipFileName);
    std::string dataDir = "data/test/";
    std::list<std::string> fileNames;
    fileNames.push_back(dataDir + fileInsideZip);
    fileNames.push_back(dataDir + fileInsideZipWithUmlaut);

    bool actual = zip->addFiles(fileNames, false);
    zip->close();

    CPPUNIT_ASSERT_EQUAL_MESSAGE("add", expected, actual);
    CPPUNIT_ASSERT_EQUAL_MESSAGE("count", 2, numFilesInZip(zipFileName));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("contains", true, containsFile(zipFileName, fileInsideZip));
    CPPUNIT_ASSERT_EQUAL_MESSAGE("contains", true, containsFile(zipFileName, fileInsideZipWithUmlaut));
}