mtransport_test_utils.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. // Original author: ekr@rtfm.com
  6. #ifndef mtransport_test_utils_h__
  7. #define mtransport_test_utils_h__
  8. #include "nsCOMPtr.h"
  9. #include "nsNetCID.h"
  10. #include "nsIEventTarget.h"
  11. #include "nsPISocketTransportService.h"
  12. #include "nsServiceManagerUtils.h"
  13. class MtransportTestUtils {
  14. public:
  15. MtransportTestUtils() {
  16. InitServices();
  17. }
  18. ~MtransportTestUtils() {
  19. }
  20. void InitServices() {
  21. nsresult rv;
  22. sts_target_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
  23. MOZ_ASSERT(NS_SUCCEEDED(rv));
  24. sts_ = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
  25. MOZ_ASSERT(NS_SUCCEEDED(rv));
  26. }
  27. nsIEventTarget* sts_target() { return sts_target_; }
  28. private:
  29. nsCOMPtr<nsIEventTarget> sts_target_;
  30. nsCOMPtr<nsPISocketTransportService> sts_;
  31. };
  32. #define CHECK_ENVIRONMENT_FLAG(envname) \
  33. char *test_flag = getenv(envname); \
  34. if (!test_flag || strcmp(test_flag, "1")) { \
  35. printf("To run this test set %s=1 in your environment\n", envname); \
  36. exit(0); \
  37. } \
  38. #endif