Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
992c254e
Commit
992c254e
authored
Nov 17, 2012
by
Davis King
Browse files
Added unit test for iosockstream.
parent
60d725a1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
111 additions
and
1 deletion
+111
-1
dlib/test/CMakeLists.txt
dlib/test/CMakeLists.txt
+1
-0
dlib/test/iosockstream.cpp
dlib/test/iosockstream.cpp
+108
-0
dlib/test/makefile
dlib/test/makefile
+2
-1
No files found.
dlib/test/CMakeLists.txt
View file @
992c254e
...
...
@@ -55,6 +55,7 @@ set (tests
hash_table.cpp
hog_image.cpp
image.cpp
iosockstream.cpp
is_same_object.cpp
kcentroid.cpp
kernel_matrix.cpp
...
...
dlib/test/iosockstream.cpp
0 → 100644
View file @
992c254e
// Copyright (C) 2012 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#include <sstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <dlib/iosockstream.h>
#include <dlib/server.h>
#include <vector>
#include "tester.h"
namespace
{
using
namespace
test
;
using
namespace
dlib
;
using
namespace
std
;
logger
dlog
(
"test.iosockstream"
);
// ----------------------------------------------------------------------------------------
class
serv
:
public
server_iostream
{
virtual
void
on_connect
(
std
::
istream
&
in
,
std
::
ostream
&
out
,
const
std
::
string
&
,
const
std
::
string
&
,
unsigned
short
,
unsigned
short
,
uint64
)
{
try
{
dlog
<<
LINFO
<<
"serving connection"
;
std
::
string
temp
;
in
>>
temp
;
DLIB_TEST
(
temp
==
"word"
);
in
>>
temp
;
DLIB_TEST
(
temp
==
"another"
);
out
<<
"yay words "
;
in
>>
temp
;
DLIB_TEST
(
temp
==
"yep"
);
}
catch
(
error
&
e
)
{
error_string
=
e
.
what
();
}
}
public:
std
::
string
error_string
;
};
// ----------------------------------------------------------------------------------------
class
test_iosockstream
:
public
tester
{
public:
test_iosockstream
(
)
:
tester
(
"test_iosockstream"
,
"Runs tests on the iosockstream component."
)
{}
void
perform_test
(
)
{
serv
theserv
;
theserv
.
set_listening_port
(
12345
);
theserv
.
start_async
();
for
(
int
i
=
0
;
i
<
1001
;
++
i
)
{
print_spinner
();
iosockstream
stream
(
"localhost:12345"
);
stream
<<
"word another "
;
std
::
string
temp
;
stream
>>
temp
;
DLIB_TEST
(
temp
==
"yay"
);
stream
>>
temp
;
DLIB_TEST
(
temp
==
"words"
);
stream
<<
"yep "
;
}
// Just to make sure the server finishes processing the last connection before
// we kill it and accidentally trigger a DLIB_TEST().
dlib
::
sleep
(
500
);
if
(
theserv
.
error_string
.
size
()
!=
0
)
throw
error
(
theserv
.
error_string
);
}
}
a
;
}
dlib/test/makefile
View file @
992c254e
...
...
@@ -70,6 +70,7 @@ SRC += hash_set.cpp
SRC
+=
hash_table.cpp
SRC
+=
hog_image.cpp
SRC
+=
image.cpp
SRC
+=
iosockstream.cpp
SRC
+=
is_same_object.cpp
SRC
+=
kcentroid.cpp
SRC
+=
kernel_matrix.cpp
...
...
@@ -95,11 +96,11 @@ SRC += multithreaded_object.cpp
SRC
+=
object_detector.cpp
SRC
+=
oca.cpp
SRC
+=
one_vs_all_trainer.cpp
SRC
+=
parse.cpp
SRC
+=
one_vs_one_trainer.cpp
SRC
+=
optimization.cpp
SRC
+=
optimization_test_functions.cpp
SRC
+=
opt_qp_solver.cpp
SRC
+=
parse.cpp
SRC
+=
pipe.cpp
SRC
+=
pixel.cpp
SRC
+=
probabilistic.cpp
...
...
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