Example #1
0
    /*!a  Test case for the isEmpty() method. 
    *     The test data for this test are :-
    *        a) When the list has just been created. 
    *        b) When the list has one entry in it 
    *        c) When the list has multiple entries in it. 
    *        d) When all the entries in a list have been removed using get. 
    *        e) When all the entries in a list have been removed using removeAll()
    */
    void testIsEmpty()
    {
        const int testCount = 5 ; 
        const char* prefix = "Test the isEmpty() method when " ; 
        const char* Msgs[] = { \
                "the list has just been created" , \
                "the list has just one entry in it", \
                "the list has multiple entries in it", \
                "all the list entries have been retreieved using get()", \
                "all the list entries have been retreived using removeAll()" \
        } ;

        UtlSList newList ; 
        UtlSList secondNewList ; 
        UtlSList commonList_Clone ; 

        // first populate a list and then retreive all elements using get
        for (int i = 0 ; i < commonEntriesCount ; i++)
        {
            commonList_Clone.append(commonContainables_Clone[i]) ; 
        }
        for (int j = 0 ; j < commonEntriesCount; j++)
        {
            commonList_Clone.get(); 
        }
        
        UtlString uS1 = UtlString("Lone Entry") ; 
        newList.append(&uS1) ; 

        // populate the second list and then clear all entries. 
        secondNewList.append(&uS1) ; 
        UtlInt uI1 = UtlInt(232) ; 
        secondNewList.append(&uI1) ; 
        secondNewList.removeAll() ; 
    
        UtlSList* testLists[] = { \
                 &emptyList, &newList, &commonList, &commonList_Clone,  &secondNewList \
        } ; 

        bool expectedValue[] = { true, false, false, true, true } ; 
        for (int k = 0 ; k < testCount; k++)
        {
            string msg ; 
            TestUtilities::createMessage(2, &msg, prefix, Msgs[k]) ; 
            UtlBoolean actual = testLists[k] -> isEmpty() ; 
            CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), (UtlBoolean)expectedValue[k], \
                actual) ; 
        }
    } // testIsEmpty
Example #2
0
    /*!a test the removeAll() method. 
    *
    *    The test data for this method is 
    *        a) When the list is empty
    *        b) When the list has one entry. 
    *        c) When the list multiple entries
    *        d) When removeAll has been called and entries are added again
    *        d) When the removeAll is called twice on the list. 
    */
    void testClear()
    {
        const int testCount = 5 ; 
        const char* prefix = "Test the removeAll() method when :- " ; 
        const char* Msgs[] = { \
               "the list is empty", \
               "the list has one entry", \
               "the list has multiple entries", \
               "removeAll() has been called and entries are added again", \
               "removeAll() has already been called", \
        } ; 
        const char* suffix = " :- Verify number of entries after removeAll()"  ;
        UtlSList uSingleList ;
        UtlSList uAddAfterClear ; 
        UtlSList uDoubleClear ; 

        uSingleList.append(&commonString1) ; 
     
        // call removeAll() on a list and then add entries again. 
        uAddAfterClear.append(&commonInt1) ; 
        uAddAfterClear.append(&commonString1) ; 
        uAddAfterClear.removeAll() ; 
        uAddAfterClear.append(&commonInt2) ; 
 
        // call removeAll on a list twice. 
        uDoubleClear.append(&commonString3) ; 
        uDoubleClear.append(&commonInt3) ; 
        uDoubleClear.removeAll() ; 
 
        UtlSList* testLists[] = { \
                     &emptyList, &uSingleList, &commonList, &uAddAfterClear, &uDoubleClear
        } ;
        int expectedEntries[] = { 0 , 0, 0, 1, 0 } ; 

        // since we are not calling removeAll for all the data, do it outside the for loop. 
        emptyList.removeAll() ; 
        uSingleList.removeAll() ; 
        commonList.removeAll() ; 
        // no removeAll() for uAddAfterClear 
        uDoubleClear.removeAll() ; 
        for ( int i = 0 ; i < testCount ; i++) 
        {
            string msg ; 
            TestUtilities::createMessage(3, &msg, prefix, Msgs[i], suffix) ; 
            CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data() , expectedEntries[i], \
                (int)testLists[i]->entries()) ; 
        }
    } //testClear()
Example #3
0
   void testHandleAlarm()
   {
      OsSysLog::add(FAC_ALARM, PRI_DEBUG, "AlarmServerTest::testHandleAlarm");

      UtlString localhost("localhost");
      UtlString alarmId("NO_LOG");
      UtlString alarmParam("testing");
      UtlSList alarmParams;
      alarmParams.append(&alarmParam);
      UtlString oldLastString;
      tail(mAlarmFile, oldLastString);
      OsSysLog::add(FAC_ALARM, PRI_DEBUG, "oldLastString %s", oldLastString.data());
      bool rc=cAlarmServer::getInstance()->handleAlarm(localhost, alarmId, alarmParams);
      OsTask::delay(500);
      CPPUNIT_ASSERT_MESSAGE("handleAlarm('NO_LOG') failed", rc==true);
      UtlString newLastString;
      tail(mAlarmFile, newLastString);
      OsSysLog::add(FAC_ALARM, PRI_DEBUG, "newLastString %s", newLastString.data());
      CPPUNIT_ASSERT_MESSAGE("alarm with 'NO_LOG' was logged", !oldLastString.compareTo(newLastString));

      alarmId = "TEST_LOG";
      alarmParam = "single parameter";
      alarmParams.removeAll();
      alarmParams.append(&alarmParam);
      OsSysLog::add(FAC_ALARM, PRI_DEBUG, "Test TEST_LOG");
      cAlarmServer::getInstance()->handleAlarm(localhost, alarmId, alarmParams);
      OsTask::delay(DELAY);
      UtlString actualString;
      UtlString expectedString = "This is a test of the log function. Single parameter should be here: single parameter, and that's all that is required";
      tail(mAlarmFile, actualString);
      char msg[1000];
      sprintf(msg, "incorrect message was logged: actualString '%s'  expected '%s'", actualString.data(), expectedString.data());
      CPPUNIT_ASSERT_MESSAGE(msg, actualString.contains(expectedString));

      // test that non-existant alarm returns false
      alarmId = "NONEXISTANT_ID";
      rc=cAlarmServer::getInstance()->handleAlarm(localhost, alarmId, alarmParams);
      CPPUNIT_ASSERT_MESSAGE("handleAlarm('NONEXISTANT_ID') did not fail, and should have", rc!=true);

      // test that alarm with min_threshold is only logged after n attempts
      alarmId = "MIN_THRESHOLD";
      alarmParam = "one";
      alarmParams.removeAll();
      alarmParams.append(&alarmParam);
      tail(mAlarmFile, oldLastString);
      OsSysLog::add(FAC_ALARM, PRI_DEBUG, "oldLastString %s", oldLastString.data());
      cAlarmServer::getInstance()->handleAlarm(localhost, alarmId, alarmParams);
      OsTask::delay(DELAY);
      tail(mAlarmFile, newLastString);
      OsSysLog::add(FAC_ALARM, PRI_DEBUG, "newLastString %s", newLastString.data());
      CPPUNIT_ASSERT_MESSAGE("first instance of alarm with 'min_threshold' was logged", !oldLastString.compareTo(newLastString));
      alarmParam = "two";
      alarmParams.append(&alarmParam);
      cAlarmServer::getInstance()->handleAlarm(localhost, alarmId, alarmParams);
      OsTask::delay(DELAY);
      tail(mAlarmFile, actualString);
      expectedString = "This should only be logged the second time";
      sprintf(msg, "incorrect message was logged: actualString '%s'  expected '%s'", actualString.data(), expectedString.data());
      CPPUNIT_ASSERT_MESSAGE(msg, actualString.contains(expectedString));

   }