Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2014-07-31 23:14:56 +0400
committerEdward Thomson <ethomson@edwardthomson.com>2014-08-15 19:12:42 +0400
commite003f83a5840d6e9966f1830768771bcd205ba52 (patch)
tree0411bd285a838e252c8d2e7ace56778b2a2624a5 /tests/core/buffer.c
parent40867266bf964ed6acb2344e594e0c49106c3c67 (diff)
Introduce git_buf_decode_base64
Decode base64-encoded text into a git_buf
Diffstat (limited to 'tests/core/buffer.c')
-rw-r--r--tests/core/buffer.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/tests/core/buffer.c b/tests/core/buffer.c
index 8310deae1..7482dadbe 100644
--- a/tests/core/buffer.c
+++ b/tests/core/buffer.c
@@ -748,7 +748,7 @@ void test_core_buffer__unescape(void)
assert_unescape("", "");
}
-void test_core_buffer__base64(void)
+void test_core_buffer__encode_base64(void)
{
git_buf buf = GIT_BUF_INIT;
@@ -759,33 +759,54 @@ void test_core_buffer__base64(void)
* 0x 1d 06 21 29 1c 30
* d G h p c w
*/
- cl_git_pass(git_buf_put_base64(&buf, "this", 4));
+ cl_git_pass(git_buf_encode_base64(&buf, "this", 4));
cl_assert_equal_s("dGhpcw==", buf.ptr);
git_buf_clear(&buf);
- cl_git_pass(git_buf_put_base64(&buf, "this!", 5));
+ cl_git_pass(git_buf_encode_base64(&buf, "this!", 5));
cl_assert_equal_s("dGhpcyE=", buf.ptr);
git_buf_clear(&buf);
- cl_git_pass(git_buf_put_base64(&buf, "this!\n", 6));
+ cl_git_pass(git_buf_encode_base64(&buf, "this!\n", 6));
cl_assert_equal_s("dGhpcyEK", buf.ptr);
git_buf_free(&buf);
}
-void test_core_buffer__base85(void)
+void test_core_buffer__decode_base64(void)
{
git_buf buf = GIT_BUF_INIT;
- cl_git_pass(git_buf_put_base85(&buf, "this", 4));
+ cl_git_pass(git_buf_decode_base64(&buf, "dGhpcw==", 8));
+ cl_assert_equal_s("this", buf.ptr);
+
+ git_buf_clear(&buf);
+ cl_git_pass(git_buf_decode_base64(&buf, "dGhpcyE=", 8));
+ cl_assert_equal_s("this!", buf.ptr);
+
+ git_buf_clear(&buf);
+ cl_git_pass(git_buf_decode_base64(&buf, "dGhpcyEK", 8));
+ cl_assert_equal_s("this!\n", buf.ptr);
+
+ cl_git_fail(git_buf_decode_base64(&buf, "This is not a valid base64 string!!!", 36));
+ cl_assert_equal_s("this!\n", buf.ptr);
+
+ git_buf_free(&buf);
+}
+
+void test_core_buffer__encode_base85(void)
+{
+ git_buf buf = GIT_BUF_INIT;
+
+ cl_git_pass(git_buf_encode_base85(&buf, "this", 4));
cl_assert_equal_s("bZBXF", buf.ptr);
git_buf_clear(&buf);
- cl_git_pass(git_buf_put_base85(&buf, "two rnds", 8));
+ cl_git_pass(git_buf_encode_base85(&buf, "two rnds", 8));
cl_assert_equal_s("ba!tca&BaE", buf.ptr);
git_buf_clear(&buf);
- cl_git_pass(git_buf_put_base85(&buf, "this is base 85 encoded",
+ cl_git_pass(git_buf_encode_base85(&buf, "this is base 85 encoded",
strlen("this is base 85 encoded")));
cl_assert_equal_s("bZBXFAZc?TVqtS-AUHK3Wo~0{WMyOk", buf.ptr);
git_buf_clear(&buf);