Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
cc5a6f76
Commit
cc5a6f76
authored
Nov 22, 2014
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #72.
parent
dc44fee8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
4 deletions
+26
-4
async-io-test.c++
c++/src/kj/async-io-test.c++
+26
-4
No files found.
c++/src/kj/async-io-test.c++
View file @
cc5a6f76
...
...
@@ -23,6 +23,9 @@
#include "async-unix.h"
#include "debug.h"
#include <gtest/gtest.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
namespace
kj
{
namespace
{
...
...
@@ -69,6 +72,20 @@ String tryParse(WaitScope& waitScope, Network& network, StringPtr text, uint por
return
network
.
parseAddress
(
text
,
portHint
).
wait
(
waitScope
)
->
toString
();
}
bool
hasIpv6
()
{
// Can getaddrinfo() parse ipv6 addresses? This is only true if ipv6 is configured on at least
// one interface. (The loopback interface usually has it even if others don't... but not always.)
struct
addrinfo
*
list
;
int
status
=
getaddrinfo
(
"::"
,
nullptr
,
nullptr
,
&
list
);
if
(
status
==
0
)
{
freeaddrinfo
(
list
);
return
true
;
}
else
{
KJ_FAIL_ASSERT
(
"foo"
);
return
false
;
}
}
TEST
(
AsyncIo
,
AddressParsing
)
{
auto
ioContext
=
setupAsyncIo
();
auto
&
w
=
ioContext
.
waitScope
;
...
...
@@ -76,19 +93,24 @@ TEST(AsyncIo, AddressParsing) {
EXPECT_EQ
(
"*:0"
,
tryParse
(
w
,
network
,
"*"
));
EXPECT_EQ
(
"*:123"
,
tryParse
(
w
,
network
,
"*:123"
));
EXPECT_EQ
(
"[::]:123"
,
tryParse
(
w
,
network
,
"0::0"
,
123
));
EXPECT_EQ
(
"0.0.0.0:0"
,
tryParse
(
w
,
network
,
"0.0.0.0"
));
EXPECT_EQ
(
"1.2.3.4:5678"
,
tryParse
(
w
,
network
,
"1.2.3.4"
,
5678
));
EXPECT_EQ
(
"[12ab:cd::34]:321"
,
tryParse
(
w
,
network
,
"[12ab:cd:0::0:34]:321"
,
432
));
EXPECT_EQ
(
"unix:foo/bar/baz"
,
tryParse
(
w
,
network
,
"unix:foo/bar/baz"
));
// We can parse services by name...
EXPECT_EQ
(
"1.2.3.4:80"
,
tryParse
(
w
,
network
,
"1.2.3.4:http"
,
5678
));
EXPECT_EQ
(
"[::]:80"
,
tryParse
(
w
,
network
,
"[::]:http"
,
5678
));
EXPECT_EQ
(
"[12ab:cd::34]:80"
,
tryParse
(
w
,
network
,
"[12ab:cd::34]:http"
,
5678
));
EXPECT_EQ
(
"*:80"
,
tryParse
(
w
,
network
,
"*:http"
,
5678
));
// IPv6 tests. Annoyingly, these don't work on machines that don't have IPv6 configured on any
// interfaces.
if
(
hasIpv6
())
{
EXPECT_EQ
(
"[::]:123"
,
tryParse
(
w
,
network
,
"0::0"
,
123
));
EXPECT_EQ
(
"[12ab:cd::34]:321"
,
tryParse
(
w
,
network
,
"[12ab:cd:0::0:34]:321"
,
432
));
EXPECT_EQ
(
"[::]:80"
,
tryParse
(
w
,
network
,
"[::]:http"
,
5678
));
EXPECT_EQ
(
"[12ab:cd::34]:80"
,
tryParse
(
w
,
network
,
"[12ab:cd::34]:http"
,
5678
));
}
// It would be nice to test DNS lookup here but the test would not be very hermetic. Even
// localhost can map to different addresses depending on whether IPv6 is enabled. We do
// connect to "localhost" in a different test, though.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment