当前位置: 首页>>代码示例>>C++>>正文


C++ UtlDList::index方法代码示例

本文整理汇总了C++中UtlDList::index方法的典型用法代码示例。如果您正苦于以下问题:C++ UtlDList::index方法的具体用法?C++ UtlDList::index怎么用?C++ UtlDList::index使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UtlDList的用法示例。


在下文中一共展示了UtlDList::index方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: utlTestIndex_Find_And_Contains

    // Since the test setup / preconditions for the index, find, 
    // contains and containsReference are all the same, these
    // tests have been combined into one utility function. Based
    // on the type argument, the method to be tested is varied. 
    void utlTestIndex_Find_And_Contains(IndexOrContains type)
    {
        const int testCount = 7 ; 
        const char* prefixIndex = "Test the index() method when the match " ; 
        const char* prefixFind = "Test the find() method when the match " ; 
        const char* prefixContains = "Test the contains() method when the match " ; 
        const char* prefixContainsRef = "Test the containsReference() method when the match " ; 
        const char* Msgs[] = { \
               "is the first element ", \
               "is the last element ", \
               "is a mid element (unique match) ", \
               "has two value matches but a single ref match ", \
               "has two ref matches", \
               "has a value match but no ref match", \
               "has no match at all" \
        } ; 
        // insert a clone of the 4th element to the 1st position
        commonList.insertAt(1, commonContainables_Clone[4]) ; 
       // The new index for a value match of commonContainables[4] must be 1. 

       // insert another copy of the 3rd element to the 2nd position. 
       commonList.insertAt(2, commonContainables[3]) ; 
       // The new index for commonContainables[3] must be 2) ; 
       // what used to be the second element has now moved to 4. 

       UtlString noExist("This cannot and should not exist!!!") ; 

       UtlContainable* searchValues[] = { \
                 commonContainables[0], commonContainables[5], commonContainables[2], \
                 commonContainables[4], commonContainables[3], \
                 commonContainables_Clone[2], &noExist \
       } ; 

       size_t expectedValues_Index[] = { 0, 7, 4, 1, 2, 4, UTL_NOT_FOUND } ; 
 
       bool expectedValues_Contains[]    = {true, true, true, true, true, true, false } ;
       bool expectedValues_ContainsRef[] = {true, true, true, true, true, false, false} ; 

       UtlContainable* searchValuesForFind[] = { \
                 commonContainables[0], commonContainables[5], commonContainables[2], \
                 commonContainables[4], commonContainables[3], \
                 commonContainables_Clone[1], &noExist \
       } ;
       UtlContainable* expectedValuesForFind[] = { \
                 commonContainables[0], commonContainables[5], commonContainables[2], \
                 commonContainables_Clone[4], commonContainables[3], \
                 commonContainables[1], NULL \
       } ;

       for (int i = 0 ; i < testCount ; i++)
       {
           string msg ; 
           if (type == TEST_INDEX) 
           {
               size_t actual = commonList.index(searchValues[i]) ; 
               TestUtilities::createMessage(2, &msg, prefixIndex, Msgs[i]) ; 
               CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValues_Index[i], actual) ; 
           } 
           else if (type == TEST_FIND) 
           {
               UtlContainable* actual = commonList.find(searchValuesForFind[i]) ; 
               TestUtilities::createMessage(2, &msg, prefixFind, Msgs[i]) ; 
               CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValuesForFind[i], actual) ;
           }
           else if (type == TEST_CONTAINS) 
           {
               UtlBoolean actual = commonList.contains(searchValues[i]) ; 
               TestUtilities::createMessage(2, &msg, prefixContains, Msgs[i]) ; 
               CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValues_Contains[i], \
                  (TRUE == actual)) ; 
           }
           else if (type == TEST_CONTAINS_REF)
           {
               UtlBoolean actual = commonList.containsReference(searchValues[i]) ;
               TestUtilities::createMessage(2, &msg, prefixContainsRef, Msgs[i]) ;
               CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), expectedValues_ContainsRef[i], \
                   (TRUE == actual)) ;
           }
       }
    }//utlTestIndex
开发者ID:Jaroslav23,项目名称:sipxtapi,代码行数:84,代码来源:UtlDList.cpp


注:本文中的UtlDList::index方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。