aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrzysztof Kozlowski <krzysztof.kozlowski@canonical.com>2021-07-10 07:17:51 +0200
committerKrzysztof Kozlowski <krzysztof.kozlowski@canonical.com>2021-07-19 12:53:25 +0200
commitd159ccc0b8fcd8904888813e355bec603e121819 (patch)
tree5b252ad27e3b38a53490658657fd9d55de6e21e0
parentfee2d27b9fb3ad0e255b66ece50047f7219af3a7 (diff)
downloadneard-d159ccc0b8fcd8904888813e355bec603e121819.tar.gz
unit: use g_assert_cmpmem()
Comparisons of simple values should use test macros instead of checking standard library call return value. This prints more information on failure - the actual values used for comparisons. Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
-rw-r--r--unit/test-ndef-build.c6
-rw-r--r--unit/test-ndef-parse.c2
-rw-r--r--unit/test-snep-read.c9
3 files changed, 9 insertions, 8 deletions
diff --git a/unit/test-ndef-build.c b/unit/test-ndef-build.c
index bf77fdd..44dce4b 100644
--- a/unit/test-ndef-build.c
+++ b/unit/test-ndef-build.c
@@ -64,7 +64,7 @@ static void test_ndef_text_build(void)
g_assert(ndef);
g_assert_cmpuint(ndef->length, ==, ARRAY_SIZE(text));
- g_assert(!memcmp(ndef->data, text, ARRAY_SIZE(text)));
+ g_assert_cmpmem(ndef->data, ARRAY_SIZE(text), text, ARRAY_SIZE(text));
}
static void test_ndef_wsc_with_passphrase_build(void)
@@ -75,7 +75,7 @@ static void test_ndef_wsc_with_passphrase_build(void)
g_assert(ndef);
g_assert_cmpuint(ndef->length, ==, ARRAY_SIZE(wsc));
- g_assert(!memcmp(ndef->data, wsc, ARRAY_SIZE(wsc)));
+ g_assert_cmpmem(ndef->data, ARRAY_SIZE(wsc), wsc, ARRAY_SIZE(wsc));
}
static void test_ndef_wsc_with_out_passphrase_build(void)
@@ -86,7 +86,7 @@ static void test_ndef_wsc_with_out_passphrase_build(void)
g_assert(ndef);
g_assert_cmpuint(ndef->length, ==, ARRAY_SIZE(wsc_wo));
- g_assert(!memcmp(ndef->data, wsc_wo, ARRAY_SIZE(wsc_wo)));
+ g_assert_cmpmem(ndef->data, ARRAY_SIZE(wsc_wo), wsc_wo, ARRAY_SIZE(wsc_wo));
}
static void test_ndef_wsc_with_out_ssid_build(void)
diff --git a/unit/test-ndef-parse.c b/unit/test-ndef-parse.c
index a4f1ab3..96288f2 100644
--- a/unit/test-ndef-parse.c
+++ b/unit/test-ndef-parse.c
@@ -427,7 +427,7 @@ static void test_ndef_ho_hs_bt(void)
ac = ho->ac_payloads[0];
g_assert_cmpuint(ac->cdr_len, ==, 1);
- g_assert(memcmp(ac->cdr, "0", ac->cdr_len) == 0);
+ g_assert_cmpmem(ac->cdr, ac->cdr_len, "0", sizeof("0"));
records = g_list_next(records);
record = records->data;
diff --git a/unit/test-snep-read.c b/unit/test-snep-read.c
index 1871bac..5511fec 100644
--- a/unit/test-snep-read.c
+++ b/unit/test-snep-read.c
@@ -456,7 +456,8 @@ static void test_snep_read_verify_resp(int exp_resp_code,
g_assert_cmpuint(resp->version, ==, NEAR_SNEP_VERSION);
g_assert_cmpuint(resp->response, ==, exp_resp_code);
g_assert_cmpuint(resp->length, ==, GUINT_TO_BE(exp_resp_info_len));
- g_assert(!memcmp(resp->info, exp_resp_info, exp_resp_info_len));
+ g_assert_cmpmem(resp->info, GUINT_FROM_BE(resp->length),
+ exp_resp_info, exp_resp_info_len);
g_free(resp);
}
@@ -786,8 +787,8 @@ static void test_snep_read_get_req_frags_client_resp(gpointer context,
data_recvd + offset);
/* verify data */
- g_assert(!memcmp(data_recvd, ctx->req_info,
- ctx->req_info_len));
+ g_assert_cmpmem(data_recvd, ctx->req_info_len, ctx->req_info,
+ ctx->req_info_len);
}
g_free(data_recvd);
@@ -891,7 +892,7 @@ static void test_snep_response_put_get_ndef(gpointer context,
g_assert_cmpuint(resp->response, ==, NEAR_SNEP_RESP_SUCCESS);
g_assert_cmpint(resp->length, ==, GUINT_TO_BE(ndef->length));
g_assert_cmpuint(resp->length, ==, GUINT_TO_BE(ndef->length));
- g_assert(!memcmp(resp->info, text, ndef->length));
+ g_assert_cmpmem(resp->info, GUINT_FROM_BE(resp->length), text, ndef->length);
g_free(req);
g_free(resp);