12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630 |
- /*
- * Asterisk -- An open source telephony toolkit.
- *
- * Copyright (C) 2013, Digium, Inc.
- *
- * Matt Jordan <mjordan@digium.com>
- *
- * See http://www.asterisk.org for more information about
- * the Asterisk project. Please do not directly contact
- * any of the maintainers of this project for assistance;
- * the project provides a web site, mailing lists and IRC
- * channels for your use.
- *
- * This program is free software, distributed under the terms of
- * the GNU General Public License Version 2. See the LICENSE file
- * at the top of the source tree.
- */
- /*!
- * \file
- * \brief CDR unit tests
- *
- * \author Matt Jordan <mjordan@digium.com>
- *
- */
- /*** MODULEINFO
- <depend>TEST_FRAMEWORK</depend>
- <support_level>core</support_level>
- ***/
- #include "asterisk.h"
- ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
- #include <math.h>
- #include "asterisk/module.h"
- #include "asterisk/test.h"
- #include "asterisk/cdr.h"
- #include "asterisk/linkedlists.h"
- #include "asterisk/chanvars.h"
- #include "asterisk/utils.h"
- #include "asterisk/causes.h"
- #include "asterisk/time.h"
- #include "asterisk/bridge.h"
- #include "asterisk/bridge_basic.h"
- #include "asterisk/stasis_channels.h"
- #include "asterisk/stasis_bridges.h"
- #include "asterisk/format_cache.h"
- #define EPSILON 0.001
- #define TEST_CATEGORY "/main/cdr/"
- #define MOCK_CDR_BACKEND "mock_cdr_backend"
- #define CHANNEL_TECH_NAME "CDRTestChannel"
- /*! \brief A placeholder for Asterisk's 'real' CDR configuration */
- static struct ast_cdr_config *saved_config;
- /*! \brief A configuration suitable for 'normal' CDRs */
- static struct ast_cdr_config debug_cdr_config = {
- .settings.flags = CDR_ENABLED | CDR_DEBUG,
- };
- /*! \brief A configuration suitable for CDRs with unanswered records */
- static struct ast_cdr_config unanswered_cdr_config = {
- .settings.flags = CDR_ENABLED | CDR_UNANSWERED | CDR_DEBUG,
- };
- /*! \brief A configuration suitable for CDRs with congestion enabled */
- static struct ast_cdr_config congestion_cdr_config = {
- .settings.flags = CDR_ENABLED | CDR_UNANSWERED | CDR_DEBUG | CDR_CONGESTION,
- };
- /*! \brief Macro to swap a configuration out from the CDR engine. This should be
- * used at the beginning of each test to set the needed configuration for that
- * test.
- */
- #define SWAP_CONFIG(ao2_config, template) do { \
- *(ao2_config) = (template); \
- ast_cdr_set_config((ao2_config)); \
- } while (0)
- /*! \brief A linked list of received CDR entries from the engine */
- static AST_LIST_HEAD(, test_cdr_entry) actual_cdr_entries = AST_LIST_HEAD_INIT_VALUE;
- /*! \brief The Mock CDR backend condition wait */
- static ast_cond_t mock_cdr_cond;
- /*! \brief A channel technology used for the unit tests */
- static struct ast_channel_tech test_cdr_chan_tech = {
- .type = CHANNEL_TECH_NAME,
- .description = "Mock channel technology for CDR tests",
- };
- struct test_cdr_entry {
- struct ast_cdr *cdr;
- AST_LIST_ENTRY(test_cdr_entry) list;
- };
- /*! \brief The number of CDRs the mock backend has received */
- static int global_mock_cdr_count;
- /*! \internal
- * \brief Callback function for the mock CDR backend
- *
- * This function 'processes' a dispatched CDR record by adding it to the
- * \ref actual_cdr_entries list. When a test completes, it can verify the
- * expected records against this list of actual CDRs created by the engine.
- *
- * \param cdr The public CDR object created by the engine
- *
- * \retval -1 on error
- * \retval 0 on success
- */
- static int mock_cdr_backend_cb(struct ast_cdr *cdr)
- {
- struct ast_cdr *cdr_copy, *cdr_prev = NULL;
- struct ast_cdr *mock_cdr = NULL;
- struct test_cdr_entry *cdr_wrapper;
- cdr_wrapper = ast_calloc(1, sizeof(*cdr_wrapper));
- if (!cdr_wrapper) {
- return -1;
- }
- for (; cdr; cdr = cdr->next) {
- struct ast_var_t *var_entry, *var_copy;
- cdr_copy = ast_calloc(1, sizeof(*cdr_copy));
- if (!cdr_copy) {
- return -1;
- }
- *cdr_copy = *cdr;
- cdr_copy->varshead.first = NULL;
- cdr_copy->varshead.last = NULL;
- cdr_copy->next = NULL;
- AST_LIST_TRAVERSE(&cdr->varshead, var_entry, entries) {
- var_copy = ast_var_assign(var_entry->name, var_entry->value);
- if (!var_copy) {
- return -1;
- }
- AST_LIST_INSERT_TAIL(&cdr_copy->varshead, var_copy, entries);
- }
- if (!mock_cdr) {
- mock_cdr = cdr_copy;
- }
- if (cdr_prev) {
- cdr_prev->next = cdr_copy;
- }
- cdr_prev = cdr_copy;
- }
- cdr_wrapper->cdr = mock_cdr;
- AST_LIST_LOCK(&actual_cdr_entries);
- AST_LIST_INSERT_TAIL(&actual_cdr_entries, cdr_wrapper, list);
- global_mock_cdr_count++;
- ast_cond_signal(&mock_cdr_cond);
- AST_LIST_UNLOCK(&actual_cdr_entries);
- return 0;
- }
- /*! \internal
- * \brief Remove all entries from \ref actual_cdr_entries
- */
- static void clear_mock_cdr_backend(void)
- {
- struct test_cdr_entry *cdr_wrapper;
- AST_LIST_LOCK(&actual_cdr_entries);
- while ((cdr_wrapper = AST_LIST_REMOVE_HEAD(&actual_cdr_entries, list))) {
- ast_cdr_free(cdr_wrapper->cdr);
- ast_free(cdr_wrapper);
- }
- global_mock_cdr_count = 0;
- AST_LIST_UNLOCK(&actual_cdr_entries);
- }
- /*! \brief Verify a string field. This will set the test status result to fail;
- * as such, it assumes that (a) test is the test object variable, and (b) that
- * a return variable res exists.
- */
- #define VERIFY_STRING_FIELD(field, actual, expected) do { \
- if (strcmp((actual)->field, (expected)->field)) { \
- ast_test_status_update(test, "Field %s failed: actual %s, expected %s\n", #field, (actual)->field, (expected)->field); \
- ast_test_set_result(test, AST_TEST_FAIL); \
- res = AST_TEST_FAIL; \
- } } while (0)
- /*! \brief Verify a numeric field. This will set the test status result to fail;
- * as such, it assumes that (a) test is the test object variable, and (b) that
- * a return variable res exists.
- */
- #define VERIFY_NUMERIC_FIELD(field, actual, expected) do { \
- if ((actual)->field != (expected)->field) { \
- ast_test_status_update(test, "Field %s failed: actual %ld, expected %ld\n", #field, (long)(actual)->field, (long)(expected)->field); \
- ast_test_set_result(test, AST_TEST_FAIL); \
- res = AST_TEST_FAIL; \
- } } while (0)
- /*! \brief Verify a time field. This will set the test status result to fail;
- * as such, it assumes that (a) test is the test object variable, and (b) that
- * a return variable res exists.
- */
- #define VERIFY_TIME_VALUE(field, actual) do { \
- if (ast_tvzero((actual)->field)) { \
- ast_test_status_update(test, "Field %s failed: should not be 0\n", #field); \
- ast_test_set_result(test, AST_TEST_FAIL); \
- res = AST_TEST_FAIL; \
- } } while (0)
- /*! \brief Alice's Caller ID */
- #define ALICE_CALLERID { .id.name.str = "Alice", .id.name.valid = 1, .id.number.str = "100", .id.number.valid = 1, }
- /*! \brief Bob's Caller ID */
- #define BOB_CALLERID { .id.name.str = "Bob", .id.name.valid = 1, .id.number.str = "200", .id.number.valid = 1, }
- /*! \brief Charlie's Caller ID */
- #define CHARLIE_CALLERID { .id.name.str = "Charlie", .id.name.valid = 1, .id.number.str = "300", .id.number.valid = 1, }
- /*! \brief David's Caller ID */
- #define DAVID_CALLERID { .id.name.str = "David", .id.name.valid = 1, .id.number.str = "400", .id.number.valid = 1, }
- /*! \brief Copy the linkedid and uniqueid from a channel to an expected CDR */
- #define COPY_IDS(channel_var, expected_record) do { \
- ast_copy_string((expected_record)->uniqueid, ast_channel_uniqueid((channel_var)), sizeof((expected_record)->uniqueid)); \
- ast_copy_string((expected_record)->linkedid, ast_channel_linkedid((channel_var)), sizeof((expected_record)->linkedid)); \
- } while (0)
- /*! \brief Set ulaw format on channel */
- #define SET_FORMATS(chan) do {\
- struct ast_format_cap *caps;\
- caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);\
- ast_format_cap_append(caps, ast_format_ulaw, 0);\
- ast_channel_nativeformats_set((chan), caps);\
- ast_channel_set_writeformat((chan), ast_format_ulaw);\
- ast_channel_set_rawwriteformat((chan), ast_format_ulaw);\
- ast_channel_set_readformat((chan), ast_format_ulaw);\
- ast_channel_set_rawreadformat((chan), ast_format_ulaw);\
- ao2_ref(caps, -1);\
- } while (0)
- /*! \brief Create a \ref test_cdr_chan_tech for Alice, and set the expected
- * CDR records' linkedid and uniqueid. */
- #define CREATE_ALICE_CHANNEL(channel_var, caller_id, expected_record) do { \
- (channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, "100", "Alice", "100", "100", "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/Alice"); \
- SET_FORMATS((channel_var));\
- ast_channel_set_caller((channel_var), (caller_id), NULL); \
- ast_copy_string((expected_record)->uniqueid, ast_channel_uniqueid((channel_var)), sizeof((expected_record)->uniqueid)); \
- ast_copy_string((expected_record)->linkedid, ast_channel_linkedid((channel_var)), sizeof((expected_record)->linkedid)); \
- ast_channel_unlock((channel_var)); \
- } while (0)
- /*! \brief Create a \ref test_cdr_chan_tech for Bob, and set the expected
- * CDR records' linkedid and uniqueid. */
- #define CREATE_BOB_CHANNEL(channel_var, caller_id, expected_record) do { \
- (channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, "200", "Bob", "200", "200", "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/Bob"); \
- SET_FORMATS((channel_var));\
- ast_channel_set_caller((channel_var), (caller_id), NULL); \
- ast_copy_string((expected_record)->uniqueid, ast_channel_uniqueid((channel_var)), sizeof((expected_record)->uniqueid)); \
- ast_copy_string((expected_record)->linkedid, ast_channel_linkedid((channel_var)), sizeof((expected_record)->linkedid)); \
- ast_channel_unlock((channel_var)); \
- } while (0)
- /*! \brief Create a \ref test_cdr_chan_tech for Charlie, and set the expected
- * CDR records' linkedid and uniqueid. */
- #define CREATE_CHARLIE_CHANNEL(channel_var, caller_id, expected_record) do { \
- (channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, "300", "Charlie", "300", "300", "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/Charlie"); \
- SET_FORMATS((channel_var));\
- ast_channel_set_caller((channel_var), (caller_id), NULL); \
- ast_copy_string((expected_record)->uniqueid, ast_channel_uniqueid((channel_var)), sizeof((expected_record)->uniqueid)); \
- ast_copy_string((expected_record)->linkedid, ast_channel_linkedid((channel_var)), sizeof((expected_record)->linkedid)); \
- ast_channel_unlock((channel_var)); \
- } while (0)
- /*! \brief Create a \ref test_cdr_chan_tech for Charlie, and set the expected
- * CDR records' linkedid and uniqueid. */
- #define CREATE_DAVID_CHANNEL(channel_var, caller_id, expected_record) do { \
- (channel_var) = ast_channel_alloc(0, AST_STATE_DOWN, "400", "David", "400", "400", "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/David"); \
- SET_FORMATS((channel_var));\
- ast_channel_set_caller((channel_var), (caller_id), NULL); \
- ast_copy_string((expected_record)->uniqueid, ast_channel_uniqueid((channel_var)), sizeof((expected_record)->uniqueid)); \
- ast_copy_string((expected_record)->linkedid, ast_channel_linkedid((channel_var)), sizeof((expected_record)->linkedid)); \
- ast_channel_unlock((channel_var)); \
- } while (0)
- /*! \brief Emulate a channel entering into an application */
- #define EMULATE_APP_DATA(channel, priority, application, data) do { \
- if ((priority) > 0) { \
- ast_channel_priority_set((channel), (priority)); \
- } \
- ast_channel_lock((channel)); \
- ast_channel_appl_set((channel), (application)); \
- ast_channel_data_set((channel), (data)); \
- ast_channel_publish_snapshot((channel)); \
- ast_channel_unlock((channel)); \
- } while (0)
- /*! \brief Hang up a test channel safely */
- #define HANGUP_CHANNEL(channel, cause) \
- do { \
- ast_channel_hangupcause_set((channel), (cause)); \
- ast_hangup(channel); \
- channel = NULL; \
- } while (0)
- static enum ast_test_result_state verify_mock_cdr_record(struct ast_test *test, struct ast_cdr *expected, int record)
- {
- struct ast_cdr *actual = NULL;
- struct test_cdr_entry *cdr_wrapper;
- int count = 0;
- struct timeval wait_now = ast_tvnow();
- struct timespec wait_time = { .tv_sec = wait_now.tv_sec + 5, .tv_nsec = wait_now.tv_usec * 1000 };
- enum ast_test_result_state res = AST_TEST_PASS;
- while (count < record) {
- AST_LIST_LOCK(&actual_cdr_entries);
- if (global_mock_cdr_count < record) {
- ast_cond_timedwait(&mock_cdr_cond, &actual_cdr_entries.lock, &wait_time);
- }
- cdr_wrapper = AST_LIST_REMOVE_HEAD(&actual_cdr_entries, list);
- AST_LIST_UNLOCK(&actual_cdr_entries);
- if (!cdr_wrapper) {
- ast_test_status_update(test, "Unable to find actual CDR record at %d\n", count);
- return AST_TEST_FAIL;
- }
- actual = cdr_wrapper->cdr;
- if (!expected && actual) {
- ast_test_status_update(test, "CDRs recorded where no record expected\n");
- return AST_TEST_FAIL;
- }
- ast_test_debug(test, "Verifying expected record %s, %s\n",
- expected->channel, S_OR(expected->dstchannel, "<none>"));
- VERIFY_STRING_FIELD(accountcode, actual, expected);
- VERIFY_NUMERIC_FIELD(amaflags, actual, expected);
- VERIFY_STRING_FIELD(channel, actual, expected);
- VERIFY_STRING_FIELD(clid, actual, expected);
- VERIFY_STRING_FIELD(dcontext, actual, expected);
- VERIFY_NUMERIC_FIELD(disposition, actual, expected);
- VERIFY_STRING_FIELD(dst, actual, expected);
- VERIFY_STRING_FIELD(dstchannel, actual, expected);
- VERIFY_STRING_FIELD(lastapp, actual, expected);
- VERIFY_STRING_FIELD(lastdata, actual, expected);
- VERIFY_STRING_FIELD(linkedid, actual, expected);
- VERIFY_STRING_FIELD(peeraccount, actual, expected);
- VERIFY_STRING_FIELD(src, actual, expected);
- VERIFY_STRING_FIELD(uniqueid, actual, expected);
- VERIFY_STRING_FIELD(userfield, actual, expected);
- VERIFY_TIME_VALUE(start, actual);
- VERIFY_TIME_VALUE(end, actual);
- /* Note: there's no way we can really calculate a duration or
- * billsec - the unit tests are too short. However, if billsec is
- * non-zero in the expected, then make sure we have an answer time
- */
- if (expected->billsec) {
- VERIFY_TIME_VALUE(answer, actual);
- }
- ast_test_debug(test, "Finished expected record %s, %s\n",
- expected->channel, S_OR(expected->dstchannel, "<none>"));
- expected = expected->next;
- ++count;
- }
- return res;
- }
- static void safe_channel_release(struct ast_channel *chan)
- {
- if (!chan) {
- return;
- }
- ast_channel_release(chan);
- }
- static void safe_bridge_destroy(struct ast_bridge *bridge)
- {
- if (!bridge) {
- return;
- }
- ast_bridge_destroy(bridge, 0);
- }
- static void do_sleep(struct timespec *to_sleep)
- {
- while ((nanosleep(to_sleep, to_sleep) == -1) && (errno == EINTR)) {
- }
- }
- AST_TEST_DEFINE(test_cdr_channel_creation)
- {
- RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct ast_party_caller caller = ALICE_CALLERID;
- struct ast_cdr expected = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_NOANSWER,
- .accountcode = "100",
- };
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test that a CDR is created when a channel is created";
- info->description =
- "Test that a CDR is created when a channel is created";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, unanswered_cdr_config);
- CREATE_ALICE_CHANNEL(chan, (&caller), &expected);
- HANGUP_CHANNEL(chan, AST_CAUSE_NORMAL);
- result = verify_mock_cdr_record(test, &expected, 1);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_unanswered_inbound_call)
- {
- RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct ast_party_caller caller = ALICE_CALLERID;
- struct ast_cdr expected = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .lastapp = "Wait",
- .lastdata = "1",
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_NOANSWER,
- .accountcode = "100",
- };
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test inbound unanswered calls";
- info->description =
- "Test the properties of a CDR for a call that is\n"
- "inbound to Asterisk, executes some dialplan, but\n"
- "is never answered.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, unanswered_cdr_config);
- CREATE_ALICE_CHANNEL(chan, &caller, &expected);
- EMULATE_APP_DATA(chan, 1, "Wait", "1");
- HANGUP_CHANNEL(chan, AST_CAUSE_NORMAL);
- result = verify_mock_cdr_record(test, &expected, 1);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_unanswered_outbound_call)
- {
- RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct ast_party_caller caller = {
- .id.name.str = "",
- .id.name.valid = 1,
- .id.number.str = "",
- .id.number.valid = 1, };
- struct ast_cdr expected = {
- .clid = "\"\" <>",
- .dst = "s",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .lastapp = "AppDial",
- .lastdata = "(Outgoing Line)",
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_NOANSWER,
- .accountcode = "100",
- };
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test outbound unanswered calls";
- info->description =
- "Test the properties of a CDR for a call that is\n"
- "outbound to Asterisk but is never answered.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, unanswered_cdr_config);
- CREATE_ALICE_CHANNEL(chan, &caller, &expected);
- ast_channel_exten_set(chan, "s");
- ast_channel_context_set(chan, "default");
- ast_set_flag(ast_channel_flags(chan), AST_FLAG_ORIGINATED);
- EMULATE_APP_DATA(chan, 0, "AppDial", "(Outgoing Line)");
- HANGUP_CHANNEL(chan, AST_CAUSE_NORMAL);
- result = verify_mock_cdr_record(test, &expected, 1);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_outbound_bridged_call)
- {
- RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
- RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
- RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct timespec to_sleep = {1, 0};
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- struct ast_party_caller caller = ALICE_CALLERID;
- struct ast_cdr alice_expected = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .dstchannel = CHANNEL_TECH_NAME "/Bob",
- .lastapp = "",
- .lastdata = "",
- .amaflags = AST_AMA_DOCUMENTATION,
- .billsec = 1,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "100",
- .peeraccount = "200",
- };
- struct ast_cdr bob_expected = {
- .clid = "\"\" <>",
- .src = "",
- .dst = "s",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Bob",
- .dstchannel = "",
- .lastapp = "AppDial",
- .lastdata = "(Outgoing Line)",
- .amaflags = AST_AMA_DOCUMENTATION,
- .billsec = 1,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "200",
- .peeraccount = "",
- .next = &alice_expected,
- };
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test dialing, answering, and going into a 2-party bridge";
- info->description =
- "The most 'basic' of scenarios";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, debug_cdr_config);
- CREATE_ALICE_CHANNEL(chan_alice, &caller, &alice_expected);
- ast_channel_state_set(chan_alice, AST_STATE_UP);
- bridge = ast_bridge_basic_new();
- ast_test_validate(test, bridge != NULL);
- do_sleep(&to_sleep);
- ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- chan_bob = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, NULL, chan_alice, 0, CHANNEL_TECH_NAME "/Bob");
- SET_FORMATS(chan_bob);
- ast_channel_unlock(chan_bob);
- ast_copy_string(bob_expected.linkedid, ast_channel_linkedid(chan_bob), sizeof(bob_expected.linkedid));
- ast_copy_string(bob_expected.uniqueid, ast_channel_uniqueid(chan_bob), sizeof(bob_expected.uniqueid));
- ast_set_flag(ast_channel_flags(chan_bob), AST_FLAG_OUTGOING);
- ast_set_flag(ast_channel_flags(chan_bob), AST_FLAG_ORIGINATED);
- EMULATE_APP_DATA(chan_bob, 0, "AppDial", "(Outgoing Line)");
- ast_channel_publish_dial(NULL, chan_bob, "Bob", NULL);
- ast_channel_state_set(chan_bob, AST_STATE_RINGING);
- ast_channel_publish_dial(NULL, chan_bob, NULL, "ANSWER");
- ast_channel_state_set(chan_bob, AST_STATE_UP);
- do_sleep(&to_sleep);
- ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- do_sleep(&to_sleep);
- ast_bridge_depart(chan_bob);
- ast_bridge_depart(chan_alice);
- HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL);
- HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL);
- result = verify_mock_cdr_record(test, &bob_expected, 2);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_single_party)
- {
- RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct ast_party_caller caller = ALICE_CALLERID;
- struct ast_cdr expected = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .dstchannel = "",
- .lastapp = "VoiceMailMain",
- .lastdata = "1",
- .billsec = 1,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "100",
- };
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test cdrs for a single party";
- info->description =
- "Test the properties of a CDR for a call that is\n"
- "answered, but only involves a single channel";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, debug_cdr_config);
- CREATE_ALICE_CHANNEL(chan, &caller, &expected);
- ast_channel_lock(chan);
- EMULATE_APP_DATA(chan, 1, "Answer", "");
- ast_setstate(chan, AST_STATE_UP);
- EMULATE_APP_DATA(chan, 2, "VoiceMailMain", "1");
- ast_channel_unlock(chan);
- HANGUP_CHANNEL(chan, AST_CAUSE_NORMAL);
- result = verify_mock_cdr_record(test, &expected, 1);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_single_bridge)
- {
- RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
- RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct timespec to_sleep = {1, 0};
- struct ast_party_caller caller = ALICE_CALLERID;
- struct ast_cdr expected = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .lastapp = "Bridge",
- .billsec = 1,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "100",
- };
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test cdrs for a single party entering/leaving a bridge";
- info->description =
- "Test the properties of a CDR for a call that is\n"
- "answered, enters a bridge, and leaves it.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, debug_cdr_config);
- CREATE_ALICE_CHANNEL(chan, &caller, &expected);
- ast_channel_lock(chan);
- EMULATE_APP_DATA(chan, 1, "Answer", "");
- ast_setstate(chan, AST_STATE_UP);
- EMULATE_APP_DATA(chan, 2, "Bridge", "");
- ast_channel_unlock(chan);
- bridge = ast_bridge_basic_new();
- ast_test_validate(test, bridge != NULL);
- do_sleep(&to_sleep);
- ast_test_validate(test, !ast_bridge_impart(bridge, chan, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- do_sleep(&to_sleep);
- ast_bridge_depart(chan);
- HANGUP_CHANNEL(chan, AST_CAUSE_NORMAL);
- result = verify_mock_cdr_record(test, &expected, 1);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_single_bridge_continue)
- {
- RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
- RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct timespec to_sleep = {1, 0};
- struct ast_party_caller caller = ALICE_CALLERID;
- struct ast_cdr expected_two = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .lastapp = "Wait",
- .billsec = 1,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "100",
- };
- struct ast_cdr expected_one = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .lastapp = "Bridge",
- .billsec = 1,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "100",
- .next = &expected_two,
- };
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test cdrs for a single party entering/leaving a bridge";
- info->description =
- "Test the properties of a CDR for a call that is\n"
- "answered, enters a bridge, and leaves it.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, debug_cdr_config);
- CREATE_ALICE_CHANNEL(chan, &caller, &expected_one);
- COPY_IDS(chan, &expected_two);
- ast_channel_lock(chan);
- EMULATE_APP_DATA(chan, 1, "Answer", "");
- ast_setstate(chan, AST_STATE_UP);
- EMULATE_APP_DATA(chan, 2, "Bridge", "");
- ast_channel_unlock(chan);
- bridge = ast_bridge_basic_new();
- ast_test_validate(test, bridge != NULL);
- do_sleep(&to_sleep);
- ast_test_validate(test, !ast_bridge_impart(bridge, chan, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- do_sleep(&to_sleep);
- ast_bridge_depart(chan);
- EMULATE_APP_DATA(chan, 3, "Wait", "");
- /* And then it hangs up */
- HANGUP_CHANNEL(chan, AST_CAUSE_NORMAL);
- result = verify_mock_cdr_record(test, &expected_one, 2);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_single_twoparty_bridge_a)
- {
- RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
- RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
- RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct timespec to_sleep = {1, 0};
- struct ast_party_caller caller_alice = ALICE_CALLERID;
- struct ast_party_caller caller_bob = BOB_CALLERID;
- struct ast_cdr bob_expected = {
- .clid = "\"Bob\" <200>",
- .src = "200",
- .dst = "200",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Bob",
- .lastapp = "Bridge",
- .billsec = 1,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "200",
- };
- struct ast_cdr alice_expected = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .dstchannel = CHANNEL_TECH_NAME "/Bob",
- .lastapp = "Bridge",
- .billsec = 1,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "100",
- .peeraccount = "200",
- .next = &bob_expected,
- };
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test cdrs for a single party entering/leaving a bridge";
- info->description =
- "Test the properties of a CDR for a call that is\n"
- "answered, enters a bridge, and leaves it. In this scenario, the\n"
- "Party A should answer the bridge first.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, debug_cdr_config);
- CREATE_ALICE_CHANNEL(chan_alice, &caller_alice, &alice_expected);
- CREATE_BOB_CHANNEL(chan_bob, &caller_bob, &bob_expected);
- ast_copy_string(bob_expected.linkedid, ast_channel_linkedid(chan_alice), sizeof(bob_expected.linkedid));
- ast_channel_lock(chan_alice);
- EMULATE_APP_DATA(chan_alice, 1, "Answer", "");
- ast_setstate(chan_alice, AST_STATE_UP);
- EMULATE_APP_DATA(chan_alice, 2, "Bridge", "");
- ast_channel_unlock(chan_alice);
- bridge = ast_bridge_basic_new();
- ast_test_validate(test, bridge != NULL);
- ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- do_sleep(&to_sleep);
- ast_channel_lock(chan_bob);
- EMULATE_APP_DATA(chan_bob, 1, "Answer", "");
- ast_setstate(chan_bob, AST_STATE_UP);
- EMULATE_APP_DATA(chan_bob, 2, "Bridge", "");
- ast_channel_unlock(chan_bob);
- ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- do_sleep(&to_sleep);
- ast_bridge_depart(chan_alice);
- ast_bridge_depart(chan_bob);
- HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL);
- HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL);
- result = verify_mock_cdr_record(test, &alice_expected, 2);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_single_twoparty_bridge_b)
- {
- RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
- RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
- RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct timespec to_sleep = {1, 0};
- struct ast_party_caller caller_alice = ALICE_CALLERID;
- struct ast_party_caller caller_bob = BOB_CALLERID;
- struct ast_cdr bob_expected = {
- .clid = "\"Bob\" <200>",
- .src = "200",
- .dst = "200",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Bob",
- .lastapp = "Bridge",
- .billsec = 1,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "200",
- };
- struct ast_cdr alice_expected = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .dstchannel = CHANNEL_TECH_NAME "/Bob",
- .lastapp = "Bridge",
- .billsec = 1,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "100",
- .peeraccount = "200",
- .next = &bob_expected,
- };
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test cdrs for a single party entering/leaving a bridge";
- info->description =
- "Test the properties of a CDR for a call that is\n"
- "answered, enters a bridge, and leaves it. In this scenario, the\n"
- "Party B should answer the bridge first.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, debug_cdr_config);
- CREATE_ALICE_CHANNEL(chan_alice, &caller_alice, &alice_expected);
- CREATE_BOB_CHANNEL(chan_bob, &caller_bob, &bob_expected);
- ast_copy_string(bob_expected.linkedid, ast_channel_linkedid(chan_alice), sizeof(bob_expected.linkedid));
- ast_channel_unlock(chan_alice);
- EMULATE_APP_DATA(chan_alice, 1, "Answer", "");
- ast_setstate(chan_alice, AST_STATE_UP);
- EMULATE_APP_DATA(chan_alice, 2, "Bridge", "");
- ast_channel_unlock(chan_alice);
- bridge = ast_bridge_basic_new();
- ast_test_validate(test, bridge != NULL);
- ast_channel_lock(chan_bob);
- EMULATE_APP_DATA(chan_bob, 1, "Answer", "");
- ast_setstate(chan_bob, AST_STATE_UP);
- EMULATE_APP_DATA(chan_bob, 2, "Bridge", "");
- ast_channel_unlock(chan_bob);
- do_sleep(&to_sleep);
- ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- do_sleep(&to_sleep);
- ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- do_sleep(&to_sleep);
- ast_bridge_depart(chan_alice);
- ast_bridge_depart(chan_bob);
- HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL);
- HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL);
- result = verify_mock_cdr_record(test, &alice_expected, 2);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_single_multiparty_bridge)
- {
- RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
- RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
- RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
- RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct timespec to_sleep = {1, 0};
- struct ast_party_caller caller_alice = ALICE_CALLERID;
- struct ast_party_caller caller_bob = BOB_CALLERID;
- struct ast_party_caller caller_charlie = CHARLIE_CALLERID;
- struct ast_cdr charlie_expected = {
- .clid = "\"Charlie\" <300>",
- .src = "300",
- .dst = "300",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Charlie",
- .lastapp = "Bridge",
- .billsec = 1,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "300",
- };
- struct ast_cdr bob_expected = {
- .clid = "\"Bob\" <200>",
- .src = "200",
- .dst = "200",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Bob",
- .dstchannel = CHANNEL_TECH_NAME "/Charlie",
- .lastapp = "Bridge",
- .billsec = 1,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "200",
- .peeraccount = "300",
- .next = &charlie_expected,
- };
- struct ast_cdr alice_expected_two = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .dstchannel = CHANNEL_TECH_NAME "/Charlie",
- .lastapp = "Bridge",
- .billsec = 1,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "100",
- .peeraccount = "300",
- .next = &bob_expected,
- };
- struct ast_cdr alice_expected_one = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .dstchannel = CHANNEL_TECH_NAME "/Bob",
- .lastapp = "Bridge",
- .billsec = 1,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "100",
- .peeraccount = "200",
- .next = &alice_expected_two,
- };
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test cdrs for a single party entering/leaving a multi-party bridge";
- info->description =
- "Test the properties of a CDR for a call that is\n"
- "answered, enters a bridge, and leaves it. A total of three\n"
- "parties perform this action.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, debug_cdr_config);
- CREATE_ALICE_CHANNEL(chan_alice, &caller_alice, &alice_expected_one);
- COPY_IDS(chan_alice, &alice_expected_two);
- CREATE_BOB_CHANNEL(chan_bob, &caller_bob, &bob_expected);
- ast_copy_string(bob_expected.linkedid, ast_channel_linkedid(chan_alice), sizeof(bob_expected.linkedid));
- CREATE_CHARLIE_CHANNEL(chan_charlie, &caller_charlie, &charlie_expected);
- ast_copy_string(charlie_expected.linkedid, ast_channel_linkedid(chan_alice), sizeof(charlie_expected.linkedid));
- ast_channel_lock(chan_alice);
- EMULATE_APP_DATA(chan_alice, 1, "Answer", "");
- ast_setstate(chan_alice, AST_STATE_UP);
- EMULATE_APP_DATA(chan_alice, 2, "Bridge", "");
- ast_channel_unlock(chan_alice);
- bridge = ast_bridge_basic_new();
- ast_test_validate(test, bridge != NULL);
- do_sleep(&to_sleep);
- ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- ast_channel_lock(chan_bob);
- EMULATE_APP_DATA(chan_bob, 1, "Answer", "");
- ast_setstate(chan_bob, AST_STATE_UP);
- EMULATE_APP_DATA(chan_bob, 2, "Bridge", "");
- ast_channel_unlock(chan_bob);
- do_sleep(&to_sleep);
- ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- do_sleep(&to_sleep);
- ast_channel_lock(chan_charlie);
- EMULATE_APP_DATA(chan_charlie, 1, "Answer", "");
- ast_setstate(chan_charlie, AST_STATE_UP);
- EMULATE_APP_DATA(chan_charlie, 2, "Bridge", "");
- ast_channel_unlock(chan_charlie);
- ast_test_validate(test, !ast_bridge_impart(bridge, chan_charlie, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- do_sleep(&to_sleep);
- ast_bridge_depart(chan_alice);
- ast_bridge_depart(chan_bob);
- ast_bridge_depart(chan_charlie);
- HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL);
- HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL);
- HANGUP_CHANNEL(chan_charlie, AST_CAUSE_NORMAL);
- result = verify_mock_cdr_record(test, &alice_expected_one, 4);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_dial_unanswered)
- {
- RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
- RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct ast_party_caller caller = ALICE_CALLERID;
- struct ast_cdr expected = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .dstchannel = CHANNEL_TECH_NAME "/Bob",
- .lastapp = "Dial",
- .lastdata = CHANNEL_TECH_NAME "/Bob",
- .billsec = 0,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_NOANSWER,
- .accountcode = "100",
- .peeraccount = "200",
- };
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test CDRs for a dial that isn't answered";
- info->description =
- "Test the properties of a CDR for a channel that\n"
- "performs a dial operation that isn't answered";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, unanswered_cdr_config);
- CREATE_ALICE_CHANNEL(chan_caller, &caller, &expected);
- EMULATE_APP_DATA(chan_caller, 1, "Dial", "CDRTestChannel/Bob");
- chan_callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/Bob");
- SET_FORMATS(chan_callee);
- ast_channel_unlock(chan_callee);
- ast_set_flag(ast_channel_flags(chan_callee), AST_FLAG_OUTGOING);
- EMULATE_APP_DATA(chan_callee, 0, "AppDial", "(Outgoing Line)");
- ast_channel_publish_dial(chan_caller, chan_callee, "Bob", NULL);
- ast_channel_state_set(chan_caller, AST_STATE_RINGING);
- ast_channel_publish_dial(chan_caller, chan_callee, NULL, "NOANSWER");
- HANGUP_CHANNEL(chan_caller, AST_CAUSE_NO_ANSWER);
- HANGUP_CHANNEL(chan_callee, AST_CAUSE_NO_ANSWER);
- result = verify_mock_cdr_record(test, &expected, 1);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_dial_busy)
- {
- RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
- RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct ast_party_caller caller = ALICE_CALLERID;
- struct ast_cdr expected = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .dstchannel = CHANNEL_TECH_NAME "/Bob",
- .lastapp = "Dial",
- .lastdata = CHANNEL_TECH_NAME "/Bob",
- .billsec = 0,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_BUSY,
- .accountcode = "100",
- .peeraccount = "200",
- };
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test CDRs for a dial that results in a busy";
- info->description =
- "Test the properties of a CDR for a channel that\n"
- "performs a dial operation to an endpoint that's busy";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, unanswered_cdr_config);
- CREATE_ALICE_CHANNEL(chan_caller, &caller, &expected);
- EMULATE_APP_DATA(chan_caller, 1, "Dial", CHANNEL_TECH_NAME "/Bob");
- chan_callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/Bob");
- SET_FORMATS(chan_callee);
- ast_channel_unlock(chan_callee);
- ast_set_flag(ast_channel_flags(chan_callee), AST_FLAG_OUTGOING);
- EMULATE_APP_DATA(chan_callee, 0, "AppDial", "(Outgoing Line)");
- ast_channel_publish_dial(chan_caller, chan_callee, "Bob", NULL);
- ast_channel_state_set(chan_caller, AST_STATE_RINGING);
- ast_channel_publish_dial(chan_caller, chan_callee, NULL, "BUSY");
- HANGUP_CHANNEL(chan_caller, AST_CAUSE_BUSY);
- HANGUP_CHANNEL(chan_callee, AST_CAUSE_BUSY);
- result = verify_mock_cdr_record(test, &expected, 1);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_dial_congestion)
- {
- RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
- RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct ast_party_caller caller = ALICE_CALLERID;
- struct ast_cdr expected = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .dstchannel = CHANNEL_TECH_NAME "/Bob",
- .lastapp = "Dial",
- .lastdata = CHANNEL_TECH_NAME "/Bob",
- .billsec = 0,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_CONGESTION,
- .accountcode = "100",
- .peeraccount = "200",
- };
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test CDRs for a dial that results in congestion";
- info->description =
- "Test the properties of a CDR for a channel that\n"
- "performs a dial operation to an endpoint that's congested";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, congestion_cdr_config);
- CREATE_ALICE_CHANNEL(chan_caller, &caller, &expected);
- EMULATE_APP_DATA(chan_caller, 1, "Dial", CHANNEL_TECH_NAME "/Bob");
- chan_callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/Bob");
- SET_FORMATS(chan_callee);
- ast_channel_unlock(chan_callee);
- ast_set_flag(ast_channel_flags(chan_callee), AST_FLAG_OUTGOING);
- EMULATE_APP_DATA(chan_callee, 0, "AppDial", "(Outgoing Line)");
- ast_channel_publish_dial(chan_caller, chan_callee, "Bob", NULL);
- ast_channel_state_set(chan_caller, AST_STATE_RINGING);
- ast_channel_publish_dial(chan_caller, chan_callee, NULL, "CONGESTION");
- HANGUP_CHANNEL(chan_caller, AST_CAUSE_CONGESTION);
- HANGUP_CHANNEL(chan_callee, AST_CAUSE_CONGESTION);
- result = verify_mock_cdr_record(test, &expected, 1);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_dial_unavailable)
- {
- RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
- RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct ast_party_caller caller = ALICE_CALLERID;
- struct ast_cdr expected = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .dstchannel = CHANNEL_TECH_NAME "/Bob",
- .lastapp = "Dial",
- .lastdata = CHANNEL_TECH_NAME "/Bob",
- .billsec = 0,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_FAILED,
- .accountcode = "100",
- .peeraccount = "200",
- };
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test CDRs for a dial that results in unavailable";
- info->description =
- "Test the properties of a CDR for a channel that\n"
- "performs a dial operation to an endpoint that's unavailable";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, unanswered_cdr_config);
- CREATE_ALICE_CHANNEL(chan_caller, &caller, &expected);
- EMULATE_APP_DATA(chan_caller, 1, "Dial", CHANNEL_TECH_NAME "/Bob");
- chan_callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/Bob");
- SET_FORMATS(chan_callee);
- ast_channel_unlock(chan_callee);
- ast_set_flag(ast_channel_flags(chan_callee), AST_FLAG_OUTGOING);
- EMULATE_APP_DATA(chan_callee, 0, "AppDial", "(Outgoing Line)");
- ast_channel_publish_dial(chan_caller, chan_callee, "Bob", NULL);
- ast_channel_state_set(chan_caller, AST_STATE_RINGING);
- ast_channel_publish_dial(chan_caller, chan_callee, NULL, "CHANUNAVAIL");
- HANGUP_CHANNEL(chan_caller, AST_CAUSE_NO_ROUTE_DESTINATION);
- HANGUP_CHANNEL(chan_callee, AST_CAUSE_NO_ROUTE_DESTINATION);
- result = verify_mock_cdr_record(test, &expected, 1);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_dial_caller_cancel)
- {
- RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
- RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct ast_party_caller caller = ALICE_CALLERID;
- struct ast_cdr expected = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .dstchannel = CHANNEL_TECH_NAME "/Bob",
- .lastapp = "Dial",
- .lastdata = CHANNEL_TECH_NAME "/Bob",
- .billsec = 0,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_NOANSWER,
- .accountcode = "100",
- .peeraccount = "200",
- };
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test CDRs for a dial where the caller cancels";
- info->description =
- "Test the properties of a CDR for a channel that\n"
- "performs a dial operation to an endpoint but then decides\n"
- "to hang up, cancelling the dial";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, unanswered_cdr_config);
- CREATE_ALICE_CHANNEL(chan_caller, &caller, &expected);
- EMULATE_APP_DATA(chan_caller, 1, "Dial", CHANNEL_TECH_NAME "/Bob");
- chan_callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/Bob");
- SET_FORMATS(chan_callee);
- ast_channel_unlock(chan_callee);
- ast_set_flag(ast_channel_flags(chan_callee), AST_FLAG_OUTGOING);
- EMULATE_APP_DATA(chan_callee, 0, "AppDial", "(Outgoing Line)");
- ast_channel_publish_dial(chan_caller, chan_callee, "Bob", NULL);
- ast_channel_state_set(chan_caller, AST_STATE_RINGING);
- ast_channel_publish_dial(chan_caller, chan_callee, NULL, "CANCEL");
- HANGUP_CHANNEL(chan_callee, AST_CAUSE_NORMAL);
- HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL);
- result = verify_mock_cdr_record(test, &expected, 1);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_dial_parallel_failed)
- {
- RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
- RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
- RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
- RAII_VAR(struct ast_channel *, chan_david, NULL, safe_channel_release);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct ast_party_caller caller = ALICE_CALLERID;
- struct ast_cdr bob_expected = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .dstchannel = CHANNEL_TECH_NAME "/Bob",
- .lastapp = "Dial",
- .lastdata = CHANNEL_TECH_NAME "/Bob&" CHANNEL_TECH_NAME "/Charlie&" CHANNEL_TECH_NAME "/David",
- .billsec = 0,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_NOANSWER,
- .accountcode = "100",
- .peeraccount = "200",
- };
- struct ast_cdr charlie_expected = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .dstchannel = CHANNEL_TECH_NAME "/Charlie",
- .lastapp = "Dial",
- .lastdata = CHANNEL_TECH_NAME "/Bob&" CHANNEL_TECH_NAME "/Charlie&" CHANNEL_TECH_NAME "/David",
- .billsec = 0,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_BUSY,
- .accountcode = "100",
- .peeraccount = "300",
- };
- struct ast_cdr david_expected = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .dstchannel = CHANNEL_TECH_NAME "/David",
- .lastapp = "Dial",
- .lastdata = CHANNEL_TECH_NAME "/Bob&" CHANNEL_TECH_NAME "/Charlie&" CHANNEL_TECH_NAME "/David",
- .billsec = 0,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_CONGESTION,
- .accountcode = "100",
- .peeraccount = "400",
- };
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- struct ast_cdr *expected = &bob_expected;
- bob_expected.next = &charlie_expected;
- charlie_expected.next = &david_expected;
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test a parallel dial where all channels fail to answer";
- info->description =
- "This tests dialing three parties: Bob, Charlie, David. Charlie\n"
- "returns BUSY; David returns CONGESTION; Bob fails to answer and\n"
- "Alice hangs up. Three records are created for Alice as a result.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, congestion_cdr_config);
- CREATE_ALICE_CHANNEL(chan_caller, &caller, &bob_expected);
- COPY_IDS(chan_caller, &charlie_expected);
- COPY_IDS(chan_caller, &david_expected);
- /* Channel enters Dial app */
- EMULATE_APP_DATA(chan_caller, 1, "Dial", CHANNEL_TECH_NAME "/Bob&" CHANNEL_TECH_NAME "/Charlie&" CHANNEL_TECH_NAME "/David");
- /* Outbound channels are created */
- chan_bob = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/Bob");
- SET_FORMATS(chan_bob);
- ast_channel_unlock(chan_bob);
- ast_set_flag(ast_channel_flags(chan_bob), AST_FLAG_OUTGOING);
- EMULATE_APP_DATA(chan_bob, 0, "AppDial", "(Outgoing Line)");
- chan_charlie = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "300", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/Charlie");
- SET_FORMATS(chan_charlie);
- ast_channel_unlock(chan_charlie);
- ast_set_flag(ast_channel_flags(chan_charlie), AST_FLAG_OUTGOING);
- EMULATE_APP_DATA(chan_charlie, 0, "AppDial", "(Outgoing Line)");
- chan_david = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "400", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/David");
- SET_FORMATS(chan_charlie);
- ast_channel_unlock(chan_david);
- ast_set_flag(ast_channel_flags(chan_david), AST_FLAG_OUTGOING);
- EMULATE_APP_DATA(chan_david, 0, "AppDial", "(Outgoing Line)");
- /* Dial starts */
- ast_channel_publish_dial(chan_caller, chan_bob, "Bob", NULL);
- ast_channel_publish_dial(chan_caller, chan_charlie, "Charlie", NULL);
- ast_channel_publish_dial(chan_caller, chan_david, "David", NULL);
- ast_channel_state_set(chan_caller, AST_STATE_RINGING);
- /* Charlie is busy */
- ast_channel_publish_dial(chan_caller, chan_charlie, NULL, "BUSY");
- HANGUP_CHANNEL(chan_charlie, AST_CAUSE_BUSY);
- /* David is congested */
- ast_channel_publish_dial(chan_caller, chan_david, NULL, "CONGESTION");
- HANGUP_CHANNEL(chan_david, AST_CAUSE_CONGESTION);
- /* Bob is canceled */
- ast_channel_publish_dial(chan_caller, chan_bob, NULL, "CANCEL");
- HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL);
- /* Alice hangs up */
- HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL);
- result = verify_mock_cdr_record(test, expected, 3);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_dial_answer_no_bridge)
- {
- RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
- RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct ast_party_caller caller = ALICE_CALLERID;
- struct ast_cdr bob_expected_one = {
- .clid = "\"\" <>",
- .src = "",
- .dst = "s",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Bob",
- .lastapp = "Wait",
- .lastdata = "1",
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "200",
- };
- struct ast_cdr alice_expected_two = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .lastapp = "Wait",
- .lastdata = "1",
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "100",
- .next = &bob_expected_one,
- };
- struct ast_cdr alice_expected_one = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .dstchannel = CHANNEL_TECH_NAME "/Bob",
- .lastapp = "Dial",
- .lastdata = CHANNEL_TECH_NAME "/Bob",
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "100",
- .peeraccount = "200",
- .next = &alice_expected_two,
- };
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test dialing, answering, and not going into a bridge.";
- info->description =
- "This is a weird one, but theoretically possible. You can perform\n"
- "a dial, then bounce both channels to different priorities and\n"
- "never have them enter a bridge together. Ew. This makes sure that\n"
- "when we answer, we get a CDR, it gets ended at that point, and\n"
- "that it gets finalized appropriately. We should get three CDRs in\n"
- "the end - one for the dial, and one for each CDR as they continued\n"
- "on.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, debug_cdr_config);
- CREATE_ALICE_CHANNEL(chan_caller, &caller, &alice_expected_one);
- COPY_IDS(chan_caller, &alice_expected_two);
- EMULATE_APP_DATA(chan_caller, 1, "Dial", CHANNEL_TECH_NAME "/Bob");
- chan_callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/Bob");
- SET_FORMATS(chan_callee);
- ast_channel_unlock(chan_callee);
- ast_set_flag(ast_channel_flags(chan_callee), AST_FLAG_OUTGOING);
- COPY_IDS(chan_callee, &bob_expected_one);
- ast_channel_publish_dial(chan_caller, chan_callee, "Bob", NULL);
- ast_channel_state_set(chan_caller, AST_STATE_RINGING);
- ast_channel_publish_dial(chan_caller, chan_callee, NULL, "ANSWER");
- ast_channel_state_set(chan_caller, AST_STATE_UP);
- ast_clear_flag(ast_channel_flags(chan_callee), AST_FLAG_OUTGOING);
- ast_channel_state_set(chan_callee, AST_STATE_UP);
- EMULATE_APP_DATA(chan_caller, 2, "Wait", "1");
- EMULATE_APP_DATA(chan_callee, 1, "Wait", "1");
- HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL);
- HANGUP_CHANNEL(chan_callee, AST_CAUSE_NORMAL);
- result = verify_mock_cdr_record(test, &alice_expected_one, 3);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_dial_answer_twoparty_bridge_a)
- {
- RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
- RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
- RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct timespec to_sleep = {1, 0};
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- struct ast_party_caller caller = ALICE_CALLERID;
- struct ast_cdr expected = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .dstchannel = CHANNEL_TECH_NAME "/Bob",
- .lastapp = "Dial",
- .lastdata = CHANNEL_TECH_NAME "/Bob",
- .amaflags = AST_AMA_DOCUMENTATION,
- .billsec = 1,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "100",
- .peeraccount = "200",
- };
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test dialing, answering, and going into a 2-party bridge";
- info->description =
- "The most 'basic' of scenarios";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, debug_cdr_config);
- CREATE_ALICE_CHANNEL(chan_caller, &caller, &expected);
- EMULATE_APP_DATA(chan_caller, 1, "Dial", CHANNEL_TECH_NAME "/Bob");
- chan_callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/Bob");
- SET_FORMATS(chan_callee);
- ast_channel_unlock(chan_callee);
- ast_set_flag(ast_channel_flags(chan_callee), AST_FLAG_OUTGOING);
- EMULATE_APP_DATA(chan_callee, 0, "AppDial", "(Outgoing Line)");
- ast_channel_publish_dial(chan_caller, chan_callee, "Bob", NULL);
- ast_channel_state_set(chan_caller, AST_STATE_RINGING);
- ast_channel_publish_dial(chan_caller, chan_callee, NULL, "ANSWER");
- ast_channel_state_set(chan_caller, AST_STATE_UP);
- ast_channel_state_set(chan_callee, AST_STATE_UP);
- bridge = ast_bridge_basic_new();
- ast_test_validate(test, bridge != NULL);
- do_sleep(&to_sleep);
- ast_test_validate(test, !ast_bridge_impart(bridge, chan_caller, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- ast_test_validate(test, !ast_bridge_impart(bridge, chan_callee, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- do_sleep(&to_sleep);
- ast_bridge_depart(chan_caller);
- ast_bridge_depart(chan_callee);
- HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL);
- HANGUP_CHANNEL(chan_callee, AST_CAUSE_NORMAL);
- result = verify_mock_cdr_record(test, &expected, 1);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_dial_answer_twoparty_bridge_b)
- {
- RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
- RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
- RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct timespec to_sleep = {1, 0};
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- struct ast_party_caller caller = ALICE_CALLERID;
- struct ast_cdr expected = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .dstchannel = CHANNEL_TECH_NAME "/Bob",
- .lastapp = "Dial",
- .lastdata = CHANNEL_TECH_NAME "/Bob",
- .amaflags = AST_AMA_DOCUMENTATION,
- .billsec = 1,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "100",
- .peeraccount = "200",
- };
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test dialing, answering, and going into a 2-party bridge";
- info->description =
- "The most 'basic' of scenarios";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, debug_cdr_config);
- CREATE_ALICE_CHANNEL(chan_caller, &caller, &expected);
- EMULATE_APP_DATA(chan_caller, 1, "Dial", CHANNEL_TECH_NAME "/Bob");
- chan_callee = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, NULL, chan_caller, 0, CHANNEL_TECH_NAME "/Bob");
- SET_FORMATS(chan_callee);
- ast_channel_unlock(chan_callee);
- ast_set_flag(ast_channel_flags(chan_callee), AST_FLAG_OUTGOING);
- EMULATE_APP_DATA(chan_callee, 0, "AppDial", "(Outgoing Line)");
- ast_channel_publish_dial(chan_caller, chan_callee, "Bob", NULL);
- ast_channel_state_set(chan_caller, AST_STATE_RINGING);
- ast_channel_publish_dial(chan_caller, chan_callee, NULL, "ANSWER");
- ast_channel_state_set(chan_caller, AST_STATE_UP);
- ast_channel_state_set(chan_callee, AST_STATE_UP);
- bridge = ast_bridge_basic_new();
- ast_test_validate(test, bridge != NULL);
- do_sleep(&to_sleep);
- ast_test_validate(test, !ast_bridge_impart(bridge, chan_callee, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- do_sleep(&to_sleep);
- ast_test_validate(test, !ast_bridge_impart(bridge, chan_caller, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- do_sleep(&to_sleep);
- ast_bridge_depart(chan_caller);
- ast_bridge_depart(chan_callee);
- HANGUP_CHANNEL(chan_caller, AST_CAUSE_NORMAL);
- HANGUP_CHANNEL(chan_callee, AST_CAUSE_NORMAL);
- result = verify_mock_cdr_record(test, &expected, 1);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_dial_answer_multiparty)
- {
- RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
- RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
- RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
- RAII_VAR(struct ast_channel *, chan_david, NULL, safe_channel_release);
- RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct timespec to_sleep = {1, 0};
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- struct ast_party_caller alice_caller = ALICE_CALLERID;
- struct ast_party_caller charlie_caller = CHARLIE_CALLERID;
- struct ast_cdr charlie_expected_two = {
- .clid = "\"Charlie\" <300>",
- .src = "300",
- .dst = "300",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Charlie",
- .dstchannel = CHANNEL_TECH_NAME "/Bob",
- .lastapp = "Dial",
- .lastdata = CHANNEL_TECH_NAME "/David",
- .amaflags = AST_AMA_DOCUMENTATION,
- .billsec = 1,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "300",
- .peeraccount = "200",
- };
- struct ast_cdr charlie_expected_one = {
- .clid = "\"Charlie\" <300>",
- .src = "300",
- .dst = "300",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Charlie",
- .dstchannel = CHANNEL_TECH_NAME "/David",
- .lastapp = "Dial",
- .lastdata = CHANNEL_TECH_NAME "/David",
- .amaflags = AST_AMA_DOCUMENTATION,
- .billsec = 1,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "300",
- .peeraccount = "400",
- .next = &charlie_expected_two,
- };
- struct ast_cdr bob_expected_one = {
- .clid = "\"Bob\" <200>",
- .src = "200",
- .dst = "200",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Bob",
- .dstchannel = CHANNEL_TECH_NAME "/David",
- .lastapp = "AppDial",
- .lastdata = "(Outgoing Line)",
- .amaflags = AST_AMA_DOCUMENTATION,
- .billsec = 1,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "200",
- .peeraccount = "400",
- .next = &charlie_expected_one,
- };
- struct ast_cdr alice_expected_three = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .dstchannel = CHANNEL_TECH_NAME "/David",
- .lastapp = "Dial",
- .lastdata = CHANNEL_TECH_NAME "/Bob",
- .amaflags = AST_AMA_DOCUMENTATION,
- .billsec = 1,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "100",
- .peeraccount = "400",
- .next = &bob_expected_one,
- };
- struct ast_cdr alice_expected_two = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .dstchannel = CHANNEL_TECH_NAME "/Charlie",
- .lastapp = "Dial",
- .lastdata = CHANNEL_TECH_NAME "/Bob",
- .amaflags = AST_AMA_DOCUMENTATION,
- .billsec = 1,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "100",
- .peeraccount = "300",
- .next = &alice_expected_three,
- };
- struct ast_cdr alice_expected_one = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .dstchannel = CHANNEL_TECH_NAME "/Bob",
- .lastapp = "Dial",
- .lastdata = CHANNEL_TECH_NAME "/Bob",
- .amaflags = AST_AMA_DOCUMENTATION,
- .billsec = 1,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "100",
- .peeraccount = "200",
- .next = &alice_expected_two,
- };
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test dialing, answering, and going into a multi-party bridge";
- info->description =
- "A little tricky to get to do, but possible with some redirects.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, debug_cdr_config);
- CREATE_ALICE_CHANNEL(chan_alice, &alice_caller, &alice_expected_one);
- COPY_IDS(chan_alice, &alice_expected_two);
- COPY_IDS(chan_alice, &alice_expected_three);
- EMULATE_APP_DATA(chan_alice, 1, "Dial", CHANNEL_TECH_NAME "/Bob");
- chan_bob = ast_channel_alloc(0, AST_STATE_DOWN, "200", "Bob", "200", "200", "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/Bob");
- SET_FORMATS(chan_bob);
- ast_channel_unlock(chan_bob);
- ast_set_flag(ast_channel_flags(chan_bob), AST_FLAG_OUTGOING);
- EMULATE_APP_DATA(chan_bob, 0, "AppDial", "(Outgoing Line)");
- ast_copy_string(bob_expected_one.uniqueid, ast_channel_uniqueid(chan_bob), sizeof(bob_expected_one.uniqueid));
- ast_copy_string(bob_expected_one.linkedid, ast_channel_linkedid(chan_alice), sizeof(bob_expected_one.linkedid));
- CREATE_CHARLIE_CHANNEL(chan_charlie, &charlie_caller, &charlie_expected_one);
- EMULATE_APP_DATA(chan_charlie, 1, "Dial", CHANNEL_TECH_NAME "/David");
- ast_copy_string(charlie_expected_one.uniqueid, ast_channel_uniqueid(chan_charlie), sizeof(charlie_expected_one.uniqueid));
- ast_copy_string(charlie_expected_one.linkedid, ast_channel_linkedid(chan_alice), sizeof(charlie_expected_one.linkedid));
- ast_copy_string(charlie_expected_two.uniqueid, ast_channel_uniqueid(chan_charlie), sizeof(charlie_expected_two.uniqueid));
- ast_copy_string(charlie_expected_two.linkedid, ast_channel_linkedid(chan_alice), sizeof(charlie_expected_two.linkedid));
- chan_david = ast_channel_alloc(0, AST_STATE_DOWN, "400", "David", "400", "400", "default", NULL, NULL, 0, CHANNEL_TECH_NAME "/David");
- SET_FORMATS(chan_david);
- ast_channel_unlock(chan_david);
- ast_set_flag(ast_channel_flags(chan_david), AST_FLAG_OUTGOING);
- EMULATE_APP_DATA(chan_david, 0, "AppDial", "(Outgoing Line)");
- ast_channel_publish_dial(chan_alice, chan_bob, "Bob", NULL);
- ast_channel_state_set(chan_alice, AST_STATE_RINGING);
- ast_channel_publish_dial(chan_charlie, chan_david, "David", NULL);
- ast_channel_state_set(chan_charlie, AST_STATE_RINGING);
- ast_channel_publish_dial(chan_alice, chan_bob, NULL, "ANSWER");
- ast_channel_publish_dial(chan_charlie, chan_david, NULL, "ANSWER");
- ast_channel_state_set(chan_alice, AST_STATE_UP);
- ast_channel_state_set(chan_bob, AST_STATE_UP);
- ast_channel_state_set(chan_charlie, AST_STATE_UP);
- ast_channel_state_set(chan_david, AST_STATE_UP);
- bridge = ast_bridge_basic_new();
- ast_test_validate(test, bridge != NULL);
- do_sleep(&to_sleep);
- ast_test_validate(test, !ast_bridge_impart(bridge, chan_charlie, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- do_sleep(&to_sleep);
- ast_test_validate(test, !ast_bridge_impart(bridge, chan_david, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- do_sleep(&to_sleep);
- ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- do_sleep(&to_sleep);
- ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- do_sleep(&to_sleep);
- ast_test_validate(test, !ast_bridge_depart(chan_alice));
- ast_test_validate(test, !ast_bridge_depart(chan_bob));
- ast_test_validate(test, !ast_bridge_depart(chan_charlie));
- ast_test_validate(test, !ast_bridge_depart(chan_david));
- HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL);
- HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL);
- HANGUP_CHANNEL(chan_charlie, AST_CAUSE_NORMAL);
- HANGUP_CHANNEL(chan_david, AST_CAUSE_NORMAL);
- result = verify_mock_cdr_record(test, &alice_expected_one, 6);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_park)
- {
- RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
- RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
- RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct timespec to_sleep = {1, 0};
- struct ast_party_caller bob_caller = BOB_CALLERID;
- struct ast_party_caller alice_caller = ALICE_CALLERID;
- struct ast_cdr bob_expected = {
- .clid = "\"Bob\" <200>",
- .src = "200",
- .dst = "200",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Bob",
- .lastapp = "Park",
- .lastdata = "701",
- .billsec = 1,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "200",
- };
- struct ast_cdr alice_expected = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .lastapp = "Park",
- .lastdata = "700",
- .billsec = 1,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "100",
- .next = &bob_expected,
- };
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test cdrs for a single party entering Park";
- info->description =
- "Test the properties of a CDR for calls that are\n"
- "answered, enters Park, and leaves it.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, debug_cdr_config);
- CREATE_ALICE_CHANNEL(chan_alice, &alice_caller, &alice_expected);
- CREATE_BOB_CHANNEL(chan_bob, &bob_caller, &bob_expected);
- ast_channel_lock(chan_alice);
- EMULATE_APP_DATA(chan_alice, 1, "Park", "700");
- ast_setstate(chan_alice, AST_STATE_UP);
- ast_channel_unlock(chan_alice);
- ast_channel_lock(chan_bob);
- EMULATE_APP_DATA(chan_bob, 1, "Park", "701");
- ast_setstate(chan_bob, AST_STATE_UP);
- ast_channel_unlock(chan_bob);
- bridge = ast_bridge_base_new(AST_BRIDGE_CAPABILITY_HOLDING,
- AST_BRIDGE_FLAG_MERGE_INHIBIT_TO | AST_BRIDGE_FLAG_MERGE_INHIBIT_FROM
- | AST_BRIDGE_FLAG_SWAP_INHIBIT_FROM | AST_BRIDGE_FLAG_TRANSFER_PROHIBITED,
- "test_cdr", "test_cdr_park", NULL);
- ast_test_validate(test, bridge != NULL);
- do_sleep(&to_sleep);
- ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- do_sleep(&to_sleep);
- ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
- do_sleep(&to_sleep);
- ast_bridge_depart(chan_alice);
- ast_bridge_depart(chan_bob);
- /* And then it hangs up */
- HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL);
- HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL);
- result = verify_mock_cdr_record(test, &alice_expected, 2);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_fields)
- {
- RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- char varbuffer[128];
- int int_buffer;
- double db_buffer;
- struct timespec to_sleep = {2, 0};
- struct ast_flags fork_options = { 0, };
- struct ast_party_caller caller = ALICE_CALLERID;
- struct ast_cdr original = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .lastapp = "Wait",
- .lastdata = "10",
- .billsec = 0,
- .amaflags = AST_AMA_OMIT,
- .disposition = AST_CDR_FAILED,
- .accountcode = "XXX",
- .userfield = "yackity",
- };
- struct ast_cdr fork_expected_one = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .lastapp = "Wait",
- .lastdata = "10",
- .billsec = 0,
- .amaflags = AST_AMA_OMIT,
- .disposition = AST_CDR_FAILED,
- .accountcode = "XXX",
- .userfield = "yackity",
- };
- struct ast_cdr fork_expected_two = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .lastapp = "Answer",
- .billsec = 0,
- .amaflags = AST_AMA_OMIT,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "ZZZ",
- .userfield = "schmackity",
- };
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- struct ast_cdr *expected = &original;
- original.next = &fork_expected_one;
- fork_expected_one.next = &fork_expected_two;
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test field access CDRs";
- info->description =
- "This tests setting/retrieving data on CDR records.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, unanswered_cdr_config);
- CREATE_ALICE_CHANNEL(chan, &caller, &original);
- ast_copy_string(fork_expected_one.uniqueid, ast_channel_uniqueid(chan), sizeof(fork_expected_one.uniqueid));
- ast_copy_string(fork_expected_one.linkedid, ast_channel_linkedid(chan), sizeof(fork_expected_one.linkedid));
- ast_copy_string(fork_expected_two.uniqueid, ast_channel_uniqueid(chan), sizeof(fork_expected_two.uniqueid));
- ast_copy_string(fork_expected_two.linkedid, ast_channel_linkedid(chan), sizeof(fork_expected_two.linkedid));
- /* Channel enters Wait app */
- ast_channel_lock(chan);
- ast_channel_appl_set(chan, "Wait");
- ast_channel_data_set(chan, "10");
- ast_channel_priority_set(chan, 1);
- ast_channel_publish_snapshot(chan);
- /* Set properties on the channel that propagate to the CDR */
- ast_channel_amaflags_set(chan, AST_AMA_OMIT);
- ast_channel_accountcode_set(chan, "XXX");
- ast_channel_unlock(chan);
- /* Wait one second so we get a duration. */
- do_sleep(&to_sleep);
- ast_cdr_setuserfield(ast_channel_name(chan), "foobar");
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "test_variable", "record_1") == 0);
- /* Verify that we can't set read-only fields or other fields directly */
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "clid", "junk") != 0);
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "src", "junk") != 0);
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "dst", "junk") != 0);
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "dcontext", "junk") != 0);
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "channel", "junk") != 0);
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "dstchannel", "junk") != 0);
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "lastapp", "junk") != 0);
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "lastdata", "junk") != 0);
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "start", "junk") != 0);
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "answer", "junk") != 0);
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "end", "junk") != 0);
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "duration", "junk") != 0);
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "billsec", "junk") != 0);
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "disposition", "junk") != 0);
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "amaflags", "junk") != 0);
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "accountcode", "junk") != 0);
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "uniqueid", "junk") != 0);
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "linkedid", "junk") != 0);
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "userfield", "junk") != 0);
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "sequence", "junk") != 0);
- /* Verify the values */
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "userfield", varbuffer, sizeof(varbuffer)) == 0);
- ast_test_validate(test, strcmp(varbuffer, "foobar") == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "test_variable", varbuffer, sizeof(varbuffer)) == 0);
- ast_test_validate(test, strcmp(varbuffer, "record_1") == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "amaflags", varbuffer, sizeof(varbuffer)) == 0);
- sscanf(varbuffer, "%d", &int_buffer);
- ast_test_validate(test, int_buffer == AST_AMA_OMIT);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "accountcode", varbuffer, sizeof(varbuffer)) == 0);
- ast_test_validate(test, strcmp(varbuffer, "XXX") == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "clid", varbuffer, sizeof(varbuffer)) == 0);
- ast_test_validate(test, strcmp(varbuffer, "\"Alice\" <100>") == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "src", varbuffer, sizeof(varbuffer)) == 0);
- ast_test_validate(test, strcmp(varbuffer, "100") == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "dst", varbuffer, sizeof(varbuffer)) == 0);
- ast_test_validate(test, strcmp(varbuffer, "100") == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "dcontext", varbuffer, sizeof(varbuffer)) == 0);
- ast_test_validate(test, strcmp(varbuffer, "default") == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "channel", varbuffer, sizeof(varbuffer)) == 0);
- ast_test_validate(test, strcmp(varbuffer, CHANNEL_TECH_NAME "/Alice") == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "dstchannel", varbuffer, sizeof(varbuffer)) == 0);
- ast_test_validate(test, strcmp(varbuffer, "") == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "lastapp", varbuffer, sizeof(varbuffer)) == 0);
- ast_test_validate(test, strcmp(varbuffer, "Wait") == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "lastdata", varbuffer, sizeof(varbuffer)) == 0);
- ast_test_validate(test, strcmp(varbuffer, "10") == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "start", varbuffer, sizeof(varbuffer)) == 0);
- sscanf(varbuffer, "%lf", &db_buffer);
- ast_test_validate(test, fabs(db_buffer) > 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "answer", varbuffer, sizeof(varbuffer)) == 0);
- sscanf(varbuffer, "%lf", &db_buffer);
- ast_test_validate(test, fabs(db_buffer) < EPSILON);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "end", varbuffer, sizeof(varbuffer)) == 0);
- sscanf(varbuffer, "%lf", &db_buffer);
- ast_test_validate(test, fabs(db_buffer) < EPSILON);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "duration", varbuffer, sizeof(varbuffer)) == 0);
- sscanf(varbuffer, "%lf", &db_buffer);
- ast_test_validate(test, fabs(db_buffer) > 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "billsec", varbuffer, sizeof(varbuffer)) == 0);
- sscanf(varbuffer, "%lf", &db_buffer);
- ast_test_validate(test, fabs(db_buffer) < EPSILON);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "disposition", varbuffer, sizeof(varbuffer)) == 0);
- sscanf(varbuffer, "%d", &int_buffer);
- ast_test_validate(test, int_buffer == AST_CDR_NULL);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "uniqueid", varbuffer, sizeof(varbuffer)) == 0);
- ast_test_validate(test, strcmp(varbuffer, ast_channel_uniqueid(chan)) == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "linkedid", varbuffer, sizeof(varbuffer)) == 0);
- ast_test_validate(test, strcmp(varbuffer, ast_channel_linkedid(chan)) == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "sequence", varbuffer, sizeof(varbuffer)) == 0);
- /* Fork the CDR, and check that we change the properties on both CDRs. */
- ast_set_flag(&fork_options, AST_CDR_FLAG_KEEP_VARS);
- ast_test_validate(test, ast_cdr_fork(ast_channel_name(chan), &fork_options) == 0);
- /* Change some properties */
- ast_cdr_setuserfield(ast_channel_name(chan), "yackity");
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "test_variable", "record_1b") == 0);
- /* Fork the CDR again, finalizing all current CDRs */
- ast_set_flag(&fork_options, AST_CDR_FLAG_KEEP_VARS | AST_CDR_FLAG_FINALIZE);
- ast_test_validate(test, ast_cdr_fork(ast_channel_name(chan), &fork_options) == 0);
- /* Channel enters Answer app */
- ast_channel_lock(chan);
- ast_channel_appl_set(chan, "Answer");
- ast_channel_data_set(chan, "");
- ast_channel_priority_set(chan, 1);
- ast_channel_publish_snapshot(chan);
- ast_setstate(chan, AST_STATE_UP);
- /* Set properties on the last record */
- ast_channel_accountcode_set(chan, "ZZZ");
- ast_channel_unlock(chan);
- ast_cdr_setuserfield(ast_channel_name(chan), "schmackity");
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "test_variable", "record_2") == 0);
- /* Hang up and verify */
- ast_channel_hangupcause_set(chan, AST_CAUSE_NORMAL);
- ast_hangup(chan);
- chan = NULL;
- result = verify_mock_cdr_record(test, expected, 3);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_no_reset_cdr)
- {
- RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- struct ast_flags fork_options = { 0, };
- struct timespec to_sleep = {1, 0};
- struct ast_party_caller caller = ALICE_CALLERID;
- struct ast_cdr expected = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .billsec = 0,
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_FAILED,
- .accountcode = "100",
- };
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test field access CDRs";
- info->description =
- "This tests setting/retrieving data on CDR records.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, unanswered_cdr_config);
- CREATE_ALICE_CHANNEL(chan, &caller, &expected);
- do_sleep(&to_sleep);
- /* Disable the CDR */
- ast_test_validate(test, ast_cdr_set_property(ast_channel_name(chan), AST_CDR_FLAG_DISABLE) == 0);
- /* Fork the CDR. This should be enabled */
- ast_set_flag(&fork_options, AST_CDR_FLAG_FINALIZE);
- ast_test_validate(test, ast_cdr_fork(ast_channel_name(chan), &fork_options) == 0);
- /* Disable and enable the forked CDR */
- ast_test_validate(test, ast_cdr_set_property(ast_channel_name(chan), AST_CDR_FLAG_DISABLE) == 0);
- ast_test_validate(test, ast_cdr_clear_property(ast_channel_name(chan), AST_CDR_FLAG_DISABLE) == 0);
- /* Fork and finalize again. This CDR should be propagated */
- ast_test_validate(test, ast_cdr_fork(ast_channel_name(chan), &fork_options) == 0);
- /* Disable all future CDRs */
- ast_test_validate(test, ast_cdr_set_property(ast_channel_name(chan), AST_CDR_FLAG_DISABLE_ALL) == 0);
- /* Fork a few more */
- ast_test_validate(test, ast_cdr_fork(ast_channel_name(chan), &fork_options) == 0);
- ast_test_validate(test, ast_cdr_fork(ast_channel_name(chan), &fork_options) == 0);
- ast_test_validate(test, ast_cdr_fork(ast_channel_name(chan), &fork_options) == 0);
- ast_channel_hangupcause_set(chan, AST_CAUSE_NORMAL);
- ast_hangup(chan);
- chan = NULL;
- result = verify_mock_cdr_record(test, &expected, 1);
- return result;
- }
- AST_TEST_DEFINE(test_cdr_fork_cdr)
- {
- RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
- RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
- ao2_cleanup);
- char varbuffer[128];
- char fork_varbuffer[128];
- char answer_time[128];
- char fork_answer_time[128];
- char start_time[128];
- char fork_start_time[128];
- struct ast_flags fork_options = { 0, };
- struct timespec to_sleep = {1, 10000};
- struct ast_party_caller caller = ALICE_CALLERID;
- struct ast_cdr original = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "100",
- };
- struct ast_cdr fork_expected_one = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "100",
- };
- struct ast_cdr fork_expected_two = {
- .clid = "\"Alice\" <100>",
- .src = "100",
- .dst = "100",
- .dcontext = "default",
- .channel = CHANNEL_TECH_NAME "/Alice",
- .amaflags = AST_AMA_DOCUMENTATION,
- .disposition = AST_CDR_ANSWERED,
- .accountcode = "100",
- };
- enum ast_test_result_state result = AST_TEST_NOT_RUN;
- struct ast_cdr *expected = &original;
- original.next = &fork_expected_one;
- fork_expected_one.next = &fork_expected_two;
- switch (cmd) {
- case TEST_INIT:
- info->name = __func__;
- info->category = TEST_CATEGORY;
- info->summary = "Test field access CDRs";
- info->description =
- "This tests setting/retrieving data on CDR records.";
- return AST_TEST_NOT_RUN;
- case TEST_EXECUTE:
- break;
- }
- SWAP_CONFIG(config, debug_cdr_config);
- CREATE_ALICE_CHANNEL(chan, &caller, &original);
- ast_copy_string(fork_expected_one.uniqueid, ast_channel_uniqueid(chan), sizeof(fork_expected_one.uniqueid));
- ast_copy_string(fork_expected_one.linkedid, ast_channel_linkedid(chan), sizeof(fork_expected_one.linkedid));
- ast_copy_string(fork_expected_two.uniqueid, ast_channel_uniqueid(chan), sizeof(fork_expected_two.uniqueid));
- ast_copy_string(fork_expected_two.linkedid, ast_channel_linkedid(chan), sizeof(fork_expected_two.linkedid));
- do_sleep(&to_sleep);
- /* Test blowing away variables */
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "test_variable", "record_1") == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "test_variable", varbuffer, sizeof(varbuffer)) == 0);
- ast_test_validate(test, strcmp(varbuffer, "record_1") == 0);
- ast_copy_string(varbuffer, "", sizeof(varbuffer));
- ast_test_validate(test, ast_cdr_fork(ast_channel_name(chan), &fork_options) == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "test_variable", fork_varbuffer, sizeof(fork_varbuffer)) == 0);
- ast_test_validate(test, strcmp(varbuffer, "record_1") != 0);
- /* Test finalizing previous CDRs */
- ast_set_flag(&fork_options, AST_CDR_FLAG_FINALIZE);
- ast_test_validate(test, ast_cdr_fork(ast_channel_name(chan), &fork_options) == 0);
- /* Test keep variables; setting a new answer time */
- ast_channel_lock(chan);
- ast_setstate(chan, AST_STATE_UP);
- ast_channel_unlock(chan);
- do_sleep(&to_sleep);
- ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "test_variable", "record_2") == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "test_variable", varbuffer, sizeof(varbuffer)) == 0);
- ast_test_validate(test, strcmp(varbuffer, "record_2") == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "answer", answer_time, sizeof(answer_time)) == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "start", start_time, sizeof(start_time)) == 0);
- ast_set_flag(&fork_options, AST_CDR_FLAG_FINALIZE);
- ast_set_flag(&fork_options, AST_CDR_FLAG_KEEP_VARS);
- ast_set_flag(&fork_options, AST_CDR_FLAG_SET_ANSWER);
- ast_test_validate(test, ast_cdr_fork(ast_channel_name(chan), &fork_options) == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "answer", fork_answer_time, sizeof(fork_answer_time)) == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "start", fork_start_time, sizeof(fork_start_time)) == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "test_variable", fork_varbuffer, sizeof(fork_varbuffer)) == 0);
- ast_test_validate(test, strcmp(fork_varbuffer, varbuffer) == 0);
- ast_test_validate(test, strcmp(fork_start_time, start_time) == 0);
- ast_test_validate(test, strcmp(fork_answer_time, answer_time) != 0);
- ast_clear_flag(&fork_options, AST_CDR_FLAG_SET_ANSWER);
- ast_set_flag(&fork_options, AST_CDR_FLAG_RESET);
- ast_test_validate(test, ast_cdr_fork(ast_channel_name(chan), &fork_options) == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "answer", fork_answer_time, sizeof(fork_answer_time)) == 0);
- ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "start", fork_start_time, sizeof(fork_start_time)) == 0);
- ast_test_validate(test, strcmp(fork_start_time, start_time) != 0);
- ast_test_validate(test, strcmp(fork_answer_time, answer_time) != 0);
- ast_channel_hangupcause_set(chan, AST_CAUSE_NORMAL);
- ast_hangup(chan);
- chan = NULL;
- result = verify_mock_cdr_record(test, expected, 3);
- return result;
- }
- /*!
- * \internal
- * \brief Callback function called before each test executes
- */
- static int test_cdr_init_cb(struct ast_test_info *info, struct ast_test *test)
- {
- /* Back up the real config */
- saved_config = ast_cdr_get_config();
- clear_mock_cdr_backend();
- return 0;
- }
- /*!
- * \internal
- * \brief Callback function called after each test executes
- */
- static int test_cdr_cleanup_cb(struct ast_test_info *info, struct ast_test *test)
- {
- /* Restore the real config */
- ast_cdr_set_config(saved_config);
- ao2_cleanup(saved_config);
- saved_config = NULL;
- clear_mock_cdr_backend();
- return 0;
- }
- static int unload_module(void)
- {
- AST_TEST_UNREGISTER(test_cdr_channel_creation);
- AST_TEST_UNREGISTER(test_cdr_unanswered_inbound_call);
- AST_TEST_UNREGISTER(test_cdr_unanswered_outbound_call);
- AST_TEST_UNREGISTER(test_cdr_single_party);
- AST_TEST_UNREGISTER(test_cdr_single_bridge);
- AST_TEST_UNREGISTER(test_cdr_single_bridge_continue);
- AST_TEST_UNREGISTER(test_cdr_single_twoparty_bridge_a);
- AST_TEST_UNREGISTER(test_cdr_single_twoparty_bridge_b);
- AST_TEST_UNREGISTER(test_cdr_single_multiparty_bridge);
- AST_TEST_UNREGISTER(test_cdr_outbound_bridged_call);
- AST_TEST_UNREGISTER(test_cdr_dial_unanswered);
- AST_TEST_UNREGISTER(test_cdr_dial_congestion);
- AST_TEST_UNREGISTER(test_cdr_dial_busy);
- AST_TEST_UNREGISTER(test_cdr_dial_unavailable);
- AST_TEST_UNREGISTER(test_cdr_dial_caller_cancel);
- AST_TEST_UNREGISTER(test_cdr_dial_parallel_failed);
- AST_TEST_UNREGISTER(test_cdr_dial_answer_no_bridge);
- AST_TEST_UNREGISTER(test_cdr_dial_answer_twoparty_bridge_a);
- AST_TEST_UNREGISTER(test_cdr_dial_answer_twoparty_bridge_b);
- AST_TEST_UNREGISTER(test_cdr_dial_answer_multiparty);
- AST_TEST_UNREGISTER(test_cdr_park);
- AST_TEST_UNREGISTER(test_cdr_fields);
- AST_TEST_UNREGISTER(test_cdr_no_reset_cdr);
- AST_TEST_UNREGISTER(test_cdr_fork_cdr);
- ast_cdr_unregister(MOCK_CDR_BACKEND);
- ast_channel_unregister(&test_cdr_chan_tech);
- clear_mock_cdr_backend();
- return 0;
- }
- static int load_module(void)
- {
- ast_cond_init(&mock_cdr_cond, NULL);
- AST_TEST_REGISTER(test_cdr_channel_creation);
- AST_TEST_REGISTER(test_cdr_unanswered_inbound_call);
- AST_TEST_REGISTER(test_cdr_unanswered_outbound_call);
- AST_TEST_REGISTER(test_cdr_single_party);
- AST_TEST_REGISTER(test_cdr_single_bridge);
- AST_TEST_REGISTER(test_cdr_single_bridge_continue);
- AST_TEST_REGISTER(test_cdr_single_twoparty_bridge_a);
- AST_TEST_REGISTER(test_cdr_single_twoparty_bridge_b);
- AST_TEST_REGISTER(test_cdr_single_multiparty_bridge);
- AST_TEST_REGISTER(test_cdr_outbound_bridged_call);
- AST_TEST_REGISTER(test_cdr_dial_unanswered);
- AST_TEST_REGISTER(test_cdr_dial_congestion);
- AST_TEST_REGISTER(test_cdr_dial_busy);
- AST_TEST_REGISTER(test_cdr_dial_unavailable);
- AST_TEST_REGISTER(test_cdr_dial_caller_cancel);
- AST_TEST_REGISTER(test_cdr_dial_parallel_failed);
- AST_TEST_REGISTER(test_cdr_dial_answer_no_bridge);
- AST_TEST_REGISTER(test_cdr_dial_answer_twoparty_bridge_a);
- AST_TEST_REGISTER(test_cdr_dial_answer_twoparty_bridge_b);
- AST_TEST_REGISTER(test_cdr_dial_answer_multiparty);
- AST_TEST_REGISTER(test_cdr_park);
- AST_TEST_REGISTER(test_cdr_fields);
- AST_TEST_REGISTER(test_cdr_no_reset_cdr);
- AST_TEST_REGISTER(test_cdr_fork_cdr);
- ast_test_register_init(TEST_CATEGORY, test_cdr_init_cb);
- ast_test_register_cleanup(TEST_CATEGORY, test_cdr_cleanup_cb);
- ast_channel_register(&test_cdr_chan_tech);
- ast_cdr_register(MOCK_CDR_BACKEND, "Mock CDR backend", mock_cdr_backend_cb);
- return AST_MODULE_LOAD_SUCCESS;
- }
- AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "CDR unit tests");
|