Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SeFHT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
josc941e
SeFHT
Commits
7cad6ed7
Commit
7cad6ed7
authored
2 years ago
by
Jonathan Schöbel
Browse files
Options
Downloads
Patches
Plain Diff
Attr: added copy constructor
Sometimes a copy is useful.
parent
b4f8e2e2
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
sefht.geany
+3
-3
3 additions, 3 deletions
sefht.geany
src/lib/sefht/attr.c
+47
-0
47 additions, 0 deletions
src/lib/sefht/attr.c
src/lib/sefht/attr.h
+9
-0
9 additions, 0 deletions
src/lib/sefht/attr.h
tests/test_attr.c
+91
-0
91 additions, 0 deletions
tests/test_attr.c
with
150 additions
and
3 deletions
sefht.geany
+
3
−
3
View file @
7cad6ed7
...
...
@@ -43,8 +43,8 @@ FILE_NAME_10=2022;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fp
FILE_NAME_11=2558;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ffragment_class.c;0;8
FILE_NAME_12=2167;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.c;0;8
FILE_NAME_13=5930;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fnode_fragment.h;0;8
FILE_NAME_14=
1840
;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.c;0;8
FILE_NAME_15=1
605
;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.h;0;8
FILE_NAME_14=
2359
;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.c;0;8
FILE_NAME_15=1
826
;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fattr.h;0;8
FILE_NAME_16=25820;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext.c;0;8
FILE_NAME_17=904;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Ftext.h;0;8
FILE_NAME_18=1779;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Fsrc%2Flib%2Fsefht%2Fvalidator.c;0;8
...
...
@@ -59,7 +59,7 @@ FILE_NAME_26=533;Make;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2
FILE_NAME_27=1085;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_cms.c;0;8
FILE_NAME_28=3283;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_data.c;0;8
FILE_NAME_29=8770;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_node_fragment.c;0;8
FILE_NAME_30=
4431
;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_attr.c;0;8
FILE_NAME_30=
6640
;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_attr.c;0;8
FILE_NAME_31=11068;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_text.c;0;8
FILE_NAME_32=5744;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_validator.c;0;8
FILE_NAME_33=165;None;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftodo.txt;0;8
...
...
This diff is collapsed.
Click to expand it.
src/lib/sefht/attr.c
+
47
−
0
View file @
7cad6ed7
...
...
@@ -112,6 +112,53 @@ SH_Attr_raw_new (/*@only@*/ char * name,
return
attr
;
}
/*@null@*/
/*@only@*/
struct
SH_Attr
*
SH_Attr_copy
(
const
struct
SH_Attr
*
attr
,
/*@null@*/
/*@out@*/
struct
SH_Status
*
status
)
/*@globals fileSystem@*/
/*@modifies fileSystem@*/
/*@modifies status@*/
{
struct
SH_Attr
*
copy
;
copy
=
malloc
(
sizeof
(
struct
SH_Attr
));
if
(
copy
==
NULL
)
{
set_status
(
status
,
E_ALLOC
,
4
,
"malloc failed"
);
return
NULL
;
}
copy
->
name
=
strdup
(
attr
->
name
);
if
(
NULL
==
copy
->
name
)
{
set_status
(
status
,
E_ALLOC
,
2
,
"strdup failed"
);
free
(
copy
);
return
NULL
;
}
if
(
NULL
==
attr
->
value
)
{
copy
->
value
=
NULL
;
}
else
{
copy
->
value
=
strdup
(
attr
->
value
);
if
(
NULL
==
copy
->
value
)
{
set_status
(
status
,
E_ALLOC
,
2
,
"strdup failed"
);
free
(
copy
->
name
);
free
(
copy
);
return
NULL
;
}
}
set_success
(
status
);
return
copy
;
}
void
SH_Attr_free
(
/*@only@*/
struct
SH_Attr
*
attr
)
/*@modifies attr->name@*/
...
...
This diff is collapsed.
Click to expand it.
src/lib/sefht/attr.h
+
9
−
0
View file @
7cad6ed7
...
...
@@ -57,6 +57,15 @@ SH_Attr_raw_new (/*@only@*/ char * name,
/*@modifies fileSystem@*/
/*@modifies status@*/
;
/*@null@*/
/*@only@*/
struct
SH_Attr
*
SH_Attr_copy
(
const
struct
SH_Attr
*
attr
,
/*@null@*/
/*@out@*/
struct
SH_Status
*
status
)
/*@globals fileSystem@*/
/*@modifies fileSystem@*/
/*@modifies status@*/
;
void
SH_Attr_free
(
/*@only@*/
SH_Attr
*
attr
)
/*@modifies attr@*/
...
...
This diff is collapsed.
Click to expand it.
tests/test_attr.c
+
91
−
0
View file @
7cad6ed7
...
...
@@ -164,6 +164,92 @@ START_TEST(test_attr_raw2_with_status)
}
END_TEST
START_TEST
(
test_attr_copy1_no_status
)
{
struct
SH_Attr
*
attr
;
struct
SH_Attr
*
copy
;
const
char
*
name
=
"name"
;
attr
=
SH_Attr_new
(
name
,
NULL
,
NULL
);
copy
=
SH_Attr_copy
(
attr
,
NULL
);
ck_assert_ptr_ne
(
NULL
,
copy
);
ck_assert_ptr_ne
(
attr
->
name
,
copy
->
name
);
ck_assert_str_eq
(
attr
->
name
,
copy
->
name
);
ck_assert_ptr_eq
(
NULL
,
copy
->
value
);
SH_Attr_free
(
attr
);
SH_Attr_free
(
copy
);
}
END_TEST
START_TEST
(
test_attr_copy1_with_status
)
{
struct
SH_Status
status
;
struct
SH_Attr
*
attr
;
struct
SH_Attr
*
copy
;
const
char
*
name
=
"name"
;
attr
=
SH_Attr_new
(
name
,
NULL
,
NULL
);
_status_preinit
(
status
);
copy
=
SH_Attr_copy
(
attr
,
&
status
);
ck_assert_ptr_ne
(
NULL
,
copy
);
ck_assert
(
succeed
(
&
status
));
ck_assert_ptr_ne
(
attr
->
name
,
copy
->
name
);
ck_assert_str_eq
(
attr
->
name
,
copy
->
name
);
ck_assert_ptr_eq
(
NULL
,
copy
->
value
);
SH_Attr_free
(
attr
);
SH_Attr_free
(
copy
);
}
END_TEST
START_TEST
(
test_attr_copy2_no_status
)
{
struct
SH_Attr
*
attr
;
struct
SH_Attr
*
copy
;
const
char
*
name
=
"name"
;
const
char
*
value
=
"value"
;
attr
=
SH_Attr_new
(
name
,
value
,
NULL
);
copy
=
SH_Attr_copy
(
attr
,
NULL
);
ck_assert_ptr_ne
(
NULL
,
copy
);
ck_assert_ptr_ne
(
attr
->
name
,
copy
->
name
);
ck_assert_str_eq
(
attr
->
name
,
copy
->
name
);
ck_assert_ptr_ne
(
attr
->
value
,
copy
->
value
);
ck_assert_str_eq
(
attr
->
value
,
copy
->
value
);
SH_Attr_free
(
attr
);
SH_Attr_free
(
copy
);
}
END_TEST
START_TEST
(
test_attr_copy2_with_status
)
{
struct
SH_Status
status
;
struct
SH_Attr
*
attr
;
struct
SH_Attr
*
copy
;
const
char
*
name
=
"name"
;
const
char
*
value
=
"value"
;
attr
=
SH_Attr_new
(
name
,
value
,
NULL
);
_status_preinit
(
status
);
copy
=
SH_Attr_copy
(
attr
,
&
status
);
ck_assert_ptr_ne
(
NULL
,
copy
);
ck_assert
(
succeed
(
&
status
));
ck_assert_ptr_ne
(
attr
->
name
,
copy
->
name
);
ck_assert_str_eq
(
attr
->
name
,
copy
->
name
);
ck_assert_ptr_ne
(
attr
->
value
,
copy
->
value
);
ck_assert_str_eq
(
attr
->
value
,
copy
->
value
);
SH_Attr_free
(
attr
);
SH_Attr_free
(
copy
);
}
END_TEST
Suite
*
test_suite
(
void
)
{
Suite
*
s
;
...
...
@@ -183,6 +269,11 @@ Suite * test_suite (void)
tcase_add_test
(
tc_core
,
test_attr_raw1_with_status
);
tcase_add_test
(
tc_core
,
test_attr_raw2_no_status
);
tcase_add_test
(
tc_core
,
test_attr_raw2_with_status
);
tcase_add_test
(
tc_core
,
test_attr_copy1_no_status
);
tcase_add_test
(
tc_core
,
test_attr_copy1_with_status
);
tcase_add_test
(
tc_core
,
test_attr_copy2_no_status
);
tcase_add_test
(
tc_core
,
test_attr_copy2_with_status
);
suite_add_tcase
(
s
,
tc_core
);
return
s
;
...
...
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