Skip to content
Snippets Groups Projects
Commit 7cad6ed7 authored by Jonathan Schöbel's avatar Jonathan Schöbel
Browse files

Attr: added copy constructor

Sometimes a copy is useful.
parent b4f8e2e2
Branches
Tags
No related merge requests found
......@@ -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=1605;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=1826;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
......
......@@ -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@*/
......
......@@ -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@*/
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment