-
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
Merged
jeanlf
merged 21 commits into
gpac:master
from
soheibthriber:buildbot-embedded-unittests
May 6, 2024
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
0e8a49a
add minimal unit tests framework
rbouqueau 82b2f01
add some flavoured assert:
09c81e1
wip: add cmocka wrappers
soheibthriber a783c17
test limit conditions of gf_sys_word_match():
soheibthriber b88f4dc
cleanup
rbouqueau 67dbc41
UTs: introduce crashing test due to wrong API
rbouqueau 7decbad
UT: add test on static fonction
rbouqueau 5549b0c
UTs: improve result readability
rbouqueau a6d9f72
UTs: automatically detect failing tests
rbouqueau eb30bf3
UTs: operate on a separate build
rbouqueau 977cce3
UTs: fix out-of-tree build
rbouqueau f447cdf
UTs: rename README -> README.md
rbouqueau 6fe74ce
UTs: simplify floavoured asserts - thanks @touatily
rbouqueau 027deb3
cleanup
rbouqueau 9b7368e
UTs: more cross-platform
rbouqueau a7d736d
UTs: fatal by default made explicit (and desactivable)
rbouqueau 672f666
UTs: add GF_STATIC in configuration.h (for Win32 only - excluding mob…
rbouqueau a8e7ddb
UTs: 'cd' before 'find' otherwise it finds all the c files! - thanks …
rbouqueau b792bf2
UTs: fix fct signature
rbouqueau ddc0882
UTs: fatal error should not call assert to be able to display the rep…
rbouqueau 0e41abc
fix build when relying on static configurations
rbouqueau File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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,32 @@ | ||
#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 |
||
static Bool fatal_ut = GF_TRUE; | ||
|
||
#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++; \ | ||
if (fatal_ut) checks_failed|=0x8000000; \ | ||
} \ | ||
} while (0) | ||
|
||
#define assert_false(expr) assert_true(!(expr)) | ||
#define assert_equal_str(str1, str2) assert_true(!strcmp((str1), (str2))) | ||
#define assert_not_equal_str(str1, str2) assert_true(strcmp((str1), (str2))) | ||
#define assert_equal(a, b) assert_true((a) == (b)) | ||
#define assert_greater(a, b) assert_true((a) > (b)) | ||
#define assert_greater_equal(a, b) assert_true((a) >= (b)) | ||
#define assert_less(a, b) assert_true((a) < (b)) | ||
#define assert_less_equal(a, b) assert_true((a) <= (b)) | ||
#define assert_not_null(ptr) assert_true((ptr) != NULL) |
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,58 @@ | ||
#include <gpac/main.h> | ||
#include "tests.h" | ||
|
||
unittest(gf_sys_word_match) | ||
{ | ||
// 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); | ||
} |
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,7 @@ | ||
#include "tests.h" | ||
|
||
char *xml_translate_xml_string(char *str); | ||
unittest(xml_translate_xml_string) | ||
{ | ||
assert_equal_str(xml_translate_xml_string("&"), "&"); | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?