[Winmerge-svn] SF.net SVN: winmerge: [4181] trunk/Testing/CppUnit
Windows visual diff and merge for files and directories
Brought to you by:
christianlist,
grimmdp
From: <ga...@us...> - 2007-03-21 13:08:58
|
Revision: 4181 http://svn.sourceforge.net/winmerge/?rev=4181&view=rev Author: galh Date: 2007-03-21 06:08:53 -0700 (Wed, 21 Mar 2007) Log Message: ----------- Added more test case to stringdiff (line coloring feature). Modified Paths: -------------- trunk/Testing/CppUnit/Changes.txt trunk/Testing/CppUnit/StringDifferencing/StringDifferencing.dsp trunk/Testing/CppUnit/StringDifferencing/TestCase1.cpp Added Paths: ----------- trunk/Testing/CppUnit/StringDifferencing/DiffColoring.cpp trunk/Testing/CppUnit/StringDifferencing/DiffColoring.h Modified: trunk/Testing/CppUnit/Changes.txt =================================================================== --- trunk/Testing/CppUnit/Changes.txt 2007-03-20 22:43:45 UTC (rev 4180) +++ trunk/Testing/CppUnit/Changes.txt 2007-03-21 13:08:53 UTC (rev 4181) @@ -1,5 +1,13 @@ Testing\selftest\Changes.txt +2007-03-21 Gal + Fix TestCase1::Difference2 test. + StringDifferencing: TestCase1.cpp + + Add more test case to stringdiff (line coloring feature). + StringDifferencing: StringDifferencing.dsp + StringDifferencing new files: DiffColoring.cpp DiffColoring.h + 2006-11-22 Kimmo Add more case difference tests to stringdiffs StringDifferencing: StringDifferencing.dsp Added: trunk/Testing/CppUnit/StringDifferencing/DiffColoring.cpp =================================================================== --- trunk/Testing/CppUnit/StringDifferencing/DiffColoring.cpp (rev 0) +++ trunk/Testing/CppUnit/StringDifferencing/DiffColoring.cpp 2007-03-21 13:08:53 UTC (rev 4181) @@ -0,0 +1,179 @@ +/** +* @file DiffColoring.cpp +* +* @brief Implementation of DiffColoring test cases. +*/ + +#include <cppunit/config/SourcePrefix.h> +#include "StdAfx.h" + +#include "CompareOptions.h" +#include "stringdiffs.h" + +#include "DiffColoring.h" + +CPPUNIT_TEST_SUITE_REGISTRATION( DiffColoring ); + +bool operator==(const wdiff& rdf, const wdiff& ldf) +{ + return ((rdf.start[0] == ldf.start[0]) && + (rdf.end[0] == ldf.end[0]) && + (rdf.start[1] == ldf.start[1]) && + (rdf.start[1] == ldf.start[1])); +} + +/** @brief Testcase initialization code. */ +void DiffColoring::setUp() +{ + // Add possible initializations here +} + +/** @brief Testcase cleanup code. */ +void DiffColoring::tearDown() +{ + // Add possible cleanups here +} + +/** +* @brief Test a single word difference. +*/ +void DiffColoring::OneWord() +{ + wdiffarray diffs; + CString string1(_T("Left")); + CString string2(_T("Right")); + int count = 0; + + // Compare case, all white spaces, whitespace break + sd_ComputeWordDiffs(string1, string2, + true, WHITESPACE_COMPARE_ALL, 0, false, + &diffs); + count = diffs.GetSize(); + CPPUNIT_ASSERT(count == 1); + CPPUNIT_ASSERT(diffs[0] == wdiff(0, 3, 0, 3)); +} + +/** +* @brief Test a multi words difference. +*/ +void DiffColoring::OneDiff() +{ + wdiffarray diffs; + CString string1(_T("This is the first line")); + CString string2(_T("This is not a cow")); + int count = 0; + + // Compare case, all white spaces, whitespace break + sd_ComputeWordDiffs(string1, string2, + true, WHITESPACE_COMPARE_ALL, 0, false, + &diffs); + count = diffs.GetSize(); + CPPUNIT_ASSERT(count == 1); + CPPUNIT_ASSERT(diffs[0] == wdiff(8, 21, 8, 16)); +} + +/** +* @brief Test a different string length difference. +*/ +void DiffColoring::DifferentLength() +{ + wdiffarray diffs; + CString string1(_T("First line to check")); + CString string2(_T("Second line")); + int count = 0; + + // Compare case, all white spaces, whitespace break + sd_ComputeWordDiffs(string1, string2, + true, WHITESPACE_COMPARE_ALL, 0, false, + &diffs); + count = diffs.GetSize(); + CPPUNIT_ASSERT(count == 2); + CPPUNIT_ASSERT(diffs[0] == wdiff(0, 4, 0, 5)); + CPPUNIT_ASSERT(diffs[1] == wdiff(11, 18, 11, 10)); +} + +/** +* @brief Test a string against an empty string difference. +*/ +void DiffColoring::DiffWithEmpty() +{ + wdiffarray diffs; + CString string1(_T("First line to check")); + CString string2(_T("")); + int count = 0; + + // Compare case, all white spaces, whitespace break + sd_ComputeWordDiffs(string1, string2, + true, WHITESPACE_COMPARE_ALL, 0, false, + &diffs); + count = diffs.GetSize(); + CPPUNIT_ASSERT(count == 1); + CPPUNIT_ASSERT(diffs[0] == wdiff(0, 18, 0, -1)); +} + +/** +* @brief Bug #1491334: Thinly highlighted position is wrong. +*/ +void DiffColoring::Bug1491334() +{ + wdiffarray diffs; + CString string1(_T("00 52 C8 52")); + CString string2(_T("00 00 00 52")); + int count = 0; + + // Compare case, all white spaces, whitespace break + sd_ComputeWordDiffs(string1, string2, + true, WHITESPACE_COMPARE_ALL, 0, false, + &diffs); + count = diffs.GetSize(); + CPPUNIT_ASSERT(count == 1); + CPPUNIT_ASSERT(diffs[0] == wdiff(3, 7, 3, 7)); +} + +/** +* @brief Bug #1639453: Imaginary difference highlighted in character level mode. +*/ +void DiffColoring::Bug1639453() +{ + wdiffarray diffs; + CString string1(_T("[12, 34]")); + CString string2(_T("[12, 34, 56]")); + int count = 0; + + // Compare case, all white spaces, whitespace break + punctuation, char level + sd_ComputeWordDiffs(string1, string2, + true, WHITESPACE_COMPARE_ALL, 1, true, + &diffs); + count = diffs.GetSize(); + CPPUNIT_ASSERT(count == 1); + CPPUNIT_ASSERT(diffs[0] == wdiff(7, 7, 7, 11)); +} + +/** +* @brief Bug #1683061: Bug in highlighting. +*/ +void DiffColoring::Bug1683061() +{ + wdiffarray diffs; + CString string1(_T("ABC")); + CString string2(_T("ABCD")); + int count = 0; + + // Compare case, all white spaces, whitespace break + sd_ComputeWordDiffs(string1, string2, + true, WHITESPACE_COMPARE_ALL, 0, false, + &diffs); + count = diffs.GetSize(); + CPPUNIT_ASSERT(count == 1); + CPPUNIT_ASSERT(diffs[0] == wdiff(0, 2, 0, 3)); + + // Compare case, all white spaces, whitespace break + punctuation + diffs.RemoveAll(); + sd_ComputeWordDiffs(string1, string2, + true, WHITESPACE_COMPARE_ALL, 0, true, + &diffs); + count = diffs.GetSize(); + CPPUNIT_ASSERT(count == 1); + CPPUNIT_ASSERT(diffs[0] == wdiff(3, 2, 3, 3)); +} + Added: trunk/Testing/CppUnit/StringDifferencing/DiffColoring.h =================================================================== --- trunk/Testing/CppUnit/StringDifferencing/DiffColoring.h (rev 0) +++ trunk/Testing/CppUnit/StringDifferencing/DiffColoring.h 2007-03-21 13:08:53 UTC (rev 4181) @@ -0,0 +1,46 @@ +/** +* @file DiffColoring.h +* +* @brief Declaration of DiffColoring test cases. +* +* This class doesn't check if the current number of differences found. It check +* the differences positions. Wrong difference positions cause bugs in the line +* coloring feature. +* +*/ + +#ifndef _DIFF_COLORING_H_INCLUDED_ +#define _DIFF_COLORING_H_INCLUDED_ + +#include <cppunit/extensions/HelperMacros.h> + +/** +* @brief Test cases for the line coloring feature. +*/ +class DiffColoring : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE( DiffColoring ); + CPPUNIT_TEST( OneWord ); + CPPUNIT_TEST( OneDiff ); + CPPUNIT_TEST( DifferentLength ); + CPPUNIT_TEST( DiffWithEmpty ); + CPPUNIT_TEST( Bug1491334 ); + CPPUNIT_TEST( Bug1639453 ); + CPPUNIT_TEST( Bug1683061 ); + CPPUNIT_TEST_SUITE_END(); + +public: + void setUp(); + void tearDown(); + +protected: + void OneWord(); + void OneDiff(); + void DifferentLength(); + void DiffWithEmpty(); + void Bug1491334(); + void Bug1639453(); + void Bug1683061(); +}; + +#endif // _DIFF_COLORING_H_INCLUDED_ Modified: trunk/Testing/CppUnit/StringDifferencing/StringDifferencing.dsp =================================================================== --- trunk/Testing/CppUnit/StringDifferencing/StringDifferencing.dsp 2007-03-20 22:43:45 UTC (rev 4180) +++ trunk/Testing/CppUnit/StringDifferencing/StringDifferencing.dsp 2007-03-21 13:08:53 UTC (rev 4181) @@ -133,6 +133,14 @@ # End Source File # Begin Source File +SOURCE=.\DiffColoring.cpp +# End Source File +# Begin Source File + +SOURCE=.\DiffColoring.h +# End Source File +# Begin Source File + SOURCE=.\DifferentStrings1.cpp # End Source File # Begin Source File Modified: trunk/Testing/CppUnit/StringDifferencing/TestCase1.cpp =================================================================== --- trunk/Testing/CppUnit/StringDifferencing/TestCase1.cpp 2007-03-20 22:43:45 UTC (rev 4180) +++ trunk/Testing/CppUnit/StringDifferencing/TestCase1.cpp 2007-03-21 13:08:53 UTC (rev 4181) @@ -134,13 +134,14 @@ count = diffs.GetSize(); CPPUNIT_ASSERT(count == 0); - // This fails? Why? - // Shouldn't it it find two differences? But it founds only one? + // Expect to find one differences since difference starts from the first + // non-matching word and ends in the predecessor of the first matching + // word. diffs.RemoveAll(); sd_ComputeWordDiffs(string1, string2, true, WHITESPACE_COMPARE_ALL, 0, false, &diffs); count = diffs.GetSize(); - CPPUNIT_ASSERT(count == 2); + CPPUNIT_ASSERT(count == 1); diffs.RemoveAll(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |