Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sxychenjing
engine
提交
933f83e3
E
engine
项目概览
sxychenjing
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
933f83e3
编写于
9月 20, 2019
作者:
G
gaaclarke
提交者:
GitHub
9月 20, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added unit tests for method channels. (#12373)
Added unit tests for method channels.
上级
48bb77c4
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
156 addition
and
0 deletion
+156
-0
ci/licenses_golden/licenses_flutter
ci/licenses_golden/licenses_flutter
+1
-0
shell/platform/darwin/common/framework/Source/FlutterChannelsTest.m
...form/darwin/common/framework/Source/FlutterChannelsTest.m
+142
-0
testing/ios/IosUnitTests/IosUnitTests.xcodeproj/project.pbxproj
...g/ios/IosUnitTests/IosUnitTests.xcodeproj/project.pbxproj
+13
-0
未找到文件。
ci/licenses_golden/licenses_flutter
浏览文件 @
933f83e3
...
...
@@ -715,6 +715,7 @@ FILE: ../../../flutter/shell/platform/darwin/common/framework/Headers/FlutterCha
FILE: ../../../flutter/shell/platform/darwin/common/framework/Headers/FlutterCodecs.h
FILE: ../../../flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterChannels.mm
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterChannelsTest.m
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterCodecs.mm
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodec.mm
FILE: ../../../flutter/shell/platform/darwin/common/framework/Source/FlutterStandardCodec_Internal.h
...
...
shell/platform/darwin/common/framework/Source/FlutterChannelsTest.m
0 → 100644
浏览文件 @
933f83e3
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#if !__has_feature(objc_arc)
#error ARC must be enabled!
#endif
#import <OCMock/OCMock.h>
#import <XCTest/XCTest.h>
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterChannels.h"
@interface
MockBinaryMessenger
:
NSObject
<
FlutterBinaryMessenger
>
@property
(
nonatomic
,
copy
)
NSString
*
channel
;
@property
(
nonatomic
,
strong
)
NSData
*
message
;
@property
(
nonatomic
,
strong
)
NSMutableDictionary
<
NSString
*
,
FlutterBinaryMessageHandler
>*
handlers
;
@end
@implementation
MockBinaryMessenger
-
(
instancetype
)
init
{
self
=
[
super
init
];
if
(
self
)
{
_handlers
=
[[
NSMutableDictionary
<
NSString
*
,
FlutterBinaryMessageHandler
>
alloc
]
init
];
}
return
self
;
}
-
(
void
)
sendOnChannel
:(
NSString
*
)
channel
message
:(
NSData
*
_Nullable
)
message
{
[
self
sendOnChannel
:
channel
message
:
message
binaryReply
:
nil
];
}
-
(
void
)
sendOnChannel
:(
NSString
*
)
channel
message
:(
NSData
*
_Nullable
)
message
binaryReply
:(
FlutterBinaryReply
_Nullable
)
callback
{
self
.
channel
=
channel
;
self
.
message
=
message
;
}
-
(
void
)
setMessageHandlerOnChannel
:(
NSString
*
)
channel
binaryMessageHandler
:(
FlutterBinaryMessageHandler
_Nullable
)
handler
{
[
self
.
handlers
setObject
:
handler
forKey
:
channel
];
}
@end
@interface
FlutterChannelsTest
:
XCTestCase
@end
@implementation
FlutterChannelsTest
-
(
void
)
testMethodInvoke
{
NSString
*
channelName
=
@"foo"
;
id
binaryMessenger
=
OCMProtocolMock
(
@protocol
(
FlutterBinaryMessenger
));
id
codec
=
OCMProtocolMock
(
@protocol
(
FlutterMethodCodec
));
FlutterMethodChannel
*
channel
=
[[
FlutterMethodChannel
alloc
]
initWithName
:
channelName
binaryMessenger:
binaryMessenger
codec:
codec
];
XCTAssertNotNil
(
channel
);
NSData
*
encodedMethodCall
=
[
@"hey"
dataUsingEncoding
:
NSUTF8StringEncoding
];
OCMStub
([
codec
encodeMethodCall
:[
OCMArg
any
]]).
andReturn
(
encodedMethodCall
);
[
channel
invokeMethod
:
@"foo"
arguments
:@[
@
(
1
)
]];
OCMVerify
([
binaryMessenger
sendOnChannel
:
channelName
message
:
encodedMethodCall
]);
}
-
(
void
)
testMethodInvokeWithReply
{
NSString
*
channelName
=
@"foo"
;
id
binaryMessenger
=
OCMProtocolMock
(
@protocol
(
FlutterBinaryMessenger
));
id
codec
=
OCMProtocolMock
(
@protocol
(
FlutterMethodCodec
));
FlutterMethodChannel
*
channel
=
[[
FlutterMethodChannel
alloc
]
initWithName
:
channelName
binaryMessenger:
binaryMessenger
codec:
codec
];
XCTAssertNotNil
(
channel
);
NSData
*
encodedMethodCall
=
[
@"hey"
dataUsingEncoding
:
NSUTF8StringEncoding
];
OCMStub
([
codec
encodeMethodCall
:[
OCMArg
any
]]).
andReturn
(
encodedMethodCall
);
XCTestExpectation
*
didCallReply
=
[
self
expectationWithDescription
:
@"didCallReply"
];
OCMExpect
([
binaryMessenger
sendOnChannel
:
channelName
message:
encodedMethodCall
binaryReply:
[
OCMArg
checkWithBlock
:
^
BOOL
(
id
obj
)
{
FlutterBinaryReply
reply
=
obj
;
reply
(
nil
);
return
YES
;
}]]);
[
channel
invokeMethod
:
@"foo"
arguments:
@[
@1
]
result:
^
(
id
_Nullable
result
)
{
[
didCallReply
fulfill
];
XCTAssertEqual
(
FlutterMethodNotImplemented
,
result
);
}];
OCMVerifyAll
(
binaryMessenger
);
[
self
waitForExpectationsWithTimeout
:
1
.
0
handler
:
nil
];
}
-
(
void
)
testMethodMessageHandler
{
NSString
*
channelName
=
@"foo"
;
id
binaryMessenger
=
OCMProtocolMock
(
@protocol
(
FlutterBinaryMessenger
));
id
codec
=
OCMProtocolMock
(
@protocol
(
FlutterMethodCodec
));
FlutterMethodChannel
*
channel
=
[[
FlutterMethodChannel
alloc
]
initWithName
:
channelName
binaryMessenger:
binaryMessenger
codec:
codec
];
XCTAssertNotNil
(
channel
);
NSData
*
encodedMethodCall
=
[
@"hey"
dataUsingEncoding
:
NSUTF8StringEncoding
];
OCMStub
([
codec
encodeMethodCall
:[
OCMArg
any
]]).
andReturn
(
encodedMethodCall
);
FlutterMethodCallHandler
handler
=
^
(
FlutterMethodCall
*
_Nonnull
call
,
FlutterResult
_Nonnull
result
)
{
NSLog
(
@"hey"
);
};
[
channel
setMethodCallHandler
:
handler
];
OCMVerify
([
binaryMessenger
setMessageHandlerOnChannel
:
channelName
binaryMessageHandler:
[
OCMArg
isNotNil
]]);
}
-
(
void
)
testCallMethodHandler
{
NSString
*
channelName
=
@"foo"
;
MockBinaryMessenger
*
binaryMessenger
=
[[
MockBinaryMessenger
alloc
]
init
];
id
codec
=
OCMProtocolMock
(
@protocol
(
FlutterMethodCodec
));
FlutterMethodChannel
*
channel
=
[[
FlutterMethodChannel
alloc
]
initWithName
:
channelName
binaryMessenger:
binaryMessenger
codec:
codec
];
XCTAssertNotNil
(
channel
);
NSData
*
encodedMethodCall
=
[
@"encoded"
dataUsingEncoding
:
NSUTF8StringEncoding
];
NSData
*
replyData
=
[
@"reply"
dataUsingEncoding
:
NSUTF8StringEncoding
];
NSData
*
replyEnvelopeData
=
[
@"reply-envelope"
dataUsingEncoding
:
NSUTF8StringEncoding
];
FlutterMethodCall
*
methodCall
=
[[
FlutterMethodCall
alloc
]
init
];
OCMStub
([
codec
decodeMethodCall
:
encodedMethodCall
]).
andReturn
(
methodCall
);
OCMStub
([
codec
encodeSuccessEnvelope
:
replyData
]).
andReturn
(
replyEnvelopeData
);
XCTestExpectation
*
didCallHandler
=
[
self
expectationWithDescription
:
@"didCallHandler"
];
XCTestExpectation
*
didCallReply
=
[
self
expectationWithDescription
:
@"didCallReply"
];
FlutterMethodCallHandler
handler
=
^
(
FlutterMethodCall
*
_Nonnull
call
,
FlutterResult
_Nonnull
result
)
{
XCTAssertEqual
(
methodCall
,
call
);
[
didCallHandler
fulfill
];
result
(
replyData
);
};
[
channel
setMethodCallHandler
:
handler
];
binaryMessenger
.
handlers
[
channelName
](
encodedMethodCall
,
^
(
NSData
*
reply
)
{
[
didCallReply
fulfill
];
XCTAssertEqual
(
replyEnvelopeData
,
reply
);
});
[
self
waitForExpectationsWithTimeout
:
1
.
0
handler
:
nil
];
}
@end
testing/ios/IosUnitTests/IosUnitTests.xcodeproj/project.pbxproj
浏览文件 @
933f83e3
...
...
@@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */
0D17A5C022D78FCD0057279F
/* FlutterViewControllerTest.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
0D17A5BF22D78FCD0057279F
/* FlutterViewControllerTest.m */
;
settings
=
{
COMPILER_FLAGS
=
"-fobjc-arc"
;
};
};
0D1CE5D8233430F400E5D880
/* FlutterChannelsTest.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
0D1CE5D7233430F400E5D880
/* FlutterChannelsTest.m */
;
settings
=
{
COMPILER_FLAGS
=
"-fobjc-arc"
;
};
};
0D4C3FB022DF9F5300A67C70
/* FlutterPluginAppLifeCycleDelegateTest.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
0D4C3FAF22DF9F5300A67C70
/* FlutterPluginAppLifeCycleDelegateTest.m */
;
settings
=
{
COMPILER_FLAGS
=
"-fobjc-arc"
;
};
};
0D52D3BD22C566D50011DEBD
/* FlutterBinaryMessengerRelayTest.mm in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
0D52D3B622C566D50011DEBD
/* FlutterBinaryMessengerRelayTest.mm */
;
settings
=
{
COMPILER_FLAGS
=
"-fobjc-arc"
;
};
};
0D6AB6B622BB05E100EEE540
/* AppDelegate.m in Sources */
=
{
isa
=
PBXBuildFile
;
fileRef
=
0D6AB6B522BB05E100EEE540
/* AppDelegate.m */
;
};
...
...
@@ -75,6 +76,7 @@
/* Begin PBXFileReference section */
0D17A5BF22D78FCD0057279F
/* FlutterViewControllerTest.m */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
FlutterViewControllerTest.m
;
sourceTree
=
"<group>"
;
};
0D1CE5D7233430F400E5D880
/* FlutterChannelsTest.m */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
FlutterChannelsTest.m
;
sourceTree
=
"<group>"
;
};
0D4C3FAF22DF9F5300A67C70
/* FlutterPluginAppLifeCycleDelegateTest.m */
=
{
isa
=
PBXFileReference
;
lastKnownFileType
=
sourcecode.c.objc
;
path
=
FlutterPluginAppLifeCycleDelegateTest.m
;
sourceTree
=
"<group>"
;
};
0D52D3B622C566D50011DEBD
/* FlutterBinaryMessengerRelayTest.mm */
=
{
isa
=
PBXFileReference
;
fileEncoding
=
4
;
lastKnownFileType
=
sourcecode.cpp.objcpp
;
path
=
FlutterBinaryMessengerRelayTest.mm
;
sourceTree
=
"<group>"
;
};
0D6AB6B122BB05E100EEE540
/* IosUnitTests.app */
=
{
isa
=
PBXFileReference
;
explicitFileType
=
wrapper.application
;
includeInIndex
=
0
;
path
=
IosUnitTests.app
;
sourceTree
=
BUILT_PRODUCTS_DIR
;
};
...
...
@@ -113,6 +115,15 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
0D1CE5D62334309900E5D880
/* Source-Common */
=
{
isa
=
PBXGroup
;
children
=
(
0D1CE5D7233430F400E5D880
/* FlutterChannelsTest.m */
,
);
name
=
"Source-Common"
;
path
=
../../../../shell/platform/darwin/common/framework/Source
;
sourceTree
=
"<group>"
;
};
0D6AB6A822BB05E100EEE540
=
{
isa
=
PBXGroup
;
children
=
(
...
...
@@ -151,6 +162,7 @@
0D6AB6CC22BB05E200EEE540
/* Tests */
=
{
isa
=
PBXGroup
;
children
=
(
0D1CE5D62334309900E5D880
/* Source-Common */
,
0D6AB71722BC336100EEE540
/* OCMock.xcodeproj */
,
0D6AB6E622BB409F00EEE540
/* Source */
,
0D6AB6CF22BB05E200EEE540
/* Info.plist */
,
...
...
@@ -376,6 +388,7 @@
files
=
(
0D6AB6EB22BB40E700EEE540
/* FlutterEngineTest.mm in Sources */
,
0D17A5C022D78FCD0057279F
/* FlutterViewControllerTest.m in Sources */
,
0D1CE5D8233430F400E5D880
/* FlutterChannelsTest.m in Sources */
,
0D52D3BD22C566D50011DEBD
/* FlutterBinaryMessengerRelayTest.mm in Sources */
,
0D4C3FB022DF9F5300A67C70
/* FlutterPluginAppLifeCycleDelegateTest.m in Sources */
,
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录