Permalink
Browse files

Add check for e2big

  • Loading branch information...
1 parent c2d3522 commit 143e5045ddaf9728c46905fa927e4bbddee051ae @freddy77 freddy77 committed Feb 16, 2014
Showing with 49 additions and 0 deletions.
  1. +49 −0 src/tds/unittests/charconv.c
View
49 src/tds/unittests/charconv.c
@@ -252,6 +252,51 @@ test(TDSSOCKET *tds, enum Odd odd_type)
}
}
+static void
+big_test(TDSSOCKET *tds)
+{
+ int i, l;
+ const int limit = 1025;
+
+ captured_errno = 0;
+
+ printf("E2BIG test\n");
+
+ for (i = 0; i < 4096+20; ++i) {
+ size_t out_len;
+ TDSRET res;
+ int err;
+
+ if (i == 32)
+ i = 490;
+
+ l = i;
+ memset(buf, 0xa0, sizeof(buf));
+
+ /* convert it */
+ out_len = limit;
+ res = convert(tds, conv, to_client, buf, l, buf_out, &out_len);
+ printf("i %d res %d out_len %u errno %d captured_errno %d\n",
+ i, (int) res, (unsigned int) out_len, last_errno, captured_errno);
+ err = l * 2 > limit ? E2BIG : 0;
+
+ if (err) {
+ assert(last_errno == err);
+ assert(TDS_FAILED(res));
+ assert(!tds || captured_errno == last_errno);
+ } else {
+ assert(TDS_SUCCEED(res));
+ assert(captured_errno == 0);
+ }
+ if (out_len != i*2 && i*2 <= limit) {
+ fprintf(stderr, "out %u bytes expected %d\n",
+ (unsigned int) out_len, i*2);
+ exit(1);
+ }
+ }
+}
+
+
int
main(int argc, char **argv)
{
@@ -292,6 +337,10 @@ main(int argc, char **argv)
test(s, odd_type);
}
+ /* not try E2BIG error */
+ big_test(NULL);
+ big_test(tds);
+
tds_free_socket(tds);
tds_free_context(ctx);
return 0;

0 comments on commit 143e504

Please sign in to comment.