Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Gxml
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Canek Peláez Valdés
Gxml
Commits
b1007d94
Commit
b1007d94
authored
5 years ago
by
Daniel Espinosa
Browse files
Options
Downloads
Patches
Plain Diff
StreamReader: prepraration for serialization tests
parent
d88f2f5a
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
gxml/StreamReader.vala
+8
-2
8 additions, 2 deletions
gxml/StreamReader.vala
test/StreamReaderTest.vala
+161
-1
161 additions, 1 deletion
test/StreamReaderTest.vala
with
169 additions
and
3 deletions
gxml/StreamReader.vala
+
8
−
2
View file @
b1007d94
...
@@ -62,9 +62,16 @@ public class GXml.StreamReader : GLib.Object {
...
@@ -62,9 +62,16 @@ public class GXml.StreamReader : GLib.Object {
private
inline
uint8
cur_byte
()
{
private
inline
uint8
cur_byte
()
{
return
buf
[
0
];
return
buf
[
0
];
}
}
public
DomDocument
read
()
throws
GLib
.
Error
{
public
DomDocument
read
()
throws
GLib
.
Error
{
_document
=
new
Document
();
_document
=
new
Document
();
internal_read
();
return
document
;
}
public
void
read_document
(
DomDocument
doc
)
throws
GLib
.
Error
{
_document
=
doc
;
internal_read
();
}
private
void
internal_read
()
throws
GLib
.
Error
{
read_byte
();
read_byte
();
if
(
cur_char
()
!=
'<'
)
{
if
(
cur_char
()
!=
'<'
)
{
throw
new
StreamReaderError
.
INVALID_DOCUMENT_ERROR
(
_
(
"Invalid document: should start with '<'"
));
throw
new
StreamReaderError
.
INVALID_DOCUMENT_ERROR
(
_
(
"Invalid document: should start with '<'"
));
...
@@ -85,7 +92,6 @@ public class GXml.StreamReader : GLib.Object {
...
@@ -85,7 +92,6 @@ public class GXml.StreamReader : GLib.Object {
}
}
var
re
=
read_root_element
();
var
re
=
read_root_element
();
document
.
append_child
(
re
);
document
.
append_child
(
re
);
return
document
;
}
}
public
GXml
.
Element
read_root_element
()
throws
GLib
.
Error
{
public
GXml
.
Element
read_root_element
()
throws
GLib
.
Error
{
return
read_element
(
true
);
return
read_element
(
true
);
...
...
This diff is collapsed.
Click to expand it.
test/StreamReaderTest.vala
+
161
−
1
View file @
b1007d94
...
@@ -21,6 +21,115 @@
...
@@ -21,6 +21,115 @@
*/
*/
using
GXml
;
using
GXml
;
class
ContentNode
:
GXml
.
Element
{
string
_val
=
null
;
public
string
val
{
get
{
_val
=
text_content
;
return
_val
;
}
set
{
text_content
=
_val
;
}
}
}
class
Name
:
ContentNode
{
construct
{
try
{
initialize
(
"Name"
);
}
catch
(
GLib
.
Error
e
)
{
warning
(
"Error: %s"
,
e
.
message
);
}
}
}
class
Email
:
ContentNode
{
construct
{
try
{
initialize
(
"Email"
);
}
catch
(
GLib
.
Error
e
)
{
warning
(
"Error: %s"
,
e
.
message
);
}
}
}
class
Author
:
GXml
.
Element
{
public
Name
name
{
get
;
set
;
}
public
Email
email
{
get
;
set
;
}
construct
{
try
{
initialize
(
"Author"
);
}
catch
(
GLib
.
Error
e
)
{
warning
(
"Error: %s"
,
e
.
message
);
}
}
public
class
Collection
:
GXml
.
ArrayList
{
construct
{
try
{
initialize
(
typeof
(
Author
));
}
catch
(
GLib
.
Error
e
)
{
warning
(
"Error: %s"
,
e
.
message
);
}
}
}
}
class
Authors
:
GXml
.
Element
{
public
Author
.
Collection
authors
{
get
;
set
;
}
construct
{
try
{
initialize
(
"Authors"
);
set_instance_property
(
"authors"
);
}
catch
(
GLib
.
Error
e
)
{
warning
(
"Error: %s"
,
e
.
message
);
}
}
}
class
Book
:
GXml
.
Element
{
[
Description
(
nick
=
"::year"
)]
public
int
year
{
get
;
set
;
}
[
Description
(
nick
=
"::ISBN"
)]
public
string
ISBN
{
get
;
set
;
}
construct
{
try
{
initialize
(
"Book"
);
}
catch
(
GLib
.
Error
e
)
{
warning
(
"Error: %s"
,
e
.
message
);
}
}
public
class
Collection
:
GXml
.
ArrayList
{
construct
{
try
{
initialize
(
typeof
(
Book
));
}
catch
(
GLib
.
Error
e
)
{
warning
(
"Error: %s"
,
e
.
message
);
}
}
}
}
class
BookStore
:
GXml
.
Element
{
public
Book
.
Collection
books
{
get
;
set
;
}
construct
{
try
{
initialize
(
"BookStore"
);
set_instance_property
(
"books"
);
}
catch
(
GLib
.
Error
e
)
{
warning
(
"Error: %s"
,
e
.
message
);
}
}
}
class
Library
:
GXml
.
Document
{
[
Description
(
nick
=
"::ROOT"
)]
public
BookStore
store
{
get
;
set
;
}
public
void
read
(
string
str
)
throws
GLib
.
Error
{
var
istream
=
new
MemoryInputStream
.
from_data
(
str
.
data
,
null
);
var
sr
=
new
StreamReader
(
istream
);
sr
.
read_document
(
this
);
}
}
class
GXmlTest
{
class
GXmlTest
{
public
static
int
main
(
string
[]
args
)
{
public
static
int
main
(
string
[]
args
)
{
Test
.
init
(
ref
args
);
Test
.
init
(
ref
args
);
...
@@ -106,7 +215,58 @@ class GXmlTest {
...
@@ -106,7 +215,58 @@ class GXmlTest {
(
doc
.
document_element
as
GXml
.
Element
).
parse_buffer
.
end
(
res
);
(
doc
.
document_element
as
GXml
.
Element
).
parse_buffer
.
end
(
res
);
message
(
doc
.
write_string
());
message
(
doc
.
write_string
());
assert
((
doc
.
document_element
as
GXml
.
Element
).
read_buffer
==
null
);
assert
((
doc
.
document_element
as
GXml
.
Element
).
read_buffer
==
null
);
//assert ((doc.document_element.child_nodes.item (0) as GXml.Element).read_buffer == null);
loop
.
quit
();
}
catch
(
GLib
.
Error
e
)
{
warning
(
"Error: %s"
,
e
.
message
);
}
});
}
catch
(
GLib
.
Error
e
)
{
warning
(
"Error while reading stream: %s"
,
e
.
message
);
}
return
Source
.
REMOVE
;
});
loop
.
run
();
});
Test
.
add_func
(
"/gxml/stream-reader/serialization"
,
()
=>
{
var
loop
=
new
GLib
.
MainLoop
(
null
);
Idle
.
add
(()=>{
string
str
=
"""<?xml version="
1.0
"?>
<
BookStore
>
<
book
year
=
"2014"
isbn
=
"ISBN83763550019---11"
>
<
Authors
>
<
Author
>
<
Name
>
Fred
</
Name
>
<
Email
>
fweasley@hogwarts
.
co
.
uk
</
Email
>
</
Author
>
<
Author
>
<
Name
>
George
</
Name
>
<
Email
>
gweasley@hogwarts
.
co
.
uk
</
Email
>
</
Author
>
</
Authors
>
<
name
>
Book1
</
name
>
</
book
>
<
book
year
=
"2014"
isbn
=
"ISBN83763550019---11"
>
<
Authors
>
<
Author
>
<
Name
>
Fred
</
Name
>
<
Email
>
fweasley@hogwarts
.
co
.
uk
</
Email
>
</
Author
>
<
Author
>
<
Name
>
George
</
Name
>
<
Email
>
gweasley@hogwarts
.
co
.
uk
</
Email
>
</
Author
>
</
Authors
>
<
name
>
Book1
</
name
>
</
book
>
</
BookStore
>
""";
var
doc
=
new
Library
();
try
{
doc
.
read
(
str
);
(
doc
.
document_element
as
GXml
.
Element
).
parse_buffer
.
begin
((
obj
,
res
)=>{
try
{
(
doc
.
document_element
as
GXml
.
Element
).
parse_buffer
.
end
(
res
);
message
(
doc
.
write_string
());
assert
((
doc
.
document_element
as
GXml
.
Element
).
read_buffer
==
null
);
loop
.
quit
();
loop
.
quit
();
}
catch
(
GLib
.
Error
e
)
{
}
catch
(
GLib
.
Error
e
)
{
warning
(
"Error: %s"
,
e
.
message
);
warning
(
"Error: %s"
,
e
.
message
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment