Commit Diff


commit - 34fca9c35c1a35f6e163edd53f5cf674b30c1799
commit + 89817b3089203b9005104fffb281f901fc147099
blob - 83ea51ae92d4b1a3559fb427fa0a9c5f519c27be
blob + 4376f1b7a87bae66bf181b0a5134e50a53b24b93
--- include/got_error.h
+++ include/got_error.h
@@ -61,6 +61,7 @@
 #define GOT_ERR_ITER_NEED_MORE	45
 #define GOT_ERR_ITER_COMPLETED	46
 #define GOT_ERR_RANGE		47
+#define GOT_ERR_EXPECTED	48 /* for use in regress tests only */
 
 static const struct got_error {
 	int code;
@@ -110,6 +111,7 @@ static const struct got_error {
 	{ GOT_ERR_ITER_NEED_MORE,"more items needed to continue iteration" },
 	{ GOT_ERR_ITER_COMPLETED,"iteration completed" },
 	{ GOT_ERR_RANGE,	"value out of range" },
+	{ GOT_ERR_EXPECTED,	"expected an error but have no error" },
 };
 
 /*
blob - 09019b9d9453700ff31458a560af1359b4e9f602
blob + 21e8c3d4a8dd6740cca89ecfa31b00392281e939
--- regress/delta/delta_test.c
+++ regress/delta/delta_test.c
@@ -34,16 +34,21 @@
 
 struct delta_test {
 	const char *base;
+	size_t base_len;
 	const char *delta;
 	size_t delta_len;
 	const char *expected;
+	size_t result_len;
 } delta_tests[] = {
 	/* base len 0, target len 4, append 4 'x' */
-	{ "", "\x00\x04\x04xxxx", 7, "xxxx" },
+	{ "", 0, "\x00\x04\x04xxxx", 7, "xxxx", 4 },
 	/* copy 4 bytes at offset 0 from base, append 4 'x' */
-	{ "aabbccdd", "\x08\x08\x90\x04\x04xxxx", 9, "aabbxxxx" },
+	{ "aabbccdd", 8, "\x08\x08\x90\x04\x04xxxx", 9, "aabbxxxx", 8 },
 	/* copy 4 bytes at offset 4 from base, append 4 'x' */
-	{ "aabbccdd", "\x08\x08\x91\x04\x04\x04xxxx", 10, "ccddxxxx" },
+	{ "aabbccdd", 8, "\x08\x08\x91\x04\x04\x04xxxx", 10, "ccddxxxx", 8 },
+	/* git 48fb7deb5 Fix big left-shifts of unsigned char, 2009-06-17) */
+	{ "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
+	  16, "\x10\x10\xff\xff\xff\xff\xff\x10\00\00", 10 , NULL, 0 }
 };
 
 static int
@@ -61,37 +66,46 @@ delta_apply(void)
 		struct delta_test *dt = &delta_tests[i];
 		FILE *base_file;
 		char buf[1024];
-		size_t n, len, result_len;
+		size_t n, result_len;
 
-		len = strlen(dt->base);
 		base_file = got_opentemp();
 		if (base_file == NULL) {
 			err = got_error_from_errno();
 			break;
 		}
 
-		n = fwrite(dt->base, 1, len, base_file);
-		if (n != len) {
+		n = fwrite(dt->base, 1, dt->base_len, base_file);
+		if (n != dt->base_len) {
 			err = got_ferror(base_file, GOT_ERR_IO);
 			break;
 		}
 		rewind(base_file);
 
 		err = got_delta_apply(base_file, dt->delta, dt->delta_len,
-		    result_file, &len);
+		    result_file, &result_len);
 		fclose(base_file);
-		if (err)
-			break;
-		result_len = strlen(dt->expected);
-		if (result_len != len) {
-			err = got_ferror(result_file, GOT_ERR_BAD_DELTA);
-			break;
+		if (dt->expected == NULL) {
+			/* Invalid delta, expect an error. */
+			if (err == NULL)
+				err = got_error(GOT_ERR_EXPECTED);
+			else if (err->code == GOT_ERR_BAD_DELTA)
+				err = NULL;
+		} else {
+			if (err)
+				break;
+			if (result_len != dt->result_len) {
+				err = got_ferror(result_file,
+				    GOT_ERR_BAD_DELTA);
+				break;
+			}
+			n = fread(buf, result_len, 1, result_file);
+			if (n != 1 ||
+			    strncmp(buf, dt->expected, result_len) != 0) {
+				err = got_ferror(result_file,
+				    GOT_ERR_BAD_DELTA);
+				break;
+			}
 		}
-		n = fread(buf, result_len, 1, result_file);
-		if (n != 1 || strncmp(buf, dt->expected, result_len) != 0) {
-			err = got_ferror(result_file, GOT_ERR_BAD_DELTA);
-			break;
-		}
 		rewind(result_file);
 	}