UDPInterface_test.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #define string_strcmp
  16. #define string_strlen
  17. #include "admin/testframework/AdminTestFramework.h"
  18. #include "admin/Admin.h"
  19. #include "admin/AdminClient.h"
  20. #include "benc/Dict.h"
  21. #include "benc/String.h"
  22. #include "benc/Int.h"
  23. #include "interface/UDPInterface_admin.h"
  24. #include "memory/Allocator.h"
  25. #include "memory/MallocAllocator.h"
  26. #include "interface/InterfaceController.h"
  27. #include "io/FileWriter.h"
  28. #include "io/Writer.h"
  29. #include "util/Assert.h"
  30. #include "util/log/Log.h"
  31. #include "util/platform/libc/string.h"
  32. static int registerPeer(struct InterfaceController* ic,
  33. uint8_t herPublicKey[32],
  34. String* password,
  35. bool requireAuth,
  36. bool transient,
  37. struct Interface* iface)
  38. {
  39. return 0;
  40. }
  41. int main(int argc, char** argv)
  42. {
  43. struct AdminTestFramework* fw = AdminTestFramework_setUp(argc, argv);
  44. // mock interface controller.
  45. struct InterfaceController ifController = {
  46. .registerPeer = registerPeer
  47. };
  48. UDPInterface_admin_register(fw->eventBase,
  49. fw->alloc,
  50. fw->logger,
  51. fw->admin,
  52. &ifController);
  53. Dict* dict = Dict_new(fw->alloc);
  54. struct AdminClient_Result* res = AdminClient_rpcCall(String_CONST("UDPInterface_new"),
  55. dict,
  56. fw->client,
  57. fw->alloc);
  58. Assert_always(!res->err);
  59. //printf("result content: >>%s<<", res->messageBytes);
  60. Assert_always(!strcmp("d5:error4:none15:interfaceNumberi0ee", (char*) res->messageBytes));
  61. // bad key
  62. dict = Dict_new(fw->alloc);
  63. Dict_putString(dict, String_CONST("publicKey"), String_CONST("notAValidKey"), fw->alloc);
  64. Dict_putString(dict, String_CONST("address"), String_CONST("127.0.0.1:12345"), fw->alloc);
  65. res = AdminClient_rpcCall(
  66. String_CONST("UDPInterface_beginConnection"), dict, fw->client, fw->alloc);
  67. Assert_always(!strcmp("d5:error30:key must be 52 characters longe",
  68. (char*) res->messageBytes));
  69. //printf("result content: >>%s<<", res->messageBytes);
  70. dict = Dict_new(fw->alloc);
  71. Dict_putString(dict,
  72. String_CONST("publicKey"),
  73. String_CONST("c86pf0ngj3wlb569juqm10yzv29n9t4w5tmsyhx6xd3fbqjlcu50.k"),
  74. fw->alloc);
  75. Dict_putString(dict, String_CONST("address"), String_CONST("127.0.0.1:12345"), fw->alloc);
  76. res = AdminClient_rpcCall(
  77. String_CONST("UDPInterface_beginConnection"), dict, fw->client, fw->alloc);
  78. Assert_always(!strcmp("d5:error4:nonee", (char*) res->messageBytes));
  79. AdminTestFramework_tearDown(fw);
  80. }