summaryrefslogtreecommitdiff
path: root/gck
diff options
context:
space:
mode:
authorGregor Riepl <onitake@gmail.com>2019-11-26 22:44:22 +0100
committerGregor Riepl <onitake@gmail.com>2019-11-26 22:44:22 +0100
commit2016d750ff23f160d8292c9e4e4fb0e133b3bf60 (patch)
treeb440a3b0f501d41524b2967337fffb60d6d84e99 /gck
parentb5b9ba30a5bf2699ff7fe574c3a1e8b79e1586ae (diff)
downloadgcr-2016d750ff23f160d8292c9e4e4fb0e133b3bf60.tar.gz
Replace pointer aliasing in unit test
Diffstat (limited to 'gck')
-rw-r--r--gck/test-gck-attributes.c36
1 files changed, 26 insertions, 10 deletions
diff --git a/gck/test-gck-attributes.c b/gck/test-gck-attributes.c
index c216ad1..2e9d7ce 100644
--- a/gck/test-gck-attributes.c
+++ b/gck/test-gck-attributes.c
@@ -55,11 +55,13 @@ static void
test_init_boolean (void)
{
GckAttribute attr;
+ CK_BBOOL ck_value = CK_FALSE;
gck_attribute_init_boolean (&attr, ATTR_TYPE, TRUE);
g_assert (attr.type == ATTR_TYPE);
g_assert (attr.length == sizeof (CK_BBOOL));
- g_assert (*((CK_BBOOL*)attr.value) == CK_TRUE);
+ memcpy(&ck_value, attr.value, sizeof (CK_BBOOL));
+ g_assert (ck_value == CK_TRUE);
gck_attribute_clear (&attr);
}
@@ -88,11 +90,13 @@ static void
test_init_ulong (void)
{
GckAttribute attr;
+ CK_ULONG ck_value = 0;
gck_attribute_init_ulong (&attr, ATTR_TYPE, 88);
g_assert (attr.type == ATTR_TYPE);
g_assert (attr.length == sizeof (CK_ULONG));
- g_assert (*((CK_ULONG*)attr.value) == 88);
+ memcpy(&ck_value, attr.value, sizeof (CK_ULONG));
+ g_assert (ck_value == 88);
gck_attribute_clear (&attr);
}
@@ -154,11 +158,13 @@ static void
test_new_boolean (void)
{
GckAttribute *attr;
+ CK_BBOOL ck_value = CK_FALSE;
attr = gck_attribute_new_boolean (ATTR_TYPE, TRUE);
g_assert (attr->type == ATTR_TYPE);
g_assert (attr->length == sizeof (CK_BBOOL));
- g_assert (*((CK_BBOOL*)attr->value) == CK_TRUE);
+ memcpy(&ck_value, attr->value, sizeof (CK_BBOOL));
+ g_assert (ck_value == CK_TRUE);
gck_attribute_free (attr);
}
@@ -187,11 +193,13 @@ static void
test_new_ulong (void)
{
GckAttribute *attr;
+ CK_ULONG ck_value = 0;
attr = gck_attribute_new_ulong (ATTR_TYPE, 88);
g_assert (attr->type == ATTR_TYPE);
g_assert (attr->length == sizeof (CK_ULONG));
- g_assert (*((CK_ULONG*)attr->value) == 88);
+ memcpy(&ck_value, attr->value, sizeof (CK_ULONG));
+ g_assert (ck_value == 88);
gck_attribute_free (attr);
}
@@ -536,6 +544,7 @@ test_build_boolean (void)
GckAttributes *attrs;
const GckAttribute *attr;
gboolean value;
+ CK_BBOOL ck_value = CK_FALSE;
g_assert (gck_builder_find_boolean (&builder, 5, &value) == FALSE);
@@ -549,7 +558,8 @@ test_build_boolean (void)
g_assert (attr != NULL);
g_assert (attr->type == ATTR_TYPE);
g_assert (attr->length == sizeof (CK_BBOOL));
- g_assert (*((CK_BBOOL*)attr->value) == CK_FALSE);
+ memcpy(&ck_value, attr->value, sizeof (CK_BBOOL));
+ g_assert (ck_value == CK_FALSE);
if (!gck_builder_find_boolean (&builder, ATTR_TYPE, &value))
g_assert_not_reached ();
g_assert (value == FALSE);
@@ -557,7 +567,8 @@ test_build_boolean (void)
gck_builder_set_boolean (&builder, ATTR_TYPE, TRUE);
g_assert (attr->type == ATTR_TYPE);
g_assert (attr->length == sizeof (CK_BBOOL));
- g_assert (*((CK_BBOOL*)attr->value) == CK_TRUE);
+ memcpy(&ck_value, attr->value, sizeof (CK_BBOOL));
+ g_assert (ck_value == CK_TRUE);
if (!gck_builder_find_boolean (&builder, ATTR_TYPE, &value))
g_assert_not_reached ();
g_assert (value == TRUE);
@@ -572,7 +583,8 @@ test_build_boolean (void)
g_assert (attr->type == ATTR_TYPE);
g_assert (attr->length == sizeof (CK_BBOOL));
- g_assert (*((CK_BBOOL*)attr->value) == CK_TRUE);
+ memcpy(&ck_value, attr->value, sizeof (CK_BBOOL));
+ g_assert (ck_value == CK_TRUE);
if (!gck_attributes_find_boolean (attrs, ATTR_TYPE, &value))
g_assert_not_reached ();
@@ -662,6 +674,7 @@ test_build_ulong (void)
GckAttributes *attrs;
const GckAttribute *attr;
gulong value;
+ CK_ULONG ck_value = 0;
g_assert (gck_builder_find_ulong (&builder, 5, &value) == FALSE);
@@ -675,7 +688,8 @@ test_build_ulong (void)
g_assert (attr != NULL);
g_assert (attr->type == ATTR_TYPE);
g_assert (attr->length == sizeof (CK_ULONG));
- g_assert (*((CK_ULONG*)attr->value) == 99);
+ memcpy(&ck_value, attr->value, sizeof (CK_ULONG));
+ g_assert (ck_value == 99);
if (!gck_builder_find_ulong (&builder, ATTR_TYPE, &value))
g_assert_not_reached ();
g_assert (value == 99);
@@ -683,7 +697,8 @@ test_build_ulong (void)
gck_builder_set_ulong (&builder, ATTR_TYPE, 88);
g_assert (attr->type == ATTR_TYPE);
g_assert (attr->length == sizeof (CK_ULONG));
- g_assert (*((CK_ULONG*)attr->value) == 88);
+ memcpy(&ck_value, attr->value, sizeof (CK_ULONG));
+ g_assert (ck_value == 88);
if (!gck_builder_find_ulong (&builder, ATTR_TYPE, &value))
g_assert_not_reached ();
g_assert (value == 88);
@@ -697,7 +712,8 @@ test_build_ulong (void)
g_assert (attr != NULL);
g_assert (attr->type == ATTR_TYPE);
g_assert (attr->length == sizeof (CK_ULONG));
- g_assert (*((CK_ULONG*)attr->value) == 88);
+ memcpy(&ck_value, attr->value, sizeof (CK_ULONG));
+ g_assert (ck_value == 88);
if (!gck_attributes_find_ulong (attrs, ATTR_TYPE, &value))
g_assert_not_reached ();