]> git.saurik.com Git - apple/configd.git/blob - SCTest-ObjC/test-objC.m
configd-963.250.1.tar.gz
[apple/configd.git] / SCTest-ObjC / test-objC.m
1 /*
2 * Copyright (c) 2015 Apple Inc. All rights reserved.
3 *
4 * A Objective-C test target to test SC APIs
5 *
6 * Created by Sushant Chavan on 4/21/15.
7 */
8
9 @import Foundation;
10 @import SystemConfiguration;
11
12 #define MY_APP_NAME CFSTR("SCTestObjC")
13 #define TARGET_HOST "www.apple.com"
14
15 static void
16 test_SCNetworkConfiguration()
17 {
18 NSLog(@"\n\n*** SCNetworkConfiguration ***\n\n");
19 CFIndex count;
20 CFIndex idx;
21 CFArrayRef interfaces;
22
23 interfaces = SCNetworkInterfaceCopyAll();
24 count = CFArrayGetCount(interfaces);
25 NSLog(@"Network Interfaces:\n");
26 for (idx=0; idx < count; idx++) {
27 SCNetworkInterfaceRef intf;
28 CFStringRef bsdName;
29
30 intf = CFArrayGetValueAtIndex(interfaces, idx);
31 bsdName = SCNetworkInterfaceGetBSDName(intf);
32 NSLog(@"- %@", bsdName);
33 }
34
35 CFRelease(interfaces);
36 }
37
38 static void
39 test_SCDynamicStore()
40 {
41 NSLog(@"\n\n*** SCDynamicStore ***\n\n");
42 CFDictionaryRef dict;
43 CFStringRef intf;
44 CFStringRef key;
45 SCDynamicStoreRef store;
46
47 store = SCDynamicStoreCreate(NULL, MY_APP_NAME, NULL, NULL);
48 key = SCDynamicStoreKeyCreateNetworkGlobalEntity(NULL, kSCDynamicStoreDomainState, kSCEntNetIPv4);
49 dict = SCDynamicStoreCopyValue(store, key);
50 intf = CFDictionaryGetValue(dict, kSCDynamicStorePropNetPrimaryInterface);
51 NSLog(@"- Primary Interface is %@\n", intf);
52
53 CFRelease(store);
54 CFRelease(dict);
55 CFRelease(key);
56 }
57
58 static void
59 test_SCPreferences()
60 {
61 NSLog(@"\n\n*** SCPreferences ***\n\n");
62 CFIndex count;
63 CFIndex idx;
64 CFStringRef model = NULL;
65 SCPreferencesRef prefs;
66 CFArrayRef services;
67
68 prefs = SCPreferencesCreate(NULL, MY_APP_NAME, NULL);
69 model = SCPreferencesGetValue(prefs, CFSTR("Model"));
70 if (model != NULL) {
71 NSLog(@"Current model is %@", model);
72 }
73
74 services = SCNetworkServiceCopyAll(prefs);
75 count = CFArrayGetCount(services);
76 NSLog(@"Network Services:\n");
77 for (idx = 0; idx < count; idx++) {
78 SCNetworkServiceRef serv;
79 CFStringRef servName;
80
81 serv = CFArrayGetValueAtIndex(services, idx);
82 servName = SCNetworkServiceGetName(serv);
83 NSLog(@"- %@\n", servName);
84 }
85
86 CFRelease(prefs);
87 CFRelease(services);
88 }
89
90 void
91 test_SCNetworkReachability()
92 {
93 NSLog(@"\n\n*** SCNetworkReachability ***\n\n");
94 SCNetworkReachabilityFlags flags;
95 SCNetworkReachabilityRef target;
96
97 target = SCNetworkReachabilityCreateWithName(NULL, TARGET_HOST);
98 (void)SCNetworkReachabilityGetFlags(target, &flags);
99 NSLog(@"- Reachability flags for "TARGET_HOST": %#x", flags);
100
101 CFRelease(target);
102 }
103
104 void
105 SCTest()
106 {
107 test_SCNetworkConfiguration();
108 test_SCNetworkReachability();
109 test_SCPreferences();
110 test_SCDynamicStore();
111 }
112
113 int main(int argc, const char * argv[]) {
114 @autoreleasepool {
115 SCTest();
116 }
117 return 0;
118 }