diff options
author | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-11-18 22:45:56 +0100 |
---|---|---|
committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2011-11-18 22:45:56 +0100 |
commit | bdd31dd5e832126b2f22fccbe244a1106c241ab0 (patch) | |
tree | b08a2ad0fad57131563aa8c071221bea241128c1 /tests-clay/object/raw/chars.c | |
parent | 277b7efe493887081ce1dafd91199d0ee9f676c9 (diff) | |
parent | e4c93a392763a006d11e1c1dd01c12f85498dad5 (diff) | |
download | libgit2-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/chars.c')
-rw-r--r-- | tests-clay/object/raw/chars.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests-clay/object/raw/chars.c b/tests-clay/object/raw/chars.c new file mode 100644 index 000000000..eba352b40 --- /dev/null +++ b/tests-clay/object/raw/chars.c @@ -0,0 +1,52 @@ + +#include "clay_libgit2.h" + +#include "odb.h" + +static int from_hex(unsigned int i) +{ + if (i >= '0' && i <= '9') + return i - '0'; + if (i >= 'a' && i <= 'f') + return 10 + (i - 'a'); + if (i >= 'A' && i <= 'F') + return 10 + (i - 'A'); + return -1; +} + +void test_object_raw_chars__find_invalid_chars_in_oid(void) +{ + git_oid out; + unsigned char exp[] = { + 0x16, 0xa6, 0x77, 0x70, 0xb7, + 0xd8, 0xd7, 0x23, 0x17, 0xc4, + 0xb7, 0x75, 0x21, 0x3c, 0x23, + 0xa8, 0xbd, 0x74, 0xf5, 0xe0, + }; + char in[41] = "16a67770b7d8d72317c4b775213c23a8bd74f5e0"; + unsigned int i; + + for (i = 0; i < 256; i++) { + in[38] = (char)i; + if (from_hex(i) >= 0) { + exp[19] = (unsigned char)(from_hex(i) << 4); + cl_git_pass(git_oid_fromstr(&out, in)); + cl_assert(memcmp(out.id, exp, sizeof(out.id)) == 0); + } else { + cl_git_fail(git_oid_fromstr(&out, in)); + } + } +} + +void test_object_raw_chars__build_valid_oid_from_raw_bytes(void) +{ + git_oid out; + unsigned char exp[] = { + 0x16, 0xa6, 0x77, 0x70, 0xb7, + 0xd8, 0xd7, 0x23, 0x17, 0xc4, + 0xb7, 0x75, 0x21, 0x3c, 0x23, + 0xa8, 0xbd, 0x74, 0xf5, 0xe0, + }; + git_oid_fromraw(&out, exp); + cl_git_pass(memcmp(out.id, exp, sizeof(out.id))); +} |