Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
6caf9113
Commit
6caf9113
authored
9 years ago
by
Jorge Canizales
Browse files
Options
Downloads
Patches
Plain Diff
Add a few unit tests for GRX
parent
ad0965ed
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/objective-c/tests/RxLibraryUnitTests.m
+87
-15
87 additions, 15 deletions
src/objective-c/tests/RxLibraryUnitTests.m
with
87 additions
and
15 deletions
src/objective-c/tests/RxLibraryUnitTests.m
+
87
−
15
View file @
6caf9113
...
@@ -34,35 +34,107 @@
...
@@ -34,35 +34,107 @@
#import <UIKit/UIKit.h>
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import <XCTest/XCTest.h>
#import <gRPC/GRXBufferedPipe.h>
#import <gRPC/GRXWriter.h>
#import <gRPC/GRXWriter.h>
#import <gRPC/GRXWriteable.h>
#import <gRPC/GRXWriteable.h>
@interface
RxLibraryUnitTests
:
XCTestCase
// A mock of a GRXSingleValueHandler block that can be queried for how many times it was called and
// what were the last values passed to it.
//
// TODO(jcanizales): Move this to a test util library, and add tests for it.
@interface
CapturingSingleValueHandler
:
NSObject
@property
(
nonatomic
,
readonly
)
void
(
^
block
)(
id
value
,
NSError
*
errorOrNil
);
@property
(
nonatomic
,
readonly
)
NSUInteger
timesCalled
;
@property
(
nonatomic
,
readonly
)
id
value
;
@property
(
nonatomic
,
readonly
)
NSError
*
errorOrNil
;
+
(
instancetype
)
handler
;
@end
@implementation
CapturingSingleValueHandler
+
(
instancetype
)
handler
{
return
[[
self
alloc
]
init
];
}
-
(
GRXSingleValueHandler
)
block
{
return
^
(
id
value
,
NSError
*
errorOrNil
)
{
++
_timesCalled
;
_value
=
value
;
_errorOrNil
=
errorOrNil
;
};
}
@end
@interface
RxLibraryUnitTests
:
XCTestCase
@end
@end
@implementation
RxLibraryUnitTests
@implementation
RxLibraryUnitTests
-
(
void
)
setUp
{
#pragma mark Writeable
[
super
setUp
];
// Put setup code here. This method is called before the invocation of each test method in the class.
-
(
void
)
testWriteableSingleValueHandlerIsCalledForValue
{
// Given:
CapturingSingleValueHandler
*
handler
=
[
CapturingSingleValueHandler
handler
];
id
anyValue
=
@7
;
// If:
id
<
GRXWriteable
>
writeable
=
[
GRXWriteable
writeableWithSingleValueHandler
:
handler
.
block
];
[
writeable
writeValue
:
anyValue
];
// Then:
XCTAssertEqual
(
handler
.
timesCalled
,
1
);
XCTAssertEqualObjects
(
handler
.
value
,
anyValue
);
XCTAssertEqualObjects
(
handler
.
errorOrNil
,
nil
);
}
}
-
(
void
)
tearDown
{
-
(
void
)
testWriteableSingleValueHandlerIsCalledForError
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
// Given:
[
super
tearDown
];
CapturingSingleValueHandler
*
handler
=
[
CapturingSingleValueHandler
handler
];
NSError
*
anyError
=
[
NSError
errorWithDomain
:
@"domain"
code
:
7
userInfo
:
nil
];
// If:
id
<
GRXWriteable
>
writeable
=
[
GRXWriteable
writeableWithSingleValueHandler
:
handler
.
block
];
[
writeable
writesFinishedWithError
:
anyError
];
// Then:
XCTAssertEqual
(
handler
.
timesCalled
,
1
);
XCTAssertEqualObjects
(
handler
.
value
,
nil
);
XCTAssertEqualObjects
(
handler
.
errorOrNil
,
anyError
);
}
}
-
(
void
)
testExample
{
#pragma mark BufferedPipe
// This is an example of a functional test case.
XCTAssert
(
YES
,
@"Pass"
);
-
(
void
)
testBufferedPipePropagatesValue
{
// Given:
CapturingSingleValueHandler
*
handler
=
[
CapturingSingleValueHandler
handler
];
id
<
GRXWriteable
>
writeable
=
[
GRXWriteable
writeableWithSingleValueHandler
:
handler
.
block
];
id
anyValue
=
@7
;
// If:
GRXBufferedPipe
*
pipe
=
[
GRXBufferedPipe
pipe
];
[
pipe
startWithWriteable
:
writeable
];
[
pipe
writeValue
:
anyValue
];
// Then:
XCTAssertEqual
(
handler
.
timesCalled
,
1
);
XCTAssertEqualObjects
(
handler
.
value
,
anyValue
);
XCTAssertEqualObjects
(
handler
.
errorOrNil
,
nil
);
}
}
-
(
void
)
testPerformanceExample
{
-
(
void
)
testBufferedPipePropagatesError
{
// This is an example of a performance test case.
// Given:
[
self
measureBlock
:
^
{
CapturingSingleValueHandler
*
handler
=
[
CapturingSingleValueHandler
handler
];
// Put the code you want to measure the time of here.
id
<
GRXWriteable
>
writeable
=
[
GRXWriteable
writeableWithSingleValueHandler
:
handler
.
block
];
}];
NSError
*
anyError
=
[
NSError
errorWithDomain
:
@"domain"
code
:
7
userInfo
:
nil
];
// If:
GRXBufferedPipe
*
pipe
=
[
GRXBufferedPipe
pipe
];
[
pipe
startWithWriteable
:
writeable
];
[
pipe
writesFinishedWithError
:
anyError
];
// Then:
XCTAssertEqual
(
handler
.
timesCalled
,
1
);
XCTAssertEqualObjects
(
handler
.
value
,
nil
);
XCTAssertEqualObjects
(
handler
.
errorOrNil
,
anyError
);
}
}
@end
@end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment