Ejemplo n.º 1
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());
      }
Ejemplo n.º 2
0
void
RegistrationDB::updateBinding(const RegistrationBinding& reg)
{
   updateBinding(*(reg.getUri()),    // must not be null
                 *(reg.getContact() ? reg.getContact() : &nullString),
                 *(reg.getQvalue() ? reg.getQvalue() : &nullString),
                 *(reg.getCallId() ? reg.getCallId() : &nullString),
                 reg.getCseq(),
                 reg.getExpires(),
                 *(reg.getInstanceId() ? reg.getInstanceId() : &nullString),
                 *(reg.getGruu() ? reg.getGruu() : &nullString),
                 *(reg.getPath() ? reg.getPath() : &nullString),
                 *(reg.getPrimary() ? reg.getPrimary() : &nullString),
                 reg.getUpdateNumber());
}
Ejemplo n.º 3
0
   void testUpdateNewBinding()
      {
         Url uri;
         UtlString contact;
         UtlSList bindings;
         RegistrationBinding* binding;
         RegistrationBinding newBinding;

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

         testDbContext.inputFile("updateBindings.xml");

         RegistrationDB* regDb = RegistrationDB::getInstance();

         // Make sure an existing binding doesn't exist
         Int64 seqOneUpdates = regDb->getNewUpdatesForRegistrar("seqOne", 3, bindings);
         CPPUNIT_ASSERT_EQUAL(0LL, seqOneUpdates);

         // Create new binding with update number 3
         uri.setUserId("300");
         uri.setHostAddress("testdomain.example.com");
         newBinding.setUri(uri);

         newBinding.setContact("sip:[email protected]");
         newBinding.setCallId("ID3");
         newBinding.setPrimary("seqOne");
         newBinding.setUpdateNumber(3);

         // Add new binding
         regDb->updateBinding(newBinding);

         bindings.destroyAll();

         // We should now have two bindings - the original with update number 2 and the new one
         seqOneUpdates = regDb->getNewUpdatesForRegistrar("seqOne", 2, bindings);
         CPPUNIT_ASSERT_EQUAL(2LL, seqOneUpdates);

         // Test if the registration data corresponds to what we expect
         UtlBoolean bSeenId2 = FALSE;
         UtlBoolean bSeenId3 = FALSE;
         UtlBoolean bSeenAnythingElse = FALSE;
         UtlSListIterator iterator(bindings);

         while ((binding = (RegistrationBinding*)iterator()))
         {
             const UtlString *s = binding->getCallId();
             if (s->compareTo("ID2") == 0)
             {
                 bSeenId2 = TRUE;
                 CPPUNIT_ASSERT_EQUAL(binding->getContact()->compareTo("sip:[email protected]"), 0);
                 CPPUNIT_ASSERT_EQUAL(binding->getUri()->toString().compareTo("sip:[email protected]"), 0);
             }
             else if (s->compareTo("ID3") == 0)
             {
                 bSeenId3 = TRUE;
                 CPPUNIT_ASSERT_EQUAL(binding->getContact()->compareTo("sip:[email protected]"), 0);
                 CPPUNIT_ASSERT_EQUAL(binding->getUri()->toString().compareTo("sip:[email protected]"), 0);
                 CPPUNIT_ASSERT_EQUAL(binding->getUpdateNumber(), 3LL);
             }
             else
             {
                 bSeenAnythingElse = TRUE;
             }
         }
         CPPUNIT_ASSERT(!bSeenAnythingElse);
         CPPUNIT_ASSERT(bSeenId2);
         CPPUNIT_ASSERT(bSeenId3);
      }