Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
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
opencv
Commits
0a5d6e10
Commit
0a5d6e10
authored
Mar 21, 2014
by
Koji Miyazato
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test code for I/O of user-defined types.
parent
a43ef9a6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
0 deletions
+43
-0
test_io.cpp
modules/core/test/test_io.cpp
+43
-0
No files found.
modules/core/test/test_io.cpp
View file @
0a5d6e10
...
...
@@ -380,6 +380,40 @@ TEST(Core_InputOutput, write_read_consistency) { Core_IOTest test; test.safe_run
extern
void
testFormatter
();
struct
UserDefinedType
{
int
a
;
float
b
;
};
static
inline
bool
operator
==
(
const
UserDefinedType
&
x
,
const
UserDefinedType
&
y
)
{
return
(
x
.
a
==
y
.
a
)
&&
(
x
.
b
==
y
.
b
);
}
static
inline
void
write
(
FileStorage
&
fs
,
const
String
&
,
const
UserDefinedType
&
value
)
{
fs
<<
"{:"
<<
"a"
<<
value
.
a
<<
"b"
<<
value
.
b
<<
"}"
;
}
static
inline
void
read
(
const
FileNode
&
node
,
UserDefinedType
&
value
,
const
UserDefinedType
&
default_value
=
UserDefinedType
())
{
if
(
node
.
empty
())
{
value
=
default_value
;
}
else
{
node
[
"a"
]
>>
value
.
a
;
node
[
"b"
]
>>
value
.
b
;
}
}
class
CV_MiscIOTest
:
public
cvtest
::
BaseTest
{
public
:
...
...
@@ -393,11 +427,14 @@ protected:
string
fname
=
cv
::
tempfile
(
".xml"
);
vector
<
int
>
mi
,
mi2
,
mi3
,
mi4
;
vector
<
Mat
>
mv
,
mv2
,
mv3
,
mv4
;
vector
<
UserDefinedType
>
vudt
,
vudt2
,
vudt3
,
vudt4
;
Mat
m
(
10
,
9
,
CV_32F
);
Mat
empty
;
UserDefinedType
udt
=
{
8
,
3.3
f
};
randu
(
m
,
0
,
1
);
mi3
.
push_back
(
5
);
mv3
.
push_back
(
m
);
vudt3
.
push_back
(
udt
);
Point_
<
float
>
p1
(
1.1
f
,
2.2
f
),
op1
;
Point3i
p2
(
3
,
4
,
5
),
op2
;
Size
s1
(
6
,
7
),
os1
;
...
...
@@ -412,6 +449,8 @@ protected:
fs
<<
"mv"
<<
mv
;
fs
<<
"mi3"
<<
mi3
;
fs
<<
"mv3"
<<
mv3
;
fs
<<
"vudt"
<<
vudt
;
fs
<<
"vudt3"
<<
vudt3
;
fs
<<
"empty"
<<
empty
;
fs
<<
"p1"
<<
p1
;
fs
<<
"p2"
<<
p2
;
...
...
@@ -428,6 +467,8 @@ protected:
fs
[
"mv"
]
>>
mv2
;
fs
[
"mi3"
]
>>
mi4
;
fs
[
"mv3"
]
>>
mv4
;
fs
[
"vudt"
]
>>
vudt2
;
fs
[
"vudt3"
]
>>
vudt4
;
fs
[
"empty"
]
>>
empty
;
fs
[
"p1"
]
>>
op1
;
fs
[
"p2"
]
>>
op2
;
...
...
@@ -442,6 +483,8 @@ protected:
CV_Assert
(
norm
(
mi3
,
mi4
,
CV_C
)
==
0
);
CV_Assert
(
mv4
.
size
()
==
1
);
double
n
=
norm
(
mv3
[
0
],
mv4
[
0
],
CV_C
);
CV_Assert
(
vudt2
.
empty
()
);
CV_Assert
(
vudt3
==
vudt4
);
CV_Assert
(
n
==
0
);
CV_Assert
(
op1
==
p1
);
CV_Assert
(
op2
==
p2
);
...
...
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