[PATCH v3 02/11] t: harmonize t-reftable-block.c with coding guidelines

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Harmonize the newly ported test unit-tests/t-reftable-block.c
with the following guidelines:
- Single line 'for' statements must omit curly braces.
- Structs must be 0-initialized with '= { 0 }' instead of '= { NULL }'.
- Array sizes and indices should preferably be of type 'size_t'and
  not 'int'.
- Return code variable should preferably be named 'ret', not 'n'.

Mentored-by: Patrick Steinhardt <ps@xxxxxx>
Mentored-by: Christian Couder <chriscool@xxxxxxxxxxxxx>
Signed-off-by: Chandra Pratap <chandrapratap3519@xxxxxxxxx>
---
 t/unit-tests/t-reftable-block.c | 52 ++++++++++++++++-----------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/t/unit-tests/t-reftable-block.c b/t/unit-tests/t-reftable-block.c
index f2b9a8a6f4..b1b238ac2a 100644
--- a/t/unit-tests/t-reftable-block.c
+++ b/t/unit-tests/t-reftable-block.c
@@ -16,20 +16,20 @@ static void t_block_read_write(void)
 {
 	const int header_off = 21; /* random */
 	char *names[30];
-	const int N = ARRAY_SIZE(names);
-	const int block_size = 1024;
-	struct reftable_block block = { NULL };
+	const size_t N = ARRAY_SIZE(names);
+	const size_t block_size = 1024;
+	struct reftable_block block = { 0 };
 	struct block_writer bw = {
 		.last_key = STRBUF_INIT,
 	};
 	struct reftable_record rec = {
 		.type = BLOCK_TYPE_REF,
 	};
-	int i = 0;
-	int n;
+	size_t i = 0;
+	int ret;
 	struct block_reader br = { 0 };
 	struct block_iter it = BLOCK_ITER_INIT;
-	int j = 0;
+	size_t j = 0;
 	struct strbuf want = STRBUF_INIT;
 
 	REFTABLE_CALLOC_ARRAY(block.data, block_size);
@@ -40,26 +40,26 @@ static void t_block_read_write(void)
 
 	rec.u.ref.refname = (char *) "";
 	rec.u.ref.value_type = REFTABLE_REF_DELETION;
-	n = block_writer_add(&bw, &rec);
-	check_int(n, ==, REFTABLE_API_ERROR);
+	ret = block_writer_add(&bw, &rec);
+	check_int(ret, ==, REFTABLE_API_ERROR);
 
 	for (i = 0; i < N; i++) {
 		char name[100];
-		snprintf(name, sizeof(name), "branch%02d", i);
+		snprintf(name, sizeof(name), "branch%02"PRIuMAX, (uintmax_t)i);
 
 		rec.u.ref.refname = name;
 		rec.u.ref.value_type = REFTABLE_REF_VAL1;
 		memset(rec.u.ref.value.val1, i, GIT_SHA1_RAWSZ);
 
 		names[i] = xstrdup(name);
-		n = block_writer_add(&bw, &rec);
+		ret = block_writer_add(&bw, &rec);
 		rec.u.ref.refname = NULL;
 		rec.u.ref.value_type = REFTABLE_REF_DELETION;
-		check_int(n, ==, 0);
+		check_int(ret, ==, 0);
 	}
 
-	n = block_writer_finish(&bw);
-	check_int(n, >, 0);
+	ret = block_writer_finish(&bw);
+	check_int(ret, >, 0);
 
 	block_writer_release(&bw);
 
@@ -68,9 +68,10 @@ static void t_block_read_write(void)
 	block_iter_seek_start(&it, &br);
 
 	while (1) {
-		int r = block_iter_next(&it, &rec);
-		check_int(r, >=, 0);
-		if (r > 0) {
+		ret = block_iter_next(&it, &rec);
+		check_int(ret, >=, 0);
+		if (ret > 0) {
+			check_int(i, ==, N);
 			break;
 		}
 		check_str(names[j], rec.u.ref.refname);
@@ -85,20 +86,20 @@ static void t_block_read_write(void)
 		strbuf_reset(&want);
 		strbuf_addstr(&want, names[i]);
 
-		n = block_iter_seek_key(&it, &br, &want);
-		check_int(n, ==, 0);
+		ret = block_iter_seek_key(&it, &br, &want);
+		check_int(ret, ==, 0);
 
-		n = block_iter_next(&it, &rec);
-		check_int(n, ==, 0);
+		ret = block_iter_next(&it, &rec);
+		check_int(ret, ==, 0);
 
 		check_str(names[i], rec.u.ref.refname);
 
 		want.len--;
-		n = block_iter_seek_key(&it, &br, &want);
-		check_int(n, ==, 0);
+		ret = block_iter_seek_key(&it, &br, &want);
+		check_int(ret, ==, 0);
 
-		n = block_iter_next(&it, &rec);
-		check_int(n, ==, 0);
+		ret = block_iter_next(&it, &rec);
+		check_int(ret, ==, 0);
 		check_str(names[10 * (i / 10)], rec.u.ref.refname);
 
 		block_iter_close(&it);
@@ -107,9 +108,8 @@ static void t_block_read_write(void)
 	reftable_record_release(&rec);
 	reftable_block_done(&br.block);
 	strbuf_release(&want);
-	for (i = 0; i < N; i++) {
+	for (i = 0; i < N; i++)
 		reftable_free(names[i]);
-	}
 }
 
 int cmd_main(int argc, const char *argv[])
-- 
2.45.GIT





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux