Example #1
0
   void testUpdateExistingBinding()
      {
         UtlSList bindings;
         RegistrationBinding* binding;

         RegistrationDbTestContext testDbContext(TEST_DATA_DIR "/regdbdata",
                                                 TEST_WORK_DIR "/regdbdata"
                                                 );

         testDbContext.inputFile("updateBindings.xml");

         RegistrationDB* regDb = RegistrationDB::getInstance();

         // Get an existing binding
         Int64 seqOneUpdates = regDb->getNewUpdatesForRegistrar("seqOne", 2, bindings);
         CPPUNIT_ASSERT_EQUAL(1LL, seqOneUpdates);

         binding = (RegistrationBinding*)bindings.first();

         // Increment the CSeq number
         int newCseq = binding->getCseq() + 1;
         binding->setCseq(newCseq);
         regDb->updateBinding(*binding);
         binding->setCseq(0);

         // Get the same binding
         bindings.destroyAll();
         seqOneUpdates = regDb->getNewUpdatesForRegistrar("seqOne", 2, bindings);
         CPPUNIT_ASSERT_EQUAL(1LL, seqOneUpdates);

         // Test if the new CSeq number got updated
         binding = (RegistrationBinding*)bindings.first();
         CPPUNIT_ASSERT_EQUAL(newCseq, binding->getCseq());
      }
Example #2
0
   void testUpdateExistingUriNewContact()
      {
         UtlSList bindings;
         RegistrationBinding* binding;

         RegistrationDbTestContext testDbContext(TEST_DATA_DIR "/regdbdata",
                                                 TEST_WORK_DIR "/regdbdata"
                                                 );

         testDbContext.inputFile("updateBindings.xml");

         RegistrationDB* regDb = RegistrationDB::getInstance();

         // Get an existing binding
         Int64 seqOneUpdates = regDb->getNewUpdatesForRegistrar("seqOne", 2, bindings);
         CPPUNIT_ASSERT_EQUAL(1LL, seqOneUpdates);

         binding = (RegistrationBinding*)bindings.first();

         // Change the contact address
         const UtlString* oldContact = binding->getContact();
         UtlString newContact(*oldContact);
         newContact.replace('2', '3');
         binding->setContact(newContact);
         regDb->updateBinding(*binding);

         // We should have 2 bindings now
         bindings.destroyAll();
         seqOneUpdates = regDb->getNewUpdatesForRegistrar("seqOne", 2, bindings);
         CPPUNIT_ASSERT_EQUAL(2LL, seqOneUpdates);
      }
Example #3
0
   void testUpdateSameBinding()
      {
         UtlSList bindings;
         RegistrationBinding* binding;

         RegistrationDbTestContext testDbContext(TEST_DATA_DIR "/regdbdata",
                                                 TEST_WORK_DIR "/regdbdata"
                                                 );

         testDbContext.inputFile("updateBindings.xml");

         RegistrationDB* regDb = RegistrationDB::getInstance();

         // Get an existing binding
         Int64 seqOneUpdates = regDb->getNewUpdatesForRegistrar("seqOne", 2, bindings);
         CPPUNIT_ASSERT_EQUAL(1LL, seqOneUpdates);

         binding = (RegistrationBinding*)bindings.first();

         // Call updateBinding with the same binding
         regDb->updateBinding(*binding);

         // Get it back and make sure we still only have one
         bindings.destroyAll();
         seqOneUpdates = regDb->getNewUpdatesForRegistrar("seqOne", 2, bindings);
         CPPUNIT_ASSERT_EQUAL(1LL, seqOneUpdates);
      }
