]> git.saurik.com Git - apple/mdnsresponder.git/blob - Clients/dnssdutil/TestUtils.m
mDNSResponder-1096.60.2.tar.gz
[apple/mdnsresponder.git] / Clients / dnssdutil / TestUtils.m
1 //
2 // TestUtils.m
3 // mDNSResponder
4 //
5 // Copyright (c) 2019 Apple Inc. All rights reserved.
6 //
7
8 #import "TestUtils.h"
9
10 #import <Foundation/Foundation.h>
11 #import <CoreUtils/CoreUtils.h>
12 #import <XCTest/XCTest.h>
13
14 #if TARGET_OS_OSX
15 #define XCTest_Framework_Runtime_Path "/AppleInternal/Developer/Library/Frameworks/XCTest.framework"
16 #else
17 #define XCTest_Framework_Runtime_Path "/Developer/Library/Frameworks/XCTest.framework"
18 #endif
19
20 //===========================================================================================================================
21 // XCTest Utils
22 //===========================================================================================================================
23 static NSBundle * LoadXCTestFramework()
24 {
25 NSBundle * result = nil;
26 Boolean loaded = (NSClassFromString(@"XCTestSuite") != nil);
27
28 if(!result) {
29 result = [NSBundle bundleWithPath: @ XCTest_Framework_Runtime_Path];
30 [result load];
31 loaded = (NSClassFromString(@"XCTestSuite") != nil);
32 if( !loaded ) {
33 FPrintF( stdout, "Failed to load XCTest framework from: %s\n", XCTest_Framework_Runtime_Path );
34 }
35 }
36
37 return( result );
38 }
39
40 //===========================================================================================================================
41 // Main Test Running
42 //===========================================================================================================================
43
44 Boolean TestUtilsRunXCTestNamed(const char * classname)
45 {
46 Boolean result = false;
47 NSBundle * xctestFramework = LoadXCTestFramework();
48
49 if(xctestFramework) {
50 NSString * name = [NSString stringWithUTF8String: classname];
51 NSBundle * testBundle = [NSBundle bundleWithPath: @"/AppleInternal/XCTests/com.apple.mDNSResponder/Tests.xctest"];
52 [testBundle load];
53
54 XCTestSuite * compiledSuite = [NSClassFromString(@"XCTestSuite") testSuiteForTestCaseWithName: name];
55 if(compiledSuite.tests.count) {
56 [compiledSuite runTest];
57 XCTestRun *testRun = compiledSuite.testRun;
58 result = (testRun.hasSucceeded != NO);
59 } else {
60 FPrintF( stdout, "Test class %s not found\n", classname );
61 }
62 }
63
64 return( result );
65 }