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); }
RegistrationBinding* RegistrationDB::copyRowToRegistrationBinding(dbCursor<RegistrationRow>& cursor) const { RegistrationBinding *reg = new RegistrationBinding(); reg->setUri(* new UtlString(cursor->uri)); reg->setCallId(* new UtlString(cursor->callid)); reg->setContact(* new UtlString(cursor->contact)); reg->setQvalue(* new UtlString(cursor->qvalue)); reg->setInstanceId(* new UtlString(cursor->instance_id)); reg->setGruu(* new UtlString(cursor->gruu)); reg->setPath(* new UtlString(cursor->path)); reg->setCseq(cursor->cseq); reg->setExpires(cursor->expires); reg->setPrimary(* new UtlString(cursor->primary)); reg->setUpdateNumber(cursor->update_number); return reg; }
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); }