Example #4
0
   void testGetNextUpdateForRegistrar()
      {
         UtlSList bindings;
         RegistrationDbTestContext testDbContext(TEST_DATA_DIR "/regdbdata",
                                                 TEST_WORK_DIR "/regdbdata"
                                                 );

         testDbContext.inputFile("getMaxUpdate.xml");

         RegistrationDB* regDb = RegistrationDB::getInstance();

         Int64 seqOneUpdates = regDb->getNextUpdateForRegistrar("seqOne", 2, bindings);
         CPPUNIT_ASSERT_EQUAL(1LL, seqOneUpdates);

         UtlSListIterator iterator(bindings);

         // Loop through all returned bindings and mark the ones we've seen.
         // Also check correctness of bindings
         RegistrationBinding *binding;
         while ((binding = (RegistrationBinding*)iterator()))
         {
             CPPUNIT_ASSERT_EQUAL(binding->getCallId()->compareTo("ID3"), 0);
             CPPUNIT_ASSERT_EQUAL(binding->getContact()->compareTo("sip:[email protected]"), 0);
             CPPUNIT_ASSERT_EQUAL(binding->getUri()->toString().compareTo("sip:[email protected]"), 0);
             CPPUNIT_ASSERT_EQUAL(300, binding->getCseq());
         }

         bindings.destroyAll();
         // Pass in high update number value, expect nothing to be returned
         seqOneUpdates = regDb->getNewUpdatesForRegistrar("seqOne", 8, bindings);
         CPPUNIT_ASSERT_EQUAL(0LL, seqOneUpdates);

         bindings.destroyAll();
         // Test the other registrar, expect one binding
         Int64 seqTwoUpdates = regDb->getNewUpdatesForRegistrar("seqTwo", 2, bindings);
         CPPUNIT_ASSERT_EQUAL(1LL, seqTwoUpdates);

         binding = (RegistrationBinding*)bindings.first();
         CPPUNIT_ASSERT_EQUAL(binding->getContact()->compareTo("sip:[email protected]"), 0);
         CPPUNIT_ASSERT_EQUAL(binding->getUri()->toString().compareTo("sip:[email protected]"), 0);
         CPPUNIT_ASSERT_EQUAL(800, binding->getCseq());
      }
Example #5
0
    /*!a  Test case to test the first() and last() method. 
    *
    *     The test data for this test case is :-
    *     a) Test the first and last element after appending
    *     b) Test the first and last element after insertAt(midlevel)
    *     c) Test the first and last element after insertAt(0) 
    *     d) Test the first and last element after insertAt(last)
    */
    void testFirst_And_Last()
    {
        const char* prefix1 = "Test the first() method "; 
        const char* prefix2 = "Test the last() method " ; 
        string msg ; 
        UtlContainable* uActual ; 
        UtlContainable* uData ; 
        UtlContainable* uExpected ; 

        const char* Msgs[] = { \
               "after appending ", \
               "after insertAt(0) ", \
               "after insertAt(last) ", \
               "after insertAt(mid-level) " \
        } ;

        // Since this testcase requires a different test data 
        // for each of its test data, the regula test-matrix
        // technique is not being used here. 

        // create a new list and append one element to it. 
        UtlSList testList ; 
        uData = commonContainables[0] ; 
        testList.append(uData); 
        
        // Test the first() and last() element immeidately after
        // appending to an empty list. 
        TestUtilities::createMessage(2, &msg, prefix1, Msgs[0]);
        uActual = testList.first() ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uData, uActual) ;
        uActual = testList.last() ;  
        TestUtilities::createMessage(2, &msg, prefix2, Msgs[0]) ; 
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uData, uActual) ; 

        // insert more values to populate the List
        testList.append(commonContainables[1]) ; 
        testList.append(commonContainables[2]) ; 

        // test the first() / last() methods 
        // after insertAt(0..)
        uData = commonContainables[3] ;
        testList.insertAt(0, uData) ;
        uExpected = commonContainables[3] ;
        uActual = testList.first() ;
        TestUtilities::createMessage(2, &msg, prefix1, Msgs[1]) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uExpected, uActual) ;
        uExpected = commonContainables[2] ; 
        uActual = testList.last() ;
        TestUtilities::createMessage(2, &msg, prefix2, Msgs[1]) ;
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uExpected, uActual) ;        

        // test after inserting at the last location
        uData = commonContainables[4] ; 
        testList.insertAt(4, uData) ; 
        uExpected = commonContainables[3] ; 
        uActual = testList.first() ; 
        TestUtilities::createMessage(2, &msg, prefix1, Msgs[2]) ; 
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uExpected, uActual) ; 
        uExpected = commonContainables[4] ; 
        uActual = testList.last() ; 
        TestUtilities::createMessage(2, &msg, prefix2, Msgs[2]) ; 
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uExpected, uActual) ; 

        //test after inserting at the midLocation
        uData = commonContainables[5] ; 
        testList.insertAt(2, uData) ; 
        uExpected = commonContainables[3] ; 
        uActual = testList.first() ; 
        TestUtilities::createMessage(2, &msg, prefix1, Msgs[3]) ; 
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uExpected, uActual) ; 
        uExpected = commonContainables[4] ; 
        uActual = testList.last() ; 
        TestUtilities::createMessage(2, &msg, prefix2, Msgs[3]) ; 
        CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.data(), uExpected, uActual) ; 

    } //testFirst_And_Last