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
4807ab06
Commit
4807ab06
authored
Nov 18, 2012
by
Davis King
Browse files
Added unit tests for the vectorstream.
parent
e6d7f93d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
144 additions
and
0 deletions
+144
-0
dlib/test/CMakeLists.txt
dlib/test/CMakeLists.txt
+1
-0
dlib/test/makefile
dlib/test/makefile
+1
-0
dlib/test/vectorstream.cpp
dlib/test/vectorstream.cpp
+142
-0
No files found.
dlib/test/CMakeLists.txt
View file @
4807ab06
...
@@ -124,6 +124,7 @@ set (tests
...
@@ -124,6 +124,7 @@ set (tests
timer.cpp
timer.cpp
tokenizer.cpp
tokenizer.cpp
trust_region.cpp
trust_region.cpp
vectorstream.cpp
tuple.cpp
tuple.cpp
type_safe_union.cpp
type_safe_union.cpp
)
)
...
...
dlib/test/makefile
View file @
4807ab06
...
@@ -141,6 +141,7 @@ SRC += tokenizer.cpp
...
@@ -141,6 +141,7 @@ SRC += tokenizer.cpp
SRC
+=
trust_region.cpp
SRC
+=
trust_region.cpp
SRC
+=
tuple.cpp
SRC
+=
tuple.cpp
SRC
+=
type_safe_union.cpp
SRC
+=
type_safe_union.cpp
SRC
+=
vectorstream.cpp
####################################################
####################################################
...
...
dlib/test/vectorstream.cpp
0 → 100644
View file @
4807ab06
// Copyright (C) 2012 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#include <dlib/vectorstream.h>
#include <sstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <vector>
#include "tester.h"
namespace
{
using
namespace
test
;
using
namespace
dlib
;
using
namespace
std
;
logger
dlog
(
"test.vectorstream"
);
// ----------------------------------------------------------------------------------------
void
test1
()
{
print_spinner
();
std
::
vector
<
char
>
buf
;
vectorstream
s
(
buf
);
for
(
int
i
=
-
1000
;
i
<=
1000
;
++
i
)
{
char
ch
=
i
;
s
.
put
(
ch
);
}
DLIB_TEST
(
buf
.
size
()
==
2001
);
int
cnt
=
-
1000
;
for
(
unsigned
long
i
=
0
;
i
<
buf
.
size
();
++
i
)
{
char
ch
=
cnt
;
DLIB_TEST
(
buf
[
i
]
==
ch
);
++
cnt
;
}
for
(
int
i
=
-
1000
;
i
<=
1000
;
++
i
)
{
DLIB_TEST
(
s
.
peek
()
!=
EOF
)
char
ch1
=
i
;
char
ch2
=
s
.
get
();
DLIB_TEST
(
ch1
==
ch2
);
}
DLIB_TEST
(
s
.
peek
()
==
EOF
);
DLIB_TEST
(
s
.
get
()
==
EOF
);
s
.
clear
();
s
.
seekg
(
6
);
for
(
int
i
=
-
1000
+
6
;
i
<=
1000
;
++
i
)
{
DLIB_TEST
(
s
.
peek
()
!=
EOF
)
char
ch1
=
i
;
char
ch2
=
s
.
get
();
DLIB_TEST
(
ch1
==
ch2
);
}
DLIB_TEST
(
s
.
peek
()
==
EOF
);
DLIB_TEST
(
s
.
get
()
==
EOF
);
std
::
string
temp
;
temp
=
"one two three!"
;
s
.
seekg
(
0
);
buf
.
clear
();
s
.
clear
();
serialize
(
temp
,
s
);
std
::
string
temp2
;
deserialize
(
temp2
,
s
);
DLIB_TEST
(
temp2
==
temp
);
s
.
put
(
'1'
);
s
.
put
(
'2'
);
s
.
put
(
'3'
);
s
.
put
(
'4'
);
DLIB_TEST
(
s
.
get
()
==
'1'
);
DLIB_TEST
(
s
.
get
()
==
'2'
);
DLIB_TEST
(
s
.
get
()
==
'3'
);
DLIB_TEST
(
s
.
get
()
==
'4'
);
s
.
putback
(
'4'
);
DLIB_TEST
(
s
.
get
()
==
'4'
);
s
.
putback
(
'4'
);
s
.
putback
(
'3'
);
s
.
putback
(
'2'
);
s
.
putback
(
'1'
);
DLIB_TEST
(
s
.
get
()
==
'1'
);
DLIB_TEST
(
s
.
get
()
==
'2'
);
DLIB_TEST
(
s
.
get
()
==
'3'
);
DLIB_TEST
(
s
.
get
()
==
'4'
);
DLIB_TEST
(
s
.
good
()
==
true
);
DLIB_TEST
(
s
.
get
()
==
EOF
);
DLIB_TEST
(
s
.
good
()
==
false
);
// make sure seeking to a crazy offset doesn't mess things up
s
.
clear
();
s
.
seekg
(
1000000
);
DLIB_TEST
(
s
.
get
()
==
EOF
);
DLIB_TEST
(
s
.
good
()
==
false
);
s
.
clear
();
s
.
seekg
(
1000000
);
char
sbuf
[
100
];
s
.
read
(
sbuf
,
sizeof
(
sbuf
));
DLIB_TEST
(
s
.
good
()
==
false
);
}
// ----------------------------------------------------------------------------------------
class
test_vectorstream
:
public
tester
{
public:
test_vectorstream
(
)
:
tester
(
"test_vectorstream"
,
"Runs tests on the vectorstream component."
)
{}
void
perform_test
(
)
{
test1
();
}
}
a
;
}
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