]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Merge remote-tracking branch 'twstrike/util_format_tests'
authorNick Mathewson <nickm@torproject.org>
Tue, 6 Oct 2015 15:20:33 +0000 (11:20 -0400)
committerNick Mathewson <nickm@torproject.org>
Tue, 6 Oct 2015 15:20:33 +0000 (11:20 -0400)
Conflicts:
src/test/test_util_format.c

1  2 
src/test/test_util_format.c

index af4997de979218effcdeb17b322c5db0c0ddfd88,7be67438f556d7222619ab1d054e1cfc56464a86..705dfcf60554b6f925dd29704403679ac40444a2
@@@ -127,16 -137,10 +130,20 @@@ test_util_format_base64_decode_nopad(vo
    res = base64_decode_nopad(dst, 1, src, 5);
    tt_int_op(res, OP_EQ, -1);
  
 +  const char *s = "SGVsbG8gd29ybGQ";
 +  res = base64_decode_nopad(dst, 1000, s, strlen(s));
 +  tt_int_op(res, OP_EQ, 11);
 +  tt_mem_op(dst, OP_EQ, "Hello world", 11);
 +
 +  s = "T3BhIG11bmRv";
 +  res = base64_decode_nopad(dst, 9, s, strlen(s));
 +  tt_int_op(res, OP_EQ, 9);
 +  tt_mem_op(dst, OP_EQ, "Opa mundo", 9);
 +
+   res = base64_decode_nopad(real_dst, 10, real_src, 10);
+   tt_int_op(res, OP_EQ, 7);
+   tt_mem_op(real_dst, OP_EQ, expected, 7);
   done:
    tor_free(src);
    tor_free(dst);
@@@ -164,21 -172,10 +175,25 @@@ test_util_format_base64_decode(void *ig
    res = base64_decode(dst, SIZE_T_CEILING+1, src, 10);
    tt_int_op(res, OP_EQ, -1);
  
 +  const char *s = "T3BhIG11bmRv";
 +  res = base64_decode(dst, 9, s, strlen(s));
 +  tt_int_op(res, OP_EQ, 9);
 +  tt_mem_op(dst, OP_EQ, "Opa mundo", 9);
 +
 +  memset(dst, 0, 1000);
 +  res = base64_decode(dst, 100, s, strlen(s));
 +  tt_int_op(res, OP_EQ, 9);
 +  tt_mem_op(dst, OP_EQ, "Opa mundo", 9);
 +
 +  s = "SGVsbG8gd29ybGQ=";
 +  res = base64_decode(dst, 100, s, strlen(s));
 +  tt_int_op(res, OP_EQ, 11);
 +  tt_mem_op(dst, OP_EQ, "Hello world", 11);
 +
+   res = base64_decode(real_dst, 10, real_src, 10);
+   tt_int_op(res, OP_EQ, 7);
+   tt_mem_op(real_dst, OP_EQ, expected, 7);
   done:
    tor_free(src);
    tor_free(dst);
@@@ -209,19 -210,10 +228,23 @@@ test_util_format_base16_decode(void *ig
    res = base16_decode(dst, SIZE_T_CEILING+2, src, 10);
    tt_int_op(res, OP_EQ, -1);
  
 +  res = base16_decode(dst, 1000, "", 0);
 +  tt_int_op(res, OP_EQ, 0);
 +
 +  res = base16_decode(dst, 1000, "aabc", 4);
 +  tt_int_op(res, OP_EQ, 0);
 +  tt_mem_op(dst, OP_EQ, "\xaa\xbc", 2);
 +
 +  res = base16_decode(dst, 1000, "aabcd", 6);
 +  tt_int_op(res, OP_EQ, -1);
 +
 +  res = base16_decode(dst, 1000, "axxx", 4);
 +  tt_int_op(res, OP_EQ, -1);
 +
+   res = base16_decode(real_dst, 10, real_src, 14);
+   tt_int_op(res, OP_EQ, 0);
+   tt_mem_op(real_dst, OP_EQ, expected, 7);
   done:
    tor_free(src);
    tor_free(dst);