Skip to content

Commit

Permalink
Finally merged Oliviers-OSS-patchs_oc_5.
Browse files Browse the repository at this point in the history
Added tests for the functionality added in the branch.

Resolved conflicts.

Merging pull request.
  • Loading branch information
atomgalaxy committed Oct 22, 2017
2 parents 5b63e77 + 3822aca commit dd046ee
Show file tree
Hide file tree
Showing 5 changed files with 234 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ guide.pdf
guide.html
parsetab.py
TEST-cxxtest.xml
TestGpp_*
TestClang_*
TestGppPy_*
*.dSYM
TestCpp_*
64 changes: 64 additions & 0 deletions cxxtest/TestSuite.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,70 @@ struct differs
}
};

template<>
struct differs<const char*, const char*>
{
static bool test(const char *x, const char *y)
{
if ((x != 0) && (y != 0))
{
return (CXXTEST_STD(strcmp(x, y)) != 0);
}
else
{
return (x != y);
}
}
};

template<>
struct differs<char*, char*>
{
static bool test(char *x, char *y)
{
if ((x != 0) && (y != 0))
{
return (CXXTEST_STD(strcmp(x, y)) != 0);
}
else
{
return (x != y);
}
}
};

template<>
struct differs<const char*, char*>
{
static bool test(const char *x, char *y)
{
if ((x != 0) && (y != 0))
{
return (CXXTEST_STD(strcmp(x, y)) != 0);
}
else
{
return (x != y);
}
}
};

template<>
struct differs<char*, const char*>
{
static bool test(char *x, const char *y)
{
if ((x != 0) && (y != 0))
{
return (CXXTEST_STD(strcmp(x, y)) != 0);
}
else
{
return (x != y);
}
}
};

template<class X, class Y>
void doAssertDiffers(const char *file, int line,
const char *xExpr, X x,
Expand Down
112 changes: 112 additions & 0 deletions test/CharAssertions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#include <cxxtest/TestSuite.h>

//
// A test for issue 122/123, where TS_ASSERT_EQUALS and TS_ASSERT_DIFFERS were
// both true at the same time.
//

// not const on purpose
static char non_const_value_1[] = { "toto" };
static char non_const_value_2[] = { "toto" }; // different pointers from value1
static char non_const_value_3[] = { "nekobus" };
class CharAssertions : public CxxTest::TestSuite {
public:
template <typename T1, typename T2> void differs_must_succeed_generator()
{
T1 str1 = non_const_value_1;
T2 str2 = non_const_value_3;
TS_ASSERT_DIFFERS(str1, str2);
}
template <typename T1, typename T2> void differs_must_fail_generator()
{
T1 str1 = non_const_value_1;
T2 str2 = non_const_value_2;
TS_ASSERT_DIFFERS(str1, str2);
}
template <typename T1, typename T2> void equals_must_succeed_generator()
{
T1 str1 = non_const_value_1;
T2 str2 = non_const_value_2;
TS_ASSERT_EQUALS(str1, str2);
}
template <typename T1, typename T2> void equals_must_fail_generator()
{
T1 str1 = non_const_value_1;
T2 str2 = non_const_value_3;
TS_ASSERT_EQUALS(str1, str2);
}

// we must test the entire matrix
// naming scheme is test_[de][sf][cm][cm], where:
// - d or e are for 'differs' and 'equals'
// - s or f are for 'expect to succeed' or 'expect to fail'
// - c or m are for 'const' or 'mutable' chars.
void test_dscc()
{
differs_must_succeed_generator<char const* const, char const* const>();
}
void test_dscm()
{
differs_must_succeed_generator<char const* const, char const*>();
}
void test_dsmc()
{
differs_must_succeed_generator<char const*, char const* const>();
}
void test_dsmm()
{
differs_must_succeed_generator<char const*, char const*>();
}

void test_dfcc()
{
differs_must_fail_generator<char const* const, char const* const>();
}
void test_dfcm()
{
differs_must_fail_generator<char const* const, char const*>();
}
void test_dfmc()
{
differs_must_fail_generator<char const*, char const* const>();
}
void test_dfmm()
{
differs_must_fail_generator<char const*, char const*>();
}


void test_escc()
{
equals_must_succeed_generator<char const* const, char const* const>();
}
void test_escm()
{
equals_must_succeed_generator<char const* const, char const*>();
}
void test_esmc()
{
equals_must_succeed_generator<char const*, char const* const>();
}
void test_esmm()
{
equals_must_succeed_generator<char const*, char const*>();
}

void test_efcc()
{
equals_must_fail_generator<char const* const, char const* const>();
}
void test_efcm()
{
equals_must_fail_generator<char const* const, char const*>();
}
void test_efmc()
{
equals_must_fail_generator<char const*, char const* const>();
}
void test_efmm()
{
equals_must_fail_generator<char const*, char const*>();
}
};
21 changes: 21 additions & 0 deletions test/char_assertions.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Running cxxtest tests (16 tests)....
In CharAssertions::test_dfcc:
CharAssertions.h:24: Error: Expected (str1 != str2), found (toto)
In CharAssertions::test_dfcm:
CharAssertions.h:24: Error: Expected (str1 != str2), found (toto)
In CharAssertions::test_dfmc:
CharAssertions.h:24: Error: Expected (str1 != str2), found (toto)
In CharAssertions::test_dfmm:
CharAssertions.h:24: Error: Expected (str1 != str2), found (toto)
....
In CharAssertions::test_efcc:
CharAssertions.h:36: Error: Expected (str1 == str2), found (toto != nekobus)
In CharAssertions::test_efcm:
CharAssertions.h:36: Error: Expected (str1 == str2), found (toto != nekobus)
In CharAssertions::test_efmc:
CharAssertions.h:36: Error: Expected (str1 == str2), found (toto != nekobus)
In CharAssertions::test_efmm:
CharAssertions.h:36: Error: Expected (str1 == str2), found (toto != nekobus)
Failed 8 and Skipped 0 of 16 tests
Success rate: 50%
Error level = 8
48 changes: 32 additions & 16 deletions test/test_cxxtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ def file_diff(filename1, filename2, filtered_reader):
fromfile=filename2, tofile=filename1))
if diff:
make_diff_readable(diff)
raise Exception("ERROR: \n\n%s\n\n%s\n\n" % (lines1, lines2))
raise Exception("ERROR: \n\n%s\n\n%s\n\n" %
('\n'.join(lines1), '\n'.join(lines2)))
diff = '\n'.join(diff)
return diff

Expand Down Expand Up @@ -475,11 +476,18 @@ def test_max_dump_size(self):
"""Max dump size"""
self.compile(prefix='max_dump_size', args="--error-printer --include=MaxDump.h DynamicMax.h SameData.h", output='max.out')

def test_char_assertions(self):
"""char* assertions"""
self.compile(prefix='char_assertions',
args='--error-printer CharAssertions.h',
output='char_assertions.out')

def test_wide_char(self):
"""Wide char"""
self.check_if_supported('wchar.cpp', "The file wchar.cpp is not supported.")
self.compile(prefix='wide_char', args="--error-printer WideCharTest.h", output="wchar.out")


#def test_factor(self):
#"""Factor"""
#self.compile(prefix='factor', args="--error-printer --factor Factor.h", output="factor.out")
Expand Down Expand Up @@ -710,23 +718,31 @@ def test_bad1(self):

def test_normal_sympath(self):
"""Normal Behavior - symbolic path"""
_files = " ".join(["LessThanEquals.h","Relation.h","DefaultTraits.h","DoubleCall.h","SameData.h","SameFiles.h","Tsm.h","TraitsTest.h","MockTest.h","SameZero.h"])
files = ["LessThanEquals.h","Relation.h","DefaultTraits.h",
"DoubleCall.h","SameData.h","SameFiles.h","Tsm.h",
"TraitsTest.h","MockTest.h","SameZero.h"]

sympath_name = 'test_sympath'
sympath_dir = '../%s' % (sympath_name,)
prefix = 'normal_sympath'

_files = " ".join(files)
self.init(prefix=prefix)
try:
os.remove('test_sympath')
except:
pass
try:
shutil.rmtree('../test_sympath')
except:
pass
os.mkdir('../test_sympath')
os.symlink('../test_sympath', 'test_sympath')
self.py_cpp = 'test_sympath/'+prefix+'_py.cpp'
self.compile(prefix=prefix, init=False, args="--error-printer "+_files, output="normal.out")
os.remove('test_sympath')
shutil.rmtree('../test_sympath')
# need to ignore very specific errors here
if os.path.islink(sympath_name):
os.remove(sympath_name)
if os.path.isdir(sympath_dir):
shutil.rmtree(sympath_dir)
if not os.path.exists('../.git'):
raise ValueError("Wrong local directory, run from the tests folder.")
os.mkdir(sympath_dir)
os.symlink(sympath_dir, sympath_name)
self.py_cpp = 'test_sympath/%s_py.cpp' % (prefix,)
self.compile(prefix=prefix, init=False, args="--error-printer "+_files,
output="normal.out")
os.remove(sympath_name)
shutil.rmtree(sympath_dir)


def test_normal_relpath(self):
"""Normal Behavior - relative path"""
Expand Down

0 comments on commit dd046ee

Please sign in to comment.