XmlRpcRequestParserControllerTest.cc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #include "XmlRpcRequestParserController.h"
  2. #include <cppunit/extensions/HelperMacros.h>
  3. namespace aria2 {
  4. namespace xmlrpc {
  5. class XmlRpcRequestParserControllerTest:public CppUnit::TestFixture {
  6. CPPUNIT_TEST_SUITE(XmlRpcRequestParserControllerTest);
  7. CPPUNIT_TEST(testPopStructFrame);
  8. CPPUNIT_TEST(testPopStructFrame_noName);
  9. CPPUNIT_TEST(testPopStructFrame_noValue);
  10. CPPUNIT_TEST(testPopArrayFrame);
  11. CPPUNIT_TEST(testPopArrayFrame_noValue);
  12. CPPUNIT_TEST(testPopArrayFrame_compound);
  13. CPPUNIT_TEST_SUITE_END();
  14. public:
  15. void setUp() {}
  16. void tearDown() {}
  17. void testPopStructFrame();
  18. void testPopStructFrame_noName();
  19. void testPopStructFrame_noValue();
  20. void testPopArrayFrame();
  21. void testPopArrayFrame_noValue();
  22. void testPopArrayFrame_compound();
  23. };
  24. CPPUNIT_TEST_SUITE_REGISTRATION(XmlRpcRequestParserControllerTest);
  25. void XmlRpcRequestParserControllerTest::testPopStructFrame()
  26. {
  27. XmlRpcRequestParserController controller;
  28. controller.setCurrentFrameValue(BDE::dict());
  29. controller.pushFrame();
  30. controller.setCurrentFrameValue(BDE("Hello, aria2"));
  31. controller.setCurrentFrameName("greeting");
  32. controller.popStructFrame();
  33. const BDE& structValue = controller.getCurrentFrameValue();
  34. CPPUNIT_ASSERT_EQUAL((size_t)1, structValue.size());
  35. CPPUNIT_ASSERT_EQUAL(std::string("Hello, aria2"),
  36. structValue["greeting"].s());
  37. }
  38. void XmlRpcRequestParserControllerTest::testPopStructFrame_noName()
  39. {
  40. XmlRpcRequestParserController controller;
  41. controller.setCurrentFrameValue(BDE::dict());
  42. controller.pushFrame();
  43. controller.setCurrentFrameValue(BDE("Hello, aria2"));
  44. controller.popStructFrame();
  45. const BDE& structValue = controller.getCurrentFrameValue();
  46. CPPUNIT_ASSERT(structValue.empty());
  47. }
  48. void XmlRpcRequestParserControllerTest::testPopStructFrame_noValue()
  49. {
  50. XmlRpcRequestParserController controller;
  51. controller.setCurrentFrameValue(BDE::dict());
  52. controller.pushFrame();
  53. controller.setCurrentFrameName("greeting");
  54. controller.popStructFrame();
  55. const BDE& structValue = controller.getCurrentFrameValue();
  56. CPPUNIT_ASSERT(structValue.empty());
  57. }
  58. void XmlRpcRequestParserControllerTest::testPopArrayFrame()
  59. {
  60. XmlRpcRequestParserController controller;
  61. controller.setCurrentFrameValue(BDE::list());
  62. controller.pushFrame();
  63. controller.setCurrentFrameValue(BDE(100));
  64. controller.popArrayFrame();
  65. const BDE& array = controller.getCurrentFrameValue();
  66. CPPUNIT_ASSERT_EQUAL((size_t)1, array.size());
  67. CPPUNIT_ASSERT_EQUAL((BDE::Integer)100, array[0].i());
  68. }
  69. void XmlRpcRequestParserControllerTest::testPopArrayFrame_noValue()
  70. {
  71. XmlRpcRequestParserController controller;
  72. controller.setCurrentFrameValue(BDE::list());
  73. controller.pushFrame();
  74. controller.popArrayFrame();
  75. const BDE& array = controller.getCurrentFrameValue();
  76. CPPUNIT_ASSERT(array.empty());
  77. }
  78. void XmlRpcRequestParserControllerTest::testPopArrayFrame_compound()
  79. {
  80. XmlRpcRequestParserController controller;
  81. // We are making following structs. [] = array, {key:value .. } = dict
  82. // [ { "uris":["http://example.org/aria2","http://aria2.sf.net/"],
  83. // "options":{ "timeout":120 } },
  84. // [ "jp","us" ] ]
  85. controller.setCurrentFrameValue(BDE::list());
  86. controller.pushFrame();
  87. controller.setCurrentFrameValue(BDE::dict());
  88. controller.pushFrame();
  89. controller.setCurrentFrameName("uris");
  90. controller.setCurrentFrameValue(BDE::list());
  91. controller.pushFrame();
  92. controller.setCurrentFrameValue(BDE("http://example.org/aria2"));
  93. controller.popArrayFrame();
  94. controller.pushFrame();
  95. controller.setCurrentFrameValue(BDE("http://aria2.sf.net/"));
  96. controller.popArrayFrame();
  97. controller.popStructFrame();
  98. controller.pushFrame();
  99. controller.setCurrentFrameName("options");
  100. controller.setCurrentFrameValue(BDE::dict());
  101. controller.pushFrame();
  102. controller.setCurrentFrameName("timeout");
  103. controller.setCurrentFrameValue(BDE(120));
  104. controller.popStructFrame();
  105. controller.popStructFrame();
  106. controller.popArrayFrame();
  107. controller.pushFrame();
  108. controller.setCurrentFrameValue(BDE::list());
  109. controller.pushFrame();
  110. controller.setCurrentFrameValue(BDE("jp"));
  111. controller.popArrayFrame();
  112. controller.pushFrame();
  113. controller.setCurrentFrameValue(BDE("us"));
  114. controller.popArrayFrame();
  115. controller.popArrayFrame();
  116. const BDE& result = controller.getCurrentFrameValue();
  117. CPPUNIT_ASSERT_EQUAL(std::string("http://aria2.sf.net/"),
  118. result[0]["uris"][1].s());
  119. CPPUNIT_ASSERT_EQUAL((BDE::Integer)120, result[0]["options"]["timeout"].i());
  120. CPPUNIT_ASSERT_EQUAL(std::string("jp"), result[1][0].s());
  121. }
  122. } // namespace xmlrpc
  123. } // namespace aria2