Skip to content

Commit d1877ad

Browse files
committed
add test
1 parent b792be0 commit d1877ad

File tree

9 files changed

+397
-25
lines changed

9 files changed

+397
-25
lines changed

NetDiag.xcodeproj/project.pbxproj

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
/* Begin PBXBuildFile section */
1010
DF2B76EC1C33702D00643678 /* QNNPing.m in Sources */ = {isa = PBXBuildFile; fileRef = DF2B76EB1C33702D00643678 /* QNNPing.m */; };
1111
DF2B76F11C3B9DA100643678 /* QNNSimplePing.m in Sources */ = {isa = PBXBuildFile; fileRef = DF2B76F01C3B9DA100643678 /* QNNSimplePing.m */; };
12+
DF8DFFC51C60951D00174DA9 /* QNNNslookup.m in Sources */ = {isa = PBXBuildFile; fileRef = DF8DFFC41C60951D00174DA9 /* QNNNslookup.m */; };
13+
DF8DFFD21C61DA1B00174DA9 /* TcpPingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = DF8DFFD11C61DA1B00174DA9 /* TcpPingTest.m */; };
14+
DF8DFFD41C61DA1B00174DA9 /* libNetDiag.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DFCEC6451C2EC01D0058EE65 /* libNetDiag.a */; };
1215
DF9D41FA1C57787500486F87 /* QNNTcpPing.m in Sources */ = {isa = PBXBuildFile; fileRef = DF9D41F91C57787500486F87 /* QNNTcpPing.m */; };
1316
DF9D41FD1C57789B00486F87 /* QNNUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = DF9D41FC1C57789B00486F87 /* QNNUtil.m */; };
1417
DF9D42001C5778B600486F87 /* QNNRtmp.m in Sources */ = {isa = PBXBuildFile; fileRef = DF9D41FF1C5778B600486F87 /* QNNRtmp.m */; };
@@ -17,6 +20,16 @@
1720
DFCEC6491C2EC01D0058EE65 /* QNNetDiag.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = DFCEC6481C2EC01D0058EE65 /* QNNetDiag.h */; };
1821
/* End PBXBuildFile section */
1922

23+
/* Begin PBXContainerItemProxy section */
24+
DF8DFFD51C61DA1B00174DA9 /* PBXContainerItemProxy */ = {
25+
isa = PBXContainerItemProxy;
26+
containerPortal = DFCEC63D1C2EC01D0058EE65 /* Project object */;
27+
proxyType = 1;
28+
remoteGlobalIDString = DFCEC6441C2EC01D0058EE65;
29+
remoteInfo = NetDiag;
30+
};
31+
/* End PBXContainerItemProxy section */
32+
2033
/* Begin PBXCopyFilesBuildPhase section */
2134
DFCEC6431C2EC01D0058EE65 /* CopyFiles */ = {
2235
isa = PBXCopyFilesBuildPhase;
@@ -36,6 +49,11 @@
3649
DF2B76ED1C33706900643678 /* QNNProtocols.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QNNProtocols.h; sourceTree = "<group>"; };
3750
DF2B76EF1C3B9DA100643678 /* QNNSimplePing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QNNSimplePing.h; sourceTree = "<group>"; };
3851
DF2B76F01C3B9DA100643678 /* QNNSimplePing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNNSimplePing.m; sourceTree = "<group>"; };
52+
DF8DFFC31C60951D00174DA9 /* QNNNslookup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QNNNslookup.h; sourceTree = "<group>"; };
53+
DF8DFFC41C60951D00174DA9 /* QNNNslookup.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNNNslookup.m; sourceTree = "<group>"; };
54+
DF8DFFCF1C61DA1B00174DA9 /* NetDiagTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NetDiagTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
55+
DF8DFFD11C61DA1B00174DA9 /* TcpPingTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TcpPingTest.m; sourceTree = "<group>"; };
56+
DF8DFFD31C61DA1B00174DA9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
3957
DF9D41F81C57787500486F87 /* QNNTcpPing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QNNTcpPing.h; sourceTree = "<group>"; };
4058
DF9D41F91C57787500486F87 /* QNNTcpPing.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNNTcpPing.m; sourceTree = "<group>"; };
4159
DF9D41FB1C57789B00486F87 /* QNNUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QNNUtil.h; sourceTree = "<group>"; };
@@ -51,6 +69,14 @@
5169
/* End PBXFileReference section */
5270

5371
/* Begin PBXFrameworksBuildPhase section */
72+
DF8DFFCC1C61DA1B00174DA9 /* Frameworks */ = {
73+
isa = PBXFrameworksBuildPhase;
74+
buildActionMask = 2147483647;
75+
files = (
76+
DF8DFFD41C61DA1B00174DA9 /* libNetDiag.a in Frameworks */,
77+
);
78+
runOnlyForDeploymentPostprocessing = 0;
79+
};
5480
DFCEC6421C2EC01D0058EE65 /* Frameworks */ = {
5581
isa = PBXFrameworksBuildPhase;
5682
buildActionMask = 2147483647;
@@ -61,10 +87,20 @@
6187
/* End PBXFrameworksBuildPhase section */
6288

6389
/* Begin PBXGroup section */
90+
DF8DFFD01C61DA1B00174DA9 /* NetDiagTests */ = {
91+
isa = PBXGroup;
92+
children = (
93+
DF8DFFD11C61DA1B00174DA9 /* TcpPingTest.m */,
94+
DF8DFFD31C61DA1B00174DA9 /* Info.plist */,
95+
);
96+
path = NetDiagTests;
97+
sourceTree = "<group>";
98+
};
6499
DFCEC63C1C2EC01D0058EE65 = {
65100
isa = PBXGroup;
66101
children = (
67102
DFCEC6471C2EC01D0058EE65 /* NetDiag */,
103+
DF8DFFD01C61DA1B00174DA9 /* NetDiagTests */,
68104
DFCEC6461C2EC01D0058EE65 /* Products */,
69105
);
70106
sourceTree = "<group>";
@@ -73,6 +109,7 @@
73109
isa = PBXGroup;
74110
children = (
75111
DFCEC6451C2EC01D0058EE65 /* libNetDiag.a */,
112+
DF8DFFCF1C61DA1B00174DA9 /* NetDiagTests.xctest */,
76113
);
77114
name = Products;
78115
sourceTree = "<group>";
@@ -96,13 +133,33 @@
96133
DF9D42021C5778EA00486F87 /* QNNTraceRoute.m */,
97134
DF9D42071C57BEFD00486F87 /* QNNExternalIp.h */,
98135
DF9D42081C57BEFD00486F87 /* QNNExternalIp.m */,
136+
DF8DFFC31C60951D00174DA9 /* QNNNslookup.h */,
137+
DF8DFFC41C60951D00174DA9 /* QNNNslookup.m */,
99138
);
100139
path = NetDiag;
101140
sourceTree = "<group>";
102141
};
103142
/* End PBXGroup section */
104143

105144
/* Begin PBXNativeTarget section */
145+
DF8DFFCE1C61DA1B00174DA9 /* NetDiagTests */ = {
146+
isa = PBXNativeTarget;
147+
buildConfigurationList = DF8DFFD71C61DA1B00174DA9 /* Build configuration list for PBXNativeTarget "NetDiagTests" */;
148+
buildPhases = (
149+
DF8DFFCB1C61DA1B00174DA9 /* Sources */,
150+
DF8DFFCC1C61DA1B00174DA9 /* Frameworks */,
151+
DF8DFFCD1C61DA1B00174DA9 /* Resources */,
152+
);
153+
buildRules = (
154+
);
155+
dependencies = (
156+
DF8DFFD61C61DA1B00174DA9 /* PBXTargetDependency */,
157+
);
158+
name = NetDiagTests;
159+
productName = NetDiagTests;
160+
productReference = DF8DFFCF1C61DA1B00174DA9 /* NetDiagTests.xctest */;
161+
productType = "com.apple.product-type.bundle.unit-test";
162+
};
106163
DFCEC6441C2EC01D0058EE65 /* NetDiag */ = {
107164
isa = PBXNativeTarget;
108165
buildConfigurationList = DFCEC64E1C2EC01D0058EE65 /* Build configuration list for PBXNativeTarget "NetDiag" */;
@@ -129,6 +186,9 @@
129186
LastUpgradeCheck = 0720;
130187
ORGANIZATIONNAME = "Qiniu Cloud Storage";
131188
TargetAttributes = {
189+
DF8DFFCE1C61DA1B00174DA9 = {
190+
CreatedOnToolsVersion = 7.2;
191+
};
132192
DFCEC6441C2EC01D0058EE65 = {
133193
CreatedOnToolsVersion = 7.2;
134194
};
@@ -147,15 +207,35 @@
147207
projectRoot = "";
148208
targets = (
149209
DFCEC6441C2EC01D0058EE65 /* NetDiag */,
210+
DF8DFFCE1C61DA1B00174DA9 /* NetDiagTests */,
150211
);
151212
};
152213
/* End PBXProject section */
153214

215+
/* Begin PBXResourcesBuildPhase section */
216+
DF8DFFCD1C61DA1B00174DA9 /* Resources */ = {
217+
isa = PBXResourcesBuildPhase;
218+
buildActionMask = 2147483647;
219+
files = (
220+
);
221+
runOnlyForDeploymentPostprocessing = 0;
222+
};
223+
/* End PBXResourcesBuildPhase section */
224+
154225
/* Begin PBXSourcesBuildPhase section */
226+
DF8DFFCB1C61DA1B00174DA9 /* Sources */ = {
227+
isa = PBXSourcesBuildPhase;
228+
buildActionMask = 2147483647;
229+
files = (
230+
DF8DFFD21C61DA1B00174DA9 /* TcpPingTest.m in Sources */,
231+
);
232+
runOnlyForDeploymentPostprocessing = 0;
233+
};
155234
DFCEC6411C2EC01D0058EE65 /* Sources */ = {
156235
isa = PBXSourcesBuildPhase;
157236
buildActionMask = 2147483647;
158237
files = (
238+
DF8DFFC51C60951D00174DA9 /* QNNNslookup.m in Sources */,
159239
DF2B76EC1C33702D00643678 /* QNNPing.m in Sources */,
160240
DF9D41FA1C57787500486F87 /* QNNTcpPing.m in Sources */,
161241
DF2B76F11C3B9DA100643678 /* QNNSimplePing.m in Sources */,
@@ -168,7 +248,35 @@
168248
};
169249
/* End PBXSourcesBuildPhase section */
170250

251+
/* Begin PBXTargetDependency section */
252+
DF8DFFD61C61DA1B00174DA9 /* PBXTargetDependency */ = {
253+
isa = PBXTargetDependency;
254+
target = DFCEC6441C2EC01D0058EE65 /* NetDiag */;
255+
targetProxy = DF8DFFD51C61DA1B00174DA9 /* PBXContainerItemProxy */;
256+
};
257+
/* End PBXTargetDependency section */
258+
171259
/* Begin XCBuildConfiguration section */
260+
DF8DFFD81C61DA1B00174DA9 /* Debug */ = {
261+
isa = XCBuildConfiguration;
262+
buildSettings = {
263+
INFOPLIST_FILE = NetDiagTests/Info.plist;
264+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
265+
PRODUCT_BUNDLE_IDENTIFIER = com.qiniu.NetDiagTests;
266+
PRODUCT_NAME = "$(TARGET_NAME)";
267+
};
268+
name = Debug;
269+
};
270+
DF8DFFD91C61DA1B00174DA9 /* Release */ = {
271+
isa = XCBuildConfiguration;
272+
buildSettings = {
273+
INFOPLIST_FILE = NetDiagTests/Info.plist;
274+
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
275+
PRODUCT_BUNDLE_IDENTIFIER = com.qiniu.NetDiagTests;
276+
PRODUCT_NAME = "$(TARGET_NAME)";
277+
};
278+
name = Release;
279+
};
172280
DFCEC64C1C2EC01D0058EE65 /* Debug */ = {
173281
isa = XCBuildConfiguration;
174282
buildSettings = {
@@ -270,6 +378,14 @@
270378
/* End XCBuildConfiguration section */
271379

272380
/* Begin XCConfigurationList section */
381+
DF8DFFD71C61DA1B00174DA9 /* Build configuration list for PBXNativeTarget "NetDiagTests" */ = {
382+
isa = XCConfigurationList;
383+
buildConfigurations = (
384+
DF8DFFD81C61DA1B00174DA9 /* Debug */,
385+
DF8DFFD91C61DA1B00174DA9 /* Release */,
386+
);
387+
defaultConfigurationIsVisible = 0;
388+
};
273389
DFCEC6401C2EC01D0058EE65 /* Build configuration list for PBXProject "NetDiag" */ = {
274390
isa = XCConfigurationList;
275391
buildConfigurations = (

NetDiag/QNNNslookup.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// QNNNslookup.h
3+
// NetDiag
4+
//
5+
// Created by bailong on 16/2/2.
6+
// Copyright © 2016年 Qiniu Cloud Storage. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface QNNNslookup : NSObject
12+
13+
@end

NetDiag/QNNNslookup.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// QNNNslookup.m
3+
// NetDiag
4+
//
5+
// Created by bailong on 16/2/2.
6+
// Copyright © 2016年 Qiniu Cloud Storage. All rights reserved.
7+
//
8+
9+
#import "QNNNslookup.h"
10+
11+
@implementation QNNNslookup
12+
13+
@end

NetDiag/QNNPing.h

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,32 @@
99
#import <Foundation/Foundation.h>
1010
#import "QNNProtocols.h"
1111

12-
@interface QNNPing : NSObject
12+
@interface QNNPingResult : NSObject
1313

14-
-(instancetype) init:(NSString*)dest;
14+
@property (readonly) NSInteger code;
15+
@property (readonly) NSInteger maxRtt;
16+
@property (readonly) NSInteger minRtt;
17+
@property (readonly) NSInteger avgRtt;
18+
@property (readonly) double lossRate;
19+
@property (readonly) NSInteger count;
20+
@property (readonly) NSInteger interval;
1521

16-
-(instancetype) init:(NSString*)dest count:(int)count;
22+
-(NSString*) description;
23+
24+
@end
25+
26+
typedef void (^QNNPingCompleteHandler)(QNNPingResult*) ;
27+
28+
@interface QNNPing : NSObject<QNNStopDelegate>
29+
30+
+(instancetype) start:(NSString*)host
31+
output:(id<QNNOutputDelegate>)output
32+
complete:(QNNPingCompleteHandler)complete;
33+
34+
+(instancetype) start:(NSString*)host
35+
output:(id<QNNOutputDelegate>)output
36+
complete:(QNNPingCompleteHandler)complete
37+
interval:(NSInteger)interval
38+
count:(NSInteger)count;
1739

1840
@end

NetDiag/QNNPing.m

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,22 @@ @interface QNNPing ()
1414

1515
@implementation QNNPing
1616

17-
-(instancetype) init:(NSString*)dest{
18-
return [self init:dest count:10];
17+
+(instancetype) start:(NSString*)host
18+
output:(id<QNNOutputDelegate>)output
19+
complete:(QNNPingCompleteHandler)complete{
20+
return [QNNPing start:host output:output complete:complete interval:200 count:10];
1921
}
2022

21-
-(instancetype) init:(NSString*)dest count:(int)count{
22-
23-
return self;
24-
}
25-
26-
-(void)setOutput:(id<QNNOutputDelegate>)output{
27-
_output = output;
28-
}
29-
30-
-(void)start{
31-
if (_output == nil) {
32-
return;
33-
}
23+
+(instancetype) start:(NSString*)host
24+
output:(id<QNNOutputDelegate>)output
25+
complete:(QNNPingCompleteHandler)complete
26+
interval:(NSInteger)interval
27+
count:(NSInteger)count{
28+
return nil;
3429
}
3530

3631
-(void)stop{
37-
32+
return;
3833
}
3934

4035
@end

NetDiag/QNNProtocols.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99

1010
#import <Foundation/Foundation.h>
1111

12-
@protocol QNNOutputDelegate <NSObject>
12+
@protocol QNNStopDelegate <NSObject>
13+
14+
-(void) stop;
15+
16+
@end
1317

14-
-(void) Write:(NSString*)line;
18+
@protocol QNNOutputDelegate <NSObject>
1519

16-
@optional
17-
-(void) setMaxLine:(int)number;
18-
-(void) end;
20+
-(void) write:(NSString*)line;
1921

2022
@end
23+

NetDiag/QNNTcpPing.h

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,41 @@
77
//
88

99
#import <Foundation/Foundation.h>
10+
#import "QNNProtocols.h"
1011

11-
@interface QNNTcpPing : NSObject
12+
@interface QNNTcpPingResult : NSObject
13+
14+
@property (readonly) NSInteger code;
15+
@property (readonly) NSInteger maxRtt;
16+
@property (readonly) NSInteger minRtt;
17+
@property (readonly) NSInteger avgRtt;
18+
@property (readonly) NSInteger count;
19+
20+
-(NSString*) description;
1221

1322
@end
23+
24+
typedef void (^QNNTcpPingCompleteHandler)(QNNTcpPingResult*);
25+
26+
@interface QNNTcpPing : NSObject<QNNStopDelegate>
27+
28+
/**
29+
* default port is 80
30+
*
31+
* @param host domain or ip
32+
* @param output output logger
33+
* @param complete complete callback, maybe null
34+
*
35+
* @return QNNTcpping instance, could be stop
36+
*/
37+
+(instancetype) start:(NSString*)host
38+
output:(id<QNNOutputDelegate>)output
39+
complete:(QNNTcpPingCompleteHandler)complete;
40+
41+
+(instancetype) start:(NSString*)host
42+
port:(NSUInteger)port
43+
output:(id<QNNOutputDelegate>)output
44+
complete:(QNNTcpPingCompleteHandler)complete
45+
count:(NSInteger)count;
46+
47+
@end

0 commit comments

Comments
 (0)