Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yaml-cpp
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
yaml-cpp
Commits
0fb59c18
Commit
0fb59c18
authored
May 22, 2012
by
Jesse Beder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split test struct and handler macros out for the emitter/spec tests
parent
115101d2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
14 deletions
+63
-14
test/create-emitter-tests.py
+10
-2
test/emittertests.cpp
+33
-0
test/handlermacros.h
+1
-2
test/spectests.h
+1
-10
test/teststruct.h
+18
-0
No files found.
test/create-emitter-tests.py
View file @
0fb59c18
...
...
@@ -61,8 +61,10 @@ def gen_tests():
def
create_emitter_tests
(
out
):
out
.
write
(
'namespace
%
s {
\n
'
%
NS
)
for
test
in
gen_tests
():
out
.
write
(
'inline TEST
%
s(YAML::Emitter& out)
\n
'
%
test
[
'name'
])
tests
=
list
(
gen_tests
())
for
test
in
tests
:
out
.
write
(
'TEST
%
s(YAML::Emitter& out)
\n
'
%
test
[
'name'
])
out
.
write
(
'{
\n
'
)
for
event
in
test
[
'events'
]:
emit
=
event
[
'emit'
]
...
...
@@ -82,5 +84,11 @@ def create_emitter_tests(out):
out
.
write
(
'}
\n
'
)
out
.
write
(
'void RunGenEmitterTests(int& passed, int& total)
\n
'
)
out
.
write
(
'{
\n
'
)
for
test
in
tests
:
out
.
write
(
' RunGenEmitterTest(&Emitter::
%
s,
%
s, passed, total);
\n
'
%
(
test
[
'name'
],
encode
(
test
[
'name'
])))
out
.
write
(
'}
\n
'
)
if
__name__
==
'__main__'
:
create_emitter_tests
(
sys
.
stdout
)
test/emittertests.cpp
View file @
0fb59c18
#include "tests.h"
#include "handlermacros.h"
#include "yaml-cpp/yaml.h"
#include "yaml-cpp/eventhandler.h"
#include <iostream>
...
...
@@ -1051,7 +1052,37 @@ namespace Test
}
total
++
;
}
void
RunGenEmitterTest
(
TEST
(
*
test
)(
YAML
::
Emitter
&
),
const
std
::
string
&
name
,
int
&
passed
,
int
&
total
)
{
YAML
::
Emitter
out
;
TEST
ret
;
try
{
ret
=
test
(
out
);
}
catch
(
const
YAML
::
Exception
&
e
)
{
ret
.
ok
=
false
;
ret
.
error
=
std
::
string
(
" Exception caught: "
)
+
e
.
what
();
}
if
(
!
out
.
good
())
{
ret
.
ok
=
false
;
ret
.
error
=
out
.
GetLastError
();
}
if
(
!
ret
.
ok
)
{
std
::
cout
<<
"Generated emitter test failed: "
<<
name
<<
"
\n
"
;
std
::
cout
<<
"Output:
\n
"
;
std
::
cout
<<
out
.
c_str
()
<<
"<<<
\n
"
;
std
::
cout
<<
ret
.
error
<<
"
\n
"
;
}
if
(
ret
.
ok
)
passed
++
;
total
++
;
}
}
#include "genemittertests.h"
bool
RunEmitterTests
()
{
...
...
@@ -1142,6 +1173,8 @@ namespace Test
RunEmitterErrorTest
(
&
Emitter
::
InvalidAnchor
,
"invalid anchor"
,
passed
,
total
);
RunEmitterErrorTest
(
&
Emitter
::
InvalidAlias
,
"invalid alias"
,
passed
,
total
);
RunEmitterErrorTest
(
&
Emitter
::
BadLocalTag
,
"bad local tag"
,
passed
,
total
);
RunGenEmitterTests
(
passed
,
total
);
std
::
cout
<<
"Emitter tests: "
<<
passed
<<
"/"
<<
total
<<
" passed
\n
"
;
return
passed
==
total
;
...
...
test/handlermacros.h
View file @
0fb59c18
#include "teststruct.h"
#pragma once
#include "yaml-cpp/yaml.h"
...
...
@@ -5,8 +6,6 @@
#include <string>
#include <cassert>
#define YAML_ASSERT(cond) do { if(!(cond)) return " Assert failed: " #cond; } while(false)
namespace
Test
{
std
::
string
Quote
(
const
std
::
string
&
text
)
{
YAML
::
Emitter
out
;
...
...
test/spectests.h
View file @
0fb59c18
...
...
@@ -5,18 +5,9 @@
#pragma once
#endif
#include
<string>
#include
"teststruct.h"
namespace
Test
{
struct
TEST
{
TEST
()
:
ok
(
false
)
{}
TEST
(
bool
ok_
)
:
ok
(
ok_
)
{}
TEST
(
const
char
*
error_
)
:
ok
(
false
),
error
(
error_
)
{}
bool
ok
;
std
::
string
error
;
};
namespace
Spec
{
// 2.1
TEST
SeqScalars
();
...
...
test/teststruct.h
0 → 100644
View file @
0fb59c18
#pragma once
#include <string>
#define YAML_ASSERT(cond) do { if(!(cond)) return " Assert failed: " #cond; } while(false)
namespace
Test
{
struct
TEST
{
TEST
()
:
ok
(
false
)
{}
TEST
(
bool
ok_
)
:
ok
(
ok_
)
{}
TEST
(
const
char
*
error_
)
:
ok
(
false
),
error
(
error_
)
{}
bool
ok
;
std
::
string
error
;
};
}
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