test_selector.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /*
  2. * Copyright (C) 2009 Mamadou Diop.
  3. *
  4. * Contact: Mamadou Diop <diopmamadou(at)doubango.org>
  5. *
  6. * This file is part of Open Source Doubango Framework.
  7. *
  8. * DOUBANGO is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * DOUBANGO is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with DOUBANGO.
  20. *
  21. */
  22. #ifndef _TEST_SELECTOR_H
  23. #define _TEST_SELECTOR_H
  24. void test_selector()
  25. {
  26. txcap_stack_handle_t* stack = tsk_null;
  27. char* urlstring;
  28. stack = txcap_stack_create(tsk_null, XUI, PASSWORD, XCAP_ROOT,
  29. TXCAP_STACK_SET_NULL());
  30. /* add user auids */
  31. txcap_stack_set(stack,
  32. TXCAP_STACK_SET_AUID("xcap-caps2", "application/xcap-caps2+xml", "urn:ietf:params:xml:ns:xcap-caps2", "index2", tsk_true),
  33. TXCAP_STACK_SET_AUID("resource-lists2", "application/resource-lists+xml2", "urn:ietf:params:xml:ns:resource-lists2", "index2", tsk_false),
  34. TXCAP_STACK_SET_NULL()); /* mandatory */
  35. /* IETF server capabilities */
  36. urlstring = txcap_selector_get_url(stack, "xcap-caps",
  37. TXCAP_SELECTOR_NODE_SET_NULL());
  38. TSK_DEBUG_INFO("Document('xcap-caps') = %s\n", urlstring);
  39. TSK_FREE(urlstring);
  40. /* My custom xcap-caps */
  41. urlstring = txcap_selector_get_url(stack, "xcap-caps2",
  42. TXCAP_SELECTOR_NODE_SET_NULL());
  43. TSK_DEBUG_INFO("Document('xcap-caps2') = %s\n", urlstring);
  44. TSK_FREE(urlstring);
  45. /* IETF resource-lists */
  46. urlstring = txcap_selector_get_url(stack, "resource-lists",
  47. TXCAP_SELECTOR_NODE_SET_NULL());
  48. TSK_DEBUG_INFO("Document('resource-lists') = %s\n", urlstring);
  49. TSK_FREE(urlstring);
  50. /* My custom resource-lists */
  51. urlstring = txcap_selector_get_url(stack, "resource-lists2",
  52. TXCAP_SELECTOR_NODE_SET_NULL());
  53. TSK_DEBUG_INFO("Document('resource-lists2') = %s\n", urlstring);
  54. TSK_FREE(urlstring);
  55. /* Full custom resource-lists */
  56. urlstring = txcap_selector_get_document_2(XCAP_ROOT, "resource-lists3", XUI, "index3");
  57. TSK_DEBUG_INFO("Document('resource-lists2') = %s\n", urlstring);
  58. TSK_FREE(urlstring);
  59. /* Retrieve 'rcs' list
  60. * Expected node: /resource-lists/list[@name="rcs"]
  61. */
  62. urlstring = txcap_selector_get_url(stack, "resource-lists",
  63. TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "rcs"),
  64. TXCAP_SELECTOR_NODE_SET_NULL());
  65. TSK_DEBUG_INFO("'rcs' list = %s\n", urlstring);
  66. TSK_FREE(urlstring);
  67. /* Retrieve the 2nd list
  68. * Expected node: /resource-lists/list[2]
  69. */
  70. urlstring = txcap_selector_get_url(stack, "resource-lists",
  71. TXCAP_SELECTOR_NODE_SET_POS("list", 2),
  72. TXCAP_SELECTOR_NODE_SET_NULL());
  73. TSK_DEBUG_INFO("2nd list = %s\n", urlstring);
  74. TSK_FREE(urlstring);
  75. /* Retrieve the 4th list (wildcard)
  76. * Expected node: /resource-lists/*[4]
  77. */
  78. urlstring = txcap_selector_get_url(stack, "resource-lists",
  79. TXCAP_SELECTOR_NODE_SET_POS("*", 4),
  80. TXCAP_SELECTOR_NODE_SET_NULL());
  81. TSK_DEBUG_INFO("4th list (wildcard) = %s\n", urlstring);
  82. TSK_FREE(urlstring);
  83. /* Retrieve the entry with: uri='sip:bob@example.com' and list='rcs'
  84. * Expected node: /resource-lists/list[@name="rcs"]/entry[@uri="sip:bob@example.com"]
  85. */
  86. urlstring = txcap_selector_get_url(stack, "resource-lists",
  87. TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "rcs"),
  88. TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("entry", "uri", XUI),
  89. TXCAP_SELECTOR_NODE_SET_NULL());
  90. TSK_DEBUG_INFO("By uri and list = %s\n", urlstring);
  91. TSK_FREE(urlstring);
  92. /* Retrieve bob's display-name
  93. * Expected node: /resource-lists/list[@name="rcs"]/entry[@uri="sip:bob@example.com"]/display-name
  94. */
  95. urlstring = txcap_selector_get_url(stack, "resource-lists",
  96. TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "rcs"),
  97. TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("entry", "uri", XUI),
  98. TXCAP_SELECTOR_NODE_SET_NAME("display-name"),
  99. TXCAP_SELECTOR_NODE_SET_NULL());
  100. TSK_DEBUG_INFO("bob's display-name = %s\n", urlstring);
  101. TSK_FREE(urlstring);
  102. /* Retrieve the display-name of the fisrt entry from the 'rcs' list
  103. * Expected node: /resource-lists/list[@name="rcs"]/entry[1]/display-name
  104. */
  105. urlstring = txcap_selector_get_url(stack, "resource-lists",
  106. TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "rcs"),
  107. TXCAP_SELECTOR_NODE_SET_POS("entry", 1),
  108. TXCAP_SELECTOR_NODE_SET_NAME("display-name"),
  109. TXCAP_SELECTOR_NODE_SET_NULL());
  110. TSK_DEBUG_INFO("display-name of 1st entry = %s\n", urlstring);
  111. TSK_FREE(urlstring);
  112. /* Retrieve the entry with: uri='sip:bob@example.com' from position 23 from 'rcs' list
  113. * Expected node: /resource-lists/list[@name="rcs"]/entry[23][@uri="sip:bob@example.com"]
  114. */
  115. urlstring = txcap_selector_get_url(stack, "resource-lists",
  116. TXCAP_SELECTOR_NODE_SET_ATTRIBUTE("list", "name", "rcs"),
  117. TXCAP_SELECTOR_NODE_SET_POS_ATTRIBUTE("entry", 23, "uri", XUI),
  118. TXCAP_SELECTOR_NODE_SET_NULL());
  119. TSK_DEBUG_INFO("bob at pos 23 from 'rcs' = %s\n", urlstring);
  120. TSK_FREE(urlstring);
  121. /* Namespace test
  122. * Expected node: /foo/a:bar/b:baz?xmlns(a=urn:test:namespace1-uri)xmlns(b=urn:test:namespace2-uri)
  123. */
  124. urlstring = txcap_selector_get_url(stack, "resource-lists",
  125. TXCAP_SELECTOR_NODE_SET_NAME("foo"),
  126. TXCAP_SELECTOR_NODE_SET_NAME("a:bar"),
  127. TXCAP_SELECTOR_NODE_SET_NAME("b:baz"),
  128. TXCAP_SELECTOR_NODE_SET_NAMESPACE("a", "urn:namespace1-uri"),
  129. TXCAP_SELECTOR_NODE_SET_NAMESPACE("b", "urn:namespace2-uri"),
  130. TXCAP_SELECTOR_NODE_SET_NULL());
  131. TSK_DEBUG_INFO("Namespace test = %s\n", urlstring);
  132. TSK_FREE(urlstring);
  133. TSK_OBJECT_SAFE_FREE(stack);
  134. }
  135. #endif /* _TEST_SELECTOR_H */