summaryrefslogtreecommitdiff
path: root/tests-clay/object/raw/convert.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <carlos@cmartin.tk>2011-11-18 22:45:56 +0100
committerCarlos Martín Nieto <carlos@cmartin.tk>2011-11-18 22:45:56 +0100
commitbdd31dd5e832126b2f22fccbe244a1106c241ab0 (patch)
treeb08a2ad0fad57131563aa8c071221bea241128c1 /tests-clay/object/raw/convert.c
parent277b7efe493887081ce1dafd91199d0ee9f676c9 (diff)
parente4c93a392763a006d11e1c1dd01c12f85498dad5 (diff)
downloadlibgit2-error-handling.tar.gz
Merge branch 'development' into error-handlingerror-handling
The code in this branch has been modified so it works with the global state introduced in development.
Diffstat (limited to 'tests-clay/object/raw/convert.c')
-rw-r--r--tests-clay/object/raw/convert.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/tests-clay/object/raw/convert.c b/tests-clay/object/raw/convert.c
new file mode 100644
index 000000000..f69f5f924
--- /dev/null
+++ b/tests-clay/object/raw/convert.c
@@ -0,0 +1,75 @@
+
+#include "clay_libgit2.h"
+
+#include "odb.h"
+
+void test_object_raw_convert__succeed_on_oid_to_string_conversion(void)
+{
+ const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0";
+ git_oid in;
+ char out[GIT_OID_HEXSZ + 1];
+ char *str;
+ int i;
+
+ cl_git_pass(git_oid_fromstr(&in, exp));
+
+ /* NULL buffer pointer, returns static empty string */
+ str = git_oid_to_string(NULL, sizeof(out), &in);
+ cl_assert(str && *str == '\0' && str != out);
+
+ /* zero buffer size, returns static empty string */
+ str = git_oid_to_string(out, 0, &in);
+ cl_assert(str && *str == '\0' && str != out);
+
+ /* NULL oid pointer, returns static empty string */
+ str = git_oid_to_string(out, sizeof(out), NULL);
+ cl_assert(str && *str == '\0' && str != out);
+
+ /* n == 1, returns out as an empty string */
+ str = git_oid_to_string(out, 1, &in);
+ cl_assert(str && *str == '\0' && str == out);
+
+ for (i = 1; i < GIT_OID_HEXSZ; i++) {
+ out[i+1] = 'Z';
+ str = git_oid_to_string(out, i+1, &in);
+ /* returns out containing c-string */
+ cl_assert(str && str == out);
+ /* must be '\0' terminated */
+ cl_assert(*(str+i) == '\0');
+ /* must not touch bytes past end of string */
+ cl_assert(*(str+(i+1)) == 'Z');
+ /* i == n-1 charaters of string */
+ cl_git_pass(strncmp(exp, out, i));
+ }
+
+ /* returns out as hex formatted c-string */
+ str = git_oid_to_string(out, sizeof(out), &in);
+ cl_assert(str && str == out && *(str+GIT_OID_HEXSZ) == '\0');
+ cl_assert(strcmp(exp, out) == 0);
+}
+
+void test_object_raw_convert__succeed_on_oid_to_string_conversion_big(void)
+{
+ const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0";
+ git_oid in;
+ char big[GIT_OID_HEXSZ + 1 + 3]; /* note + 4 => big buffer */
+ char *str;
+
+ cl_git_pass(git_oid_fromstr(&in, exp));
+
+ /* place some tail material */
+ big[GIT_OID_HEXSZ+0] = 'W'; /* should be '\0' afterwards */
+ big[GIT_OID_HEXSZ+1] = 'X'; /* should remain untouched */
+ big[GIT_OID_HEXSZ+2] = 'Y'; /* ditto */
+ big[GIT_OID_HEXSZ+3] = 'Z'; /* ditto */
+
+ /* returns big as hex formatted c-string */
+ str = git_oid_to_string(big, sizeof(big), &in);
+ cl_assert(str && str == big && *(str+GIT_OID_HEXSZ) == '\0');
+ cl_assert(strcmp(exp, big) == 0);
+
+ /* check tail material is untouched */
+ cl_assert(str && str == big && *(str+GIT_OID_HEXSZ+1) == 'X');
+ cl_assert(str && str == big && *(str+GIT_OID_HEXSZ+2) == 'Y');
+ cl_assert(str && str == big && *(str+GIT_OID_HEXSZ+3) == 'Z');
+}