GDTCORTransportTest.m 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright 2018 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "GDTCORTests/Unit/GDTCORTestCase.h"
  17. #import <GoogleDataTransport/GDTCOREvent.h>
  18. #import <GoogleDataTransport/GDTCORTransport.h>
  19. #import "GDTCORLibrary/Private/GDTCORTransport_Private.h"
  20. #import "GDTCORTests/Common/Fakes/GDTCORTransformerFake.h"
  21. #import "GDTCORTests/Unit/Helpers/GDTCORDataObjectTesterClasses.h"
  22. @interface GDTCORTransportTest : GDTCORTestCase
  23. @end
  24. @implementation GDTCORTransportTest
  25. /** Tests the default initializer. */
  26. - (void)testInit {
  27. XCTAssertNotNil([[GDTCORTransport alloc] initWithMappingID:@"1" transformers:nil target:1]);
  28. XCTAssertNil([[GDTCORTransport alloc] initWithMappingID:@"" transformers:nil target:1]);
  29. }
  30. /** Tests sending a telemetry event. */
  31. - (void)testSendTelemetryEvent {
  32. GDTCORTransport *transport = [[GDTCORTransport alloc] initWithMappingID:@"1"
  33. transformers:nil
  34. target:1];
  35. transport.transformerInstance = [[GDTCORTransformerFake alloc] init];
  36. GDTCOREvent *event = [transport eventForTransport];
  37. event.dataObject = [[GDTCORDataObjectTesterSimple alloc] init];
  38. XCTestExpectation *writtenExpectation = [self expectationWithDescription:@"event written"];
  39. XCTAssertNoThrow([transport sendTelemetryEvent:event
  40. onComplete:^(BOOL wasWritten, NSError *error) {
  41. XCTAssertTrue(wasWritten);
  42. XCTAssertNil(error);
  43. [writtenExpectation fulfill];
  44. }]);
  45. [self waitForExpectations:@[ writtenExpectation ] timeout:10.0];
  46. }
  47. /** Tests sending a data event. */
  48. - (void)testSendDataEvent {
  49. GDTCORTransport *transport = [[GDTCORTransport alloc] initWithMappingID:@"1"
  50. transformers:nil
  51. target:1];
  52. transport.transformerInstance = [[GDTCORTransformerFake alloc] init];
  53. GDTCOREvent *event = [transport eventForTransport];
  54. event.dataObject = [[GDTCORDataObjectTesterSimple alloc] init];
  55. XCTestExpectation *writtenExpectation = [self expectationWithDescription:@"event written"];
  56. XCTAssertNoThrow([transport sendDataEvent:event
  57. onComplete:^(BOOL wasWritten, NSError *error) {
  58. XCTAssertTrue(wasWritten);
  59. XCTAssertNil(error);
  60. [writtenExpectation fulfill];
  61. }]);
  62. [self waitForExpectations:@[ writtenExpectation ] timeout:10.0];
  63. }
  64. @end