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()); }
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); }