forked from git/git
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test-strcmp-offset: created test for strcmp_offset
Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
- Loading branch information
1 parent
46cf396
commit 718f869
Showing
4 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "cache.h" | ||
|
||
struct test_data { | ||
const char *s1; | ||
const char *s2; | ||
int first_change; | ||
}; | ||
|
||
static struct test_data data[] = { | ||
{ "abc", "abc", 0 }, | ||
{ "abc", "def", 0 }, | ||
|
||
{ "abc", "abz", 2 }, | ||
|
||
{ "abc", "abcdef", 3 }, | ||
|
||
{ "abc\xF0zzz", "abc\xFFzzz", 3 }, | ||
|
||
{ NULL, NULL, 0 } | ||
}; | ||
|
||
int try_pair(const char *sa, const char *sb, int first_change) | ||
{ | ||
int failed = 0; | ||
int offset, r_exp, r_tst; | ||
|
||
r_exp = strcmp(sa, sb); | ||
r_tst = strcmp_offset(sa, sb, &offset); | ||
if (r_tst != r_exp) { | ||
if ((r_tst < 0 && r_exp < 0) || (r_tst > 0 && r_exp > 0)) | ||
warning("'%s' vs '%s', imprecise result: %d != %d", | ||
sa, sb, r_exp, r_tst); | ||
else { | ||
error("'%s' vs '%s', result expect %d, observed %d", | ||
sa, sb, r_exp, r_tst); | ||
failed = 1; | ||
} | ||
} | ||
if (offset != first_change) { | ||
error("'%s' vs '%s', offset expect %d, observed %d", | ||
sa, sb, first_change, offset); | ||
failed = 1; | ||
} | ||
|
||
return failed; | ||
} | ||
|
||
int cmd_main(int argc, const char **argv) | ||
{ | ||
int failed = 0; | ||
int k; | ||
|
||
for (k=0; data[k].s1; k++) { | ||
failed += try_pair(data[k].s1, data[k].s2, data[k].first_change); | ||
failed += try_pair(data[k].s2, data[k].s1, data[k].first_change); | ||
} | ||
|
||
return failed; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/bin/sh | ||
|
||
test_description='Test strcmp_offset functionality' | ||
|
||
. ./test-lib.sh | ||
|
||
test_expect_success run_helper ' | ||
test-strcmp-offset | ||
' | ||
|
||
test_done |