-
Notifications
You must be signed in to change notification settings - Fork 511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Buildbot embedded unittests #2755
Changes from 11 commits
0e8a49a
82b2f01
09c81e1
a783c17
b88f4dc
67dbc41
7decbad
5549b0c
a6d9f72
eb30bf3
977cce3
f447cdf
6fe74ce
027deb3
9b7368e
a7d736d
672f666
a8e7ddb
b792bf2
ddc0882
0e41abc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,60 @@ | ||||||||||||||||||||||||
#pragma once | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
#include <gpac/setup.h> | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
#define unittest(suffix) void test_##suffix(void) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
extern int checks_passed; | ||||||||||||||||||||||||
extern int checks_failed; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
static Bool verbose_ut = GF_FALSE; | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there a way to set this to true via compile flags / configure? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do. What option do you envision? At the moment we just have |
||||||||||||||||||||||||
|
||||||||||||||||||||||||
// provide some flavoured asserts | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
#define custom_message_assert(expr, msg) \ | ||||||||||||||||||||||||
do { \ | ||||||||||||||||||||||||
if (expr) { \ | ||||||||||||||||||||||||
checks_passed++; \ | ||||||||||||||||||||||||
} else { \ | ||||||||||||||||||||||||
checks_failed++; \ | ||||||||||||||||||||||||
} \ | ||||||||||||||||||||||||
((expr) \ | ||||||||||||||||||||||||
? gf_fatal_assert(0) \ | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we assert(0) is the expr is true here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. outdated comment |
||||||||||||||||||||||||
: printf("Assertion failed: %s\nMessage: %s\n\tFile: %s\nLine: %d\nFunction: %s\n", #expr, msg, __FILE__, __LINE__, __ASSERT_FUNCTION)); \ | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In both scenarios, an assertion failure occurs. Within the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I propose to remove all the elements in that section that are unused. @soheibthriber Let me know if you disagree. |
||||||||||||||||||||||||
} while (0) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
#define custom_action_assert(expr, action) \ | ||||||||||||||||||||||||
do { \ | ||||||||||||||||||||||||
if (expr) { \ | ||||||||||||||||||||||||
checks_passed++; \ | ||||||||||||||||||||||||
} else { \ | ||||||||||||||||||||||||
checks_failed++; \ | ||||||||||||||||||||||||
} \ | ||||||||||||||||||||||||
((expr) \ | ||||||||||||||||||||||||
? gf_fatal_assert(0) \ | ||||||||||||||||||||||||
: (action, gf_fatal_assert(0))); \ | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. in both cases, |
||||||||||||||||||||||||
} while (0) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
#define assert_true(expr) \ | ||||||||||||||||||||||||
do { \ | ||||||||||||||||||||||||
if (expr) { \ | ||||||||||||||||||||||||
if (verbose_ut) printf("Assertion passed: \"%s\", File: \"%s\", Line: %d, Function: \"%s\"\n", #expr, __FILE__, __LINE__, __ASSERT_FUNCTION); \ | ||||||||||||||||||||||||
checks_passed++; \ | ||||||||||||||||||||||||
} else { \ | ||||||||||||||||||||||||
checks_failed++; \ | ||||||||||||||||||||||||
gf_assert(0); \ | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason for alternating between There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No but using similar names is confusing, for sure :/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. currently if a test fails the whole testing is aborted because of the assert:
and you don't get the summary with the number of tests passed/failed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's right, it is a design choice. Usually unit tests are executed at every build. So this is kind of some incremental approach. However we could add the option for failure to be non-fatal. Adding this in a7d736d. |
||||||||||||||||||||||||
} \ | ||||||||||||||||||||||||
} while (0) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
#define assert_false(expr) assert_true(!(expr)) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Other macros could be added. Here are some suggestions:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like them.
|
||||||||||||||||||||||||
#define assert_equal_str(str1, str2) \ | ||||||||||||||||||||||||
do { \ | ||||||||||||||||||||||||
if (!strcmp(str1, str2)) { \ | ||||||||||||||||||||||||
if (verbose_ut) printf("Assertion passed: Value: (%s, %s), File: %s, Line: %d, Function: %s\n", #str1, #str2, __FILE__, __LINE__, __ASSERT_FUNCTION); \ | ||||||||||||||||||||||||
checks_passed++; \ | ||||||||||||||||||||||||
} else { \ | ||||||||||||||||||||||||
checks_failed++; \ | ||||||||||||||||||||||||
gf_assert(0); \ | ||||||||||||||||||||||||
} \ | ||||||||||||||||||||||||
} while (0) | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be rewritten as follows?
Suggested change
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#include <gpac/main.h> | ||
#include "tests.h" | ||
|
||
unittest(gf_sys_word_match) | ||
{ | ||
// gf_assert(gf_sys_word_match("toto", "toto") == GF_TRUE); //TODO: provide more assert flavors | ||
// verbose_assert(gf_sys_word_match("toto", "toto") == GF_TRUE); | ||
// custom_message_assert(gf_sys_word_match("toto", "toto") == GF_TRUE, "toto must match"); | ||
// custom_action_assert( gf_sys_word_match("toto", "tot") == GF_TRUE , printf("Assertion failed: toto has lost an o \n")); | ||
|
||
// Test exact match scenario | ||
assert_true(gf_sys_word_match("abc", "abc")); | ||
|
||
// Test short orig, longer dst scenario | ||
assert_true(gf_sys_word_match("abc", "abcd")); | ||
|
||
// Test short dst, longer orig scenario | ||
assert_true(gf_sys_word_match("abcd", "abc")); | ||
|
||
// Test scenario with ':' in orig but not in dst | ||
assert_false(gf_sys_word_match("a:b:c", "xyz")); | ||
|
||
// Test scenario with ':' in dst but not in orig | ||
assert_false(gf_sys_word_match("abc", "x:y:z")); | ||
|
||
// Test strnistr match scenario | ||
assert_true(gf_sys_word_match("abc", "xabcz")); | ||
|
||
// Test repeated characters scenario | ||
assert_false(gf_sys_word_match("aabbc", "axayabaz")); | ||
|
||
// Test match*2 < olen scenario | ||
assert_false(gf_sys_word_match("abc", "xyz")); | ||
|
||
// Test half characters in order scenario | ||
assert_true(gf_sys_word_match("abcd", "aebfcd")); | ||
|
||
// Test null pointer | ||
assert_true(gf_sys_word_match(NULL, NULL)); | ||
assert_false(gf_sys_word_match("abc", NULL)); | ||
assert_false(gf_sys_word_match(NULL, "abc")); | ||
|
||
// Test empty string | ||
assert_true(gf_sys_word_match("", "")); | ||
assert_false(gf_sys_word_match("abc", "")); | ||
assert_false(gf_sys_word_match("", "abc")); | ||
|
||
// Test a very long string | ||
const char *longString = "a very long string that exceeds the normal limit of the function, it may go further and further until it can break the behaviour of the function apparently not easy so lets write more and more"; | ||
assert_true(gf_sys_word_match(longString, longString)); | ||
assert_false(gf_sys_word_match("abc", longString)); | ||
assert_false(gf_sys_word_match(longString, "abc")); | ||
|
||
// Test a non-ASCII buffer | ||
const char *nonAsciiBuffer = "\x01\x02\x03\xFF\xFE\xFD"; | ||
assert_false(gf_sys_word_match("abc", nonAsciiBuffer)); | ||
assert_false(gf_sys_word_match(nonAsciiBuffer, "abc")); | ||
assert_true(gf_sys_word_match(nonAsciiBuffer, nonAsciiBuffer)); | ||
|
||
// Test non-string: will crash because this exported function doesn't provide a str max len argument | ||
char str[3] = {'a', 'b', 'c'}; | ||
//DISABLED: gf_sys_word_match("abc", str); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "tests.h" | ||
|
||
char *xml_translate_xml_string(char *str); | ||
unittest(xml_translate_xml_string) | ||
{ | ||
assert_equal_str(xml_translate_xml_string("&"), "&"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should also be defined in configuration.h (or setup.h?) for platforms that don't use configure/config.h ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in 672f666. Should we also add a target in the msvc Solution ? xcode ? What's the usual way to add this?