Unit test fails both tests but works with same input directly.
by jmgibson1981 from LinuxQuestions.org on (#6DNXG)
Code:void test_string_field_search() {
char buffer[TEST_BUFFER];
buffer_initialize(buffer);
int tests = 0;
int t1 = 0;
int t2 = 0;
bool test = false;
strncat(buffer, "how many cats does it take?", TEST_BUFFER - 1);
char * strtest = string_field_search(buffer, " ", 3);
if (string_is_valid(strtest, "does")) {
t1++;
tests++;
}
free(strtest);
strtest = NULL;
strtest = string_field_search(buffer, " ", 1);
if (string_is_valid(strtest, "many")) {
t2++;
tests++;
}
if (tests == 2) {
test = true;
}
free(strtest);
strtest = NULL;
snprintf(buffer, TEST_BUFFER - 1,
"string_search_field - %d, %d", t1, t2);
test_func_return(buffer, test);
}https://gitlab.com/jmgibson1981/mylibraries (couldn't remember if link in sig)
The problem is that my test case above fails both tries. But if I call the actual function directly it works with the same input data every single time. A bit lost on why this is. For what it's worth the file_search_func also calls this function. It passes its test cases. But this one by itself is failing and I can't figure why. It was working on Linux. But on Windows it fails out. No error, of any kind. Just my unit-test.txt log file shows that both tests failed on this function.
Any suggestions or ideas?
*EDIT* Forgot to mention, Codeblocks with MingW. So Gcc I think.
char buffer[TEST_BUFFER];
buffer_initialize(buffer);
int tests = 0;
int t1 = 0;
int t2 = 0;
bool test = false;
strncat(buffer, "how many cats does it take?", TEST_BUFFER - 1);
char * strtest = string_field_search(buffer, " ", 3);
if (string_is_valid(strtest, "does")) {
t1++;
tests++;
}
free(strtest);
strtest = NULL;
strtest = string_field_search(buffer, " ", 1);
if (string_is_valid(strtest, "many")) {
t2++;
tests++;
}
if (tests == 2) {
test = true;
}
free(strtest);
strtest = NULL;
snprintf(buffer, TEST_BUFFER - 1,
"string_search_field - %d, %d", t1, t2);
test_func_return(buffer, test);
}https://gitlab.com/jmgibson1981/mylibraries (couldn't remember if link in sig)
The problem is that my test case above fails both tries. But if I call the actual function directly it works with the same input data every single time. A bit lost on why this is. For what it's worth the file_search_func also calls this function. It passes its test cases. But this one by itself is failing and I can't figure why. It was working on Linux. But on Windows it fails out. No error, of any kind. Just my unit-test.txt log file shows that both tests failed on this function.
Any suggestions or ideas?
*EDIT* Forgot to mention, Codeblocks with MingW. So Gcc I think.