// // Copyright 2010-2023 Amazon.com, Inc. or its affiliates. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"). // You may not use this file except in compliance with the License. // A copy of the License is located at // // http://aws.amazon.com/apache2.0 // // or in the "license" file accompanying this file. This file is distributed // on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either // express or implied. See the License for the specific language governing // permissions and limitations under the License. // #import #import #import "OCMock.h" #import "AWSTestUtility.h" #import "AWSPollyService.h" static id mockNetworking = nil; @interface AWSGeneralPollyTests : XCTestCase @end @implementation AWSGeneralPollyTests - (void)setUp { [super setUp]; [AWSTestUtility setupFakeCognitoCredentialsProvider]; mockNetworking = OCMClassMock([AWSNetworking class]); AWSTask *errorTask = [AWSTask taskWithError:[NSError errorWithDomain:@"OCMockExpectedNetworkingError" code:8848 userInfo:nil]]; OCMStub([mockNetworking sendRequest:[OCMArg isKindOfClass:[AWSNetworkingRequest class]]]).andReturn(errorTask); } - (void)tearDown { [super tearDown]; } - (void)testConstructors { NSString *key = @"testPollyConstructors"; XCTAssertNotNil([AWSPolly defaultPolly]); XCTAssertEqual([[AWSPolly defaultPolly] class], [AWSPolly class]); XCTAssertNil([AWSPolly PollyForKey:key]); AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionSAEast1 credentialsProvider:[AWSServiceManager defaultServiceManager].defaultServiceConfiguration.credentialsProvider]; [AWSPolly registerPollyWithConfiguration:configuration forKey:key]; XCTAssertNotNil([AWSPolly PollyForKey:key]); XCTAssertEqual([[AWSPolly PollyForKey:key] class], [AWSPolly class]); XCTAssertEqual([AWSPolly PollyForKey:key].configuration.regionType, AWSRegionSAEast1); [AWSPolly removePollyForKey:key]; XCTAssertNil([AWSPolly PollyForKey:key]); } - (void)testDeleteLexicon { NSString *key = @"testDeleteLexicon"; AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; [AWSPolly registerPollyWithConfiguration:configuration forKey:key]; AWSPolly *awsClient = [AWSPolly PollyForKey:key]; XCTAssertNotNil(awsClient); XCTAssertNotNil(mockNetworking); [awsClient setValue:mockNetworking forKey:@"networking"]; [[[[AWSPolly PollyForKey:key] deleteLexicon:[AWSPollyDeleteLexiconInput new]] continueWithBlock:^id(AWSTask *task) { XCTAssertNotNil(task.error); XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", task.error.domain); XCTAssertEqual(8848, task.error.code); XCTAssertNil(task.result); return nil; }] waitUntilFinished]; OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]); [AWSPolly removePollyForKey:key]; } - (void)testDeleteLexiconCompletionHandler { NSString *key = @"testDeleteLexicon"; AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; [AWSPolly registerPollyWithConfiguration:configuration forKey:key]; AWSPolly *awsClient = [AWSPolly PollyForKey:key]; XCTAssertNotNil(awsClient); XCTAssertNotNil(mockNetworking); [awsClient setValue:mockNetworking forKey:@"networking"]; dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); [[AWSPolly PollyForKey:key] deleteLexicon:[AWSPollyDeleteLexiconInput new] completionHandler:^(AWSPollyDeleteLexiconOutput* _Nullable response, NSError * _Nullable error) { XCTAssertNotNil(error); XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", error.domain); XCTAssertEqual(8848, error.code); XCTAssertNil(response); dispatch_semaphore_signal(semaphore); }]; dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, (int)(2.0 * NSEC_PER_SEC))); OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]); [AWSPolly removePollyForKey:key]; } - (void)testDescribeVoices { NSString *key = @"testDescribeVoices"; AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; [AWSPolly registerPollyWithConfiguration:configuration forKey:key]; AWSPolly *awsClient = [AWSPolly PollyForKey:key]; XCTAssertNotNil(awsClient); XCTAssertNotNil(mockNetworking); [awsClient setValue:mockNetworking forKey:@"networking"]; [[[[AWSPolly PollyForKey:key] describeVoices:[AWSPollyDescribeVoicesInput new]] continueWithBlock:^id(AWSTask *task) { XCTAssertNotNil(task.error); XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", task.error.domain); XCTAssertEqual(8848, task.error.code); XCTAssertNil(task.result); return nil; }] waitUntilFinished]; OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]); [AWSPolly removePollyForKey:key]; } - (void)testDescribeVoicesCompletionHandler { NSString *key = @"testDescribeVoices"; AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; [AWSPolly registerPollyWithConfiguration:configuration forKey:key]; AWSPolly *awsClient = [AWSPolly PollyForKey:key]; XCTAssertNotNil(awsClient); XCTAssertNotNil(mockNetworking); [awsClient setValue:mockNetworking forKey:@"networking"]; dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); [[AWSPolly PollyForKey:key] describeVoices:[AWSPollyDescribeVoicesInput new] completionHandler:^(AWSPollyDescribeVoicesOutput* _Nullable response, NSError * _Nullable error) { XCTAssertNotNil(error); XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", error.domain); XCTAssertEqual(8848, error.code); XCTAssertNil(response); dispatch_semaphore_signal(semaphore); }]; dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, (int)(2.0 * NSEC_PER_SEC))); OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]); [AWSPolly removePollyForKey:key]; } - (void)testGetLexicon { NSString *key = @"testGetLexicon"; AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; [AWSPolly registerPollyWithConfiguration:configuration forKey:key]; AWSPolly *awsClient = [AWSPolly PollyForKey:key]; XCTAssertNotNil(awsClient); XCTAssertNotNil(mockNetworking); [awsClient setValue:mockNetworking forKey:@"networking"]; [[[[AWSPolly PollyForKey:key] getLexicon:[AWSPollyGetLexiconInput new]] continueWithBlock:^id(AWSTask *task) { XCTAssertNotNil(task.error); XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", task.error.domain); XCTAssertEqual(8848, task.error.code); XCTAssertNil(task.result); return nil; }] waitUntilFinished]; OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]); [AWSPolly removePollyForKey:key]; } - (void)testGetLexiconCompletionHandler { NSString *key = @"testGetLexicon"; AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; [AWSPolly registerPollyWithConfiguration:configuration forKey:key]; AWSPolly *awsClient = [AWSPolly PollyForKey:key]; XCTAssertNotNil(awsClient); XCTAssertNotNil(mockNetworking); [awsClient setValue:mockNetworking forKey:@"networking"]; dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); [[AWSPolly PollyForKey:key] getLexicon:[AWSPollyGetLexiconInput new] completionHandler:^(AWSPollyGetLexiconOutput* _Nullable response, NSError * _Nullable error) { XCTAssertNotNil(error); XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", error.domain); XCTAssertEqual(8848, error.code); XCTAssertNil(response); dispatch_semaphore_signal(semaphore); }]; dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, (int)(2.0 * NSEC_PER_SEC))); OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]); [AWSPolly removePollyForKey:key]; } - (void)testGetSpeechSynthesisTask { NSString *key = @"testGetSpeechSynthesisTask"; AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; [AWSPolly registerPollyWithConfiguration:configuration forKey:key]; AWSPolly *awsClient = [AWSPolly PollyForKey:key]; XCTAssertNotNil(awsClient); XCTAssertNotNil(mockNetworking); [awsClient setValue:mockNetworking forKey:@"networking"]; [[[[AWSPolly PollyForKey:key] getSpeechSynthesisTask:[AWSPollyGetSpeechSynthesisTaskInput new]] continueWithBlock:^id(AWSTask *task) { XCTAssertNotNil(task.error); XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", task.error.domain); XCTAssertEqual(8848, task.error.code); XCTAssertNil(task.result); return nil; }] waitUntilFinished]; OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]); [AWSPolly removePollyForKey:key]; } - (void)testGetSpeechSynthesisTaskCompletionHandler { NSString *key = @"testGetSpeechSynthesisTask"; AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; [AWSPolly registerPollyWithConfiguration:configuration forKey:key]; AWSPolly *awsClient = [AWSPolly PollyForKey:key]; XCTAssertNotNil(awsClient); XCTAssertNotNil(mockNetworking); [awsClient setValue:mockNetworking forKey:@"networking"]; dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); [[AWSPolly PollyForKey:key] getSpeechSynthesisTask:[AWSPollyGetSpeechSynthesisTaskInput new] completionHandler:^(AWSPollyGetSpeechSynthesisTaskOutput* _Nullable response, NSError * _Nullable error) { XCTAssertNotNil(error); XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", error.domain); XCTAssertEqual(8848, error.code); XCTAssertNil(response); dispatch_semaphore_signal(semaphore); }]; dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, (int)(2.0 * NSEC_PER_SEC))); OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]); [AWSPolly removePollyForKey:key]; } - (void)testListLexicons { NSString *key = @"testListLexicons"; AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; [AWSPolly registerPollyWithConfiguration:configuration forKey:key]; AWSPolly *awsClient = [AWSPolly PollyForKey:key]; XCTAssertNotNil(awsClient); XCTAssertNotNil(mockNetworking); [awsClient setValue:mockNetworking forKey:@"networking"]; [[[[AWSPolly PollyForKey:key] listLexicons:[AWSPollyListLexiconsInput new]] continueWithBlock:^id(AWSTask *task) { XCTAssertNotNil(task.error); XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", task.error.domain); XCTAssertEqual(8848, task.error.code); XCTAssertNil(task.result); return nil; }] waitUntilFinished]; OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]); [AWSPolly removePollyForKey:key]; } - (void)testListLexiconsCompletionHandler { NSString *key = @"testListLexicons"; AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; [AWSPolly registerPollyWithConfiguration:configuration forKey:key]; AWSPolly *awsClient = [AWSPolly PollyForKey:key]; XCTAssertNotNil(awsClient); XCTAssertNotNil(mockNetworking); [awsClient setValue:mockNetworking forKey:@"networking"]; dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); [[AWSPolly PollyForKey:key] listLexicons:[AWSPollyListLexiconsInput new] completionHandler:^(AWSPollyListLexiconsOutput* _Nullable response, NSError * _Nullable error) { XCTAssertNotNil(error); XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", error.domain); XCTAssertEqual(8848, error.code); XCTAssertNil(response); dispatch_semaphore_signal(semaphore); }]; dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, (int)(2.0 * NSEC_PER_SEC))); OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]); [AWSPolly removePollyForKey:key]; } - (void)testListSpeechSynthesisTasks { NSString *key = @"testListSpeechSynthesisTasks"; AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; [AWSPolly registerPollyWithConfiguration:configuration forKey:key]; AWSPolly *awsClient = [AWSPolly PollyForKey:key]; XCTAssertNotNil(awsClient); XCTAssertNotNil(mockNetworking); [awsClient setValue:mockNetworking forKey:@"networking"]; [[[[AWSPolly PollyForKey:key] listSpeechSynthesisTasks:[AWSPollyListSpeechSynthesisTasksInput new]] continueWithBlock:^id(AWSTask *task) { XCTAssertNotNil(task.error); XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", task.error.domain); XCTAssertEqual(8848, task.error.code); XCTAssertNil(task.result); return nil; }] waitUntilFinished]; OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]); [AWSPolly removePollyForKey:key]; } - (void)testListSpeechSynthesisTasksCompletionHandler { NSString *key = @"testListSpeechSynthesisTasks"; AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; [AWSPolly registerPollyWithConfiguration:configuration forKey:key]; AWSPolly *awsClient = [AWSPolly PollyForKey:key]; XCTAssertNotNil(awsClient); XCTAssertNotNil(mockNetworking); [awsClient setValue:mockNetworking forKey:@"networking"]; dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); [[AWSPolly PollyForKey:key] listSpeechSynthesisTasks:[AWSPollyListSpeechSynthesisTasksInput new] completionHandler:^(AWSPollyListSpeechSynthesisTasksOutput* _Nullable response, NSError * _Nullable error) { XCTAssertNotNil(error); XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", error.domain); XCTAssertEqual(8848, error.code); XCTAssertNil(response); dispatch_semaphore_signal(semaphore); }]; dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, (int)(2.0 * NSEC_PER_SEC))); OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]); [AWSPolly removePollyForKey:key]; } - (void)testPutLexicon { NSString *key = @"testPutLexicon"; AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; [AWSPolly registerPollyWithConfiguration:configuration forKey:key]; AWSPolly *awsClient = [AWSPolly PollyForKey:key]; XCTAssertNotNil(awsClient); XCTAssertNotNil(mockNetworking); [awsClient setValue:mockNetworking forKey:@"networking"]; [[[[AWSPolly PollyForKey:key] putLexicon:[AWSPollyPutLexiconInput new]] continueWithBlock:^id(AWSTask *task) { XCTAssertNotNil(task.error); XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", task.error.domain); XCTAssertEqual(8848, task.error.code); XCTAssertNil(task.result); return nil; }] waitUntilFinished]; OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]); [AWSPolly removePollyForKey:key]; } - (void)testPutLexiconCompletionHandler { NSString *key = @"testPutLexicon"; AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; [AWSPolly registerPollyWithConfiguration:configuration forKey:key]; AWSPolly *awsClient = [AWSPolly PollyForKey:key]; XCTAssertNotNil(awsClient); XCTAssertNotNil(mockNetworking); [awsClient setValue:mockNetworking forKey:@"networking"]; dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); [[AWSPolly PollyForKey:key] putLexicon:[AWSPollyPutLexiconInput new] completionHandler:^(AWSPollyPutLexiconOutput* _Nullable response, NSError * _Nullable error) { XCTAssertNotNil(error); XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", error.domain); XCTAssertEqual(8848, error.code); XCTAssertNil(response); dispatch_semaphore_signal(semaphore); }]; dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, (int)(2.0 * NSEC_PER_SEC))); OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]); [AWSPolly removePollyForKey:key]; } - (void)testStartSpeechSynthesisTask { NSString *key = @"testStartSpeechSynthesisTask"; AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; [AWSPolly registerPollyWithConfiguration:configuration forKey:key]; AWSPolly *awsClient = [AWSPolly PollyForKey:key]; XCTAssertNotNil(awsClient); XCTAssertNotNil(mockNetworking); [awsClient setValue:mockNetworking forKey:@"networking"]; [[[[AWSPolly PollyForKey:key] startSpeechSynthesisTask:[AWSPollyStartSpeechSynthesisTaskInput new]] continueWithBlock:^id(AWSTask *task) { XCTAssertNotNil(task.error); XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", task.error.domain); XCTAssertEqual(8848, task.error.code); XCTAssertNil(task.result); return nil; }] waitUntilFinished]; OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]); [AWSPolly removePollyForKey:key]; } - (void)testStartSpeechSynthesisTaskCompletionHandler { NSString *key = @"testStartSpeechSynthesisTask"; AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; [AWSPolly registerPollyWithConfiguration:configuration forKey:key]; AWSPolly *awsClient = [AWSPolly PollyForKey:key]; XCTAssertNotNil(awsClient); XCTAssertNotNil(mockNetworking); [awsClient setValue:mockNetworking forKey:@"networking"]; dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); [[AWSPolly PollyForKey:key] startSpeechSynthesisTask:[AWSPollyStartSpeechSynthesisTaskInput new] completionHandler:^(AWSPollyStartSpeechSynthesisTaskOutput* _Nullable response, NSError * _Nullable error) { XCTAssertNotNil(error); XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", error.domain); XCTAssertEqual(8848, error.code); XCTAssertNil(response); dispatch_semaphore_signal(semaphore); }]; dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, (int)(2.0 * NSEC_PER_SEC))); OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]); [AWSPolly removePollyForKey:key]; } - (void)testSynthesizeSpeech { NSString *key = @"testSynthesizeSpeech"; AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; [AWSPolly registerPollyWithConfiguration:configuration forKey:key]; AWSPolly *awsClient = [AWSPolly PollyForKey:key]; XCTAssertNotNil(awsClient); XCTAssertNotNil(mockNetworking); [awsClient setValue:mockNetworking forKey:@"networking"]; [[[[AWSPolly PollyForKey:key] synthesizeSpeech:[AWSPollySynthesizeSpeechInput new]] continueWithBlock:^id(AWSTask *task) { XCTAssertNotNil(task.error); XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", task.error.domain); XCTAssertEqual(8848, task.error.code); XCTAssertNil(task.result); return nil; }] waitUntilFinished]; OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]); [AWSPolly removePollyForKey:key]; } - (void)testSynthesizeSpeechCompletionHandler { NSString *key = @"testSynthesizeSpeech"; AWSServiceConfiguration *configuration = [[AWSServiceConfiguration alloc] initWithRegion:AWSRegionUSEast1 credentialsProvider:nil]; [AWSPolly registerPollyWithConfiguration:configuration forKey:key]; AWSPolly *awsClient = [AWSPolly PollyForKey:key]; XCTAssertNotNil(awsClient); XCTAssertNotNil(mockNetworking); [awsClient setValue:mockNetworking forKey:@"networking"]; dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); [[AWSPolly PollyForKey:key] synthesizeSpeech:[AWSPollySynthesizeSpeechInput new] completionHandler:^(AWSPollySynthesizeSpeechOutput* _Nullable response, NSError * _Nullable error) { XCTAssertNotNil(error); XCTAssertEqualObjects(@"OCMockExpectedNetworkingError", error.domain); XCTAssertEqual(8848, error.code); XCTAssertNil(response); dispatch_semaphore_signal(semaphore); }]; dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, (int)(2.0 * NSEC_PER_SEC))); OCMVerify([mockNetworking sendRequest:[OCMArg isNotNil]]); [AWSPolly removePollyForKey:key]; } @end