test_udp_socket.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2013 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef PPAPI_TESTS_TEST_UDP_SOCKET_H_
  5. #define PPAPI_TESTS_TEST_UDP_SOCKET_H_
  6. #include <stddef.h>
  7. #include <string>
  8. #include "ppapi/c/pp_stdint.h"
  9. #include "ppapi/c/ppb_udp_socket.h"
  10. #include "ppapi/cpp/net_address.h"
  11. #include "ppapi/tests/test_case.h"
  12. namespace {
  13. typedef int32_t (*UDPSocketSetOption)(PP_Resource udp_socket,
  14. PP_UDPSocket_Option name,
  15. struct PP_Var value,
  16. struct PP_CompletionCallback callback);
  17. }
  18. namespace pp {
  19. class UDPSocket;
  20. }
  21. class TestUDPSocket: public TestCase {
  22. public:
  23. explicit TestUDPSocket(TestingInstance* instance);
  24. // TestCase implementation.
  25. virtual bool Init();
  26. virtual void RunTests(const std::string& filter);
  27. private:
  28. std::string GetLocalAddress(pp::NetAddress* address);
  29. std::string SetBroadcastOptions(pp::UDPSocket* socket);
  30. std::string BindUDPSocket(pp::UDPSocket* socket,
  31. const pp::NetAddress& address);
  32. std::string LookupPortAndBindUDPSocket(pp::UDPSocket* socket,
  33. pp::NetAddress* address);
  34. std::string ReadSocket(pp::UDPSocket* socket,
  35. pp::NetAddress* address,
  36. size_t size,
  37. std::string* message);
  38. std::string PassMessage(pp::UDPSocket* target,
  39. pp::UDPSocket* source,
  40. const pp::NetAddress& target_address,
  41. const std::string& message,
  42. pp::NetAddress* recvfrom_address);
  43. std::string SetMulticastOptions(pp::UDPSocket* socket);
  44. std::string TestReadWrite();
  45. std::string TestBroadcast();
  46. int32_t SetOptionValue(UDPSocketSetOption func,
  47. PP_Resource socket,
  48. PP_UDPSocket_Option option,
  49. const PP_Var& value);
  50. std::string TestSetOption_1_0();
  51. std::string TestSetOption_1_1();
  52. std::string TestSetOption();
  53. std::string TestParallelSend();
  54. std::string TestMulticast();
  55. // Error cases. It's up to the parent test fixture to ensure that these events
  56. // result in errors.
  57. std::string TestBindFails();
  58. std::string TestSetBroadcastFails();
  59. std::string TestSendToFails();
  60. std::string TestReadFails();
  61. pp::NetAddress address_;
  62. const PPB_UDPSocket_1_0* socket_interface_1_0_;
  63. const PPB_UDPSocket_1_1* socket_interface_1_1_;
  64. };
  65. #endif // PPAPI_TESTS_TEST_UDP_SOCKET_H_