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
bf1bb1e7
Commit
bf1bb1e7
authored
2 years ago
by
Jonathan Schöbel
Browse files
Options
Downloads
Patches
Plain Diff
Attr: added getter & setter for value
parent
664374f2
No related branches found
No related tags found
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
+59
-0
59 additions, 0 deletions
src/lib/sefht/attr.c
src/lib/sefht/attr.h
+13
-0
13 additions, 0 deletions
src/lib/sefht/attr.h
tests/test_attr.c
+86
-0
86 additions, 0 deletions
tests/test_attr.c
with
161 additions
and
3 deletions
sefht.geany
+
3
−
3
View file @
bf1bb1e7
...
...
@@ -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=
4170
;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=22
46
;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=
5104
;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=22
79
;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=8
638
;C;0;EUTF-8;1;1;0;%2Fhome%2Fjonathan%2FDokumente%2Fprojekte%2Fprgm%2Finternet%2Fweb%2FSeFHT%2Ftests%2Ftest_attr.c;0;8
FILE_NAME_30=8
032
;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
+
59
−
0
View file @
bf1bb1e7
...
...
@@ -214,3 +214,62 @@ SH_Attr_set_name (struct SH_Attr * attr,
set_success
(
status
);
return
TRUE
;
}
/*@null@*/
/*@only@*/
char
*
SH_Attr_get_value
(
const
struct
SH_Attr
*
attr
,
/*@null@*/
/*@out@*/
struct
SH_Status
*
status
)
/*@*/
{
char
*
value
;
if
(
NULL
==
attr
->
value
)
{
set_success
(
status
);
return
NULL
;
}
value
=
strdup
(
attr
->
value
);
if
(
NULL
==
value
)
{
set_status
(
status
,
E_ALLOC
,
3
,
"strdup failed"
);
return
NULL
;
}
set_success
(
status
);
return
value
;
}
bool
SH_Attr_set_value
(
struct
SH_Attr
*
attr
,
const
char
*
value
,
/*@null@*/
/*@out@*/
struct
SH_Status
*
status
)
/*@modifies attr->value@*/
{
char
*
value_copy
;
if
(
NULL
==
value
)
{
value_copy
=
NULL
;
}
else
{
value_copy
=
strdup
(
value
);
if
(
NULL
==
value_copy
)
{
set_status
(
status
,
E_ALLOC
,
3
,
"strdup failed"
);
return
FALSE
;
}
}
if
(
NULL
!=
attr
->
value
)
{
free
(
attr
->
value
);
}
attr
->
value
=
value_copy
;
set_success
(
status
);
return
TRUE
;
}
This diff is collapsed.
Click to expand it.
src/lib/sefht/attr.h
+
13
−
0
View file @
bf1bb1e7
...
...
@@ -84,4 +84,17 @@ SH_Attr_set_name (SH_Attr * attr,
/*@null@*/
/*@out@*/
struct
SH_Status
*
status
)
/*@modifies attr@*/
;
/*@null@*/
/*@only@*/
char
*
SH_Attr_get_value
(
const
SH_Attr
*
attr
,
/*@null@*/
/*@out@*/
struct
SH_Status
*
status
)
/*@*/
;
bool
SH_Attr_set_value
(
SH_Attr
*
attr
,
const
char
*
value
,
/*@null@*/
/*@out@*/
struct
SH_Status
*
status
)
/*@modifies attr@*/
;
#endif
/* SEFHT_ATTR_H */
This diff is collapsed.
Click to expand it.
tests/test_attr.c
+
86
−
0
View file @
bf1bb1e7
...
...
@@ -327,6 +327,89 @@ START_TEST(test_attr_name_with_status)
}
END_TEST
START_TEST
(
test_attr_value_no_status
)
{
struct
SH_Attr
*
attr
;
const
char
*
name
=
"name"
;
const
char
*
value1
=
"value1"
;
const
char
*
value2
=
"value2"
;
char
*
value
;
bool
result
;
attr
=
SH_Attr_new
(
name
,
NULL
,
NULL
);
ck_assert_ptr_ne
(
NULL
,
attr
);
ck_assert_ptr_eq
(
NULL
,
attr
->
value
);
value
=
SH_Attr_get_value
(
attr
,
NULL
);
ck_assert_ptr_eq
(
NULL
,
value
);
result
=
SH_Attr_set_value
(
attr
,
value1
,
NULL
);
ck_assert_int_eq
(
TRUE
,
result
);
ck_assert_ptr_ne
(
value1
,
attr
->
value
);
ck_assert_str_eq
(
value1
,
attr
->
value
);
value
=
SH_Attr_get_value
(
attr
,
NULL
);
ck_assert_ptr_ne
(
NULL
,
value
);
ck_assert_ptr_ne
(
value1
,
value
);
ck_assert_str_eq
(
value1
,
value
);
free
(
value
);
result
=
SH_Attr_set_value
(
attr
,
value2
,
NULL
);
ck_assert_int_eq
(
TRUE
,
result
);
ck_assert_ptr_ne
(
value2
,
attr
->
value
);
ck_assert_str_eq
(
value2
,
attr
->
value
);
SH_Attr_free
(
attr
);
}
END_TEST
START_TEST
(
test_attr_value_with_status
)
{
struct
SH_Status
status
;
struct
SH_Attr
*
attr
;
const
char
*
name
=
"name"
;
const
char
*
value1
=
"value1"
;
const
char
*
value2
=
"value2"
;
char
*
value
;
bool
result
;
_status_preinit
(
status
);
attr
=
SH_Attr_new
(
name
,
NULL
,
&
status
);
ck_assert_ptr_ne
(
NULL
,
attr
);
ck_assert
(
succeed
(
&
status
));
ck_assert_ptr_eq
(
NULL
,
attr
->
value
);
_status_preinit
(
status
);
value
=
SH_Attr_get_value
(
attr
,
&
status
);
ck_assert_ptr_eq
(
NULL
,
value
);
ck_assert
(
succeed
(
&
status
));
_status_preinit
(
status
);
result
=
SH_Attr_set_value
(
attr
,
value1
,
&
status
);
ck_assert_int_eq
(
TRUE
,
result
);
ck_assert
(
succeed
(
&
status
));
ck_assert_ptr_ne
(
value1
,
attr
->
value
);
ck_assert_str_eq
(
value1
,
attr
->
value
);
_status_preinit
(
status
);
value
=
SH_Attr_get_value
(
attr
,
&
status
);
ck_assert_ptr_ne
(
NULL
,
value
);
ck_assert
(
succeed
(
&
status
));
ck_assert_ptr_ne
(
value1
,
value
);
ck_assert_str_eq
(
value1
,
value
);
free
(
value
);
_status_preinit
(
status
);
result
=
SH_Attr_set_value
(
attr
,
value2
,
&
status
);
ck_assert_int_eq
(
TRUE
,
result
);
ck_assert
(
succeed
(
&
status
));
ck_assert_ptr_ne
(
value2
,
attr
->
value
);
ck_assert_str_eq
(
value2
,
attr
->
value
);
SH_Attr_free
(
attr
);
}
END_TEST
Suite
*
test_suite
(
void
)
{
Suite
*
s
;
...
...
@@ -355,6 +438,9 @@ Suite * test_suite (void)
tcase_add_test
(
tc_core
,
test_attr_name_no_status
);
tcase_add_test
(
tc_core
,
test_attr_name_with_status
);
tcase_add_test
(
tc_core
,
test_attr_value_no_status
);
tcase_add_test
(
tc_core
,
test_attr_value_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