1 /* 2 * Copyright 2008 Google Inc. All Rights Reserved. 3 * Author: fraser@google.com (Neil Fraser) 4 * Author: mikeslemmer@gmail.com (Mike Slemmer) 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * Diff Match and Patch -- Test Harness 19 * http://code.google.com/p/google-diff-match-patch/ 20 */ 21 22 #ifndef DIFF_MATCH_PATCH_TEST_H 23 #define DIFF_MATCH_PATCH_TEST_H 24 25 class diff_match_patch_test { 26 public: 27 diff_match_patch_test(); 28 void run_all_tests(); 29 30 // DIFF TEST FUNCTIONS 31 void testDiffCommonPrefix(); 32 void testDiffCommonSuffix(); 33 void testDiffHalfmatch(); 34 void testDiffLinesToChars(); 35 void testDiffCharsToLines(); 36 void testDiffCleanupMerge(); 37 void testDiffCleanupSemanticLossless(); 38 void testDiffCleanupSemantic(); 39 void testDiffCleanupEfficiency(); 40 void testDiffPrettyHtml(); 41 void testDiffText(); 42 void testDiffDelta(); 43 void testDiffXIndex(); 44 void testDiffLevenshtein(); 45 void testDiffPath(); 46 void testDiffMain(); 47 48 // MATCH TEST FUNCTIONS 49 void testMatchAlphabet(); 50 void testMatchBitap(); 51 void testMatchMain(); 52 53 // PATCH TEST FUNCTIONS 54 void testPatchObj(); 55 void testPatchFromText(); 56 void testPatchToText(); 57 void testPatchAddContext(); 58 void testPatchMake(); 59 void testPatchSplitMax(); 60 void testPatchAddPadding(); 61 void testPatchApply(); 62 63 private: 64 diff_match_patch dmp; 65 66 // Define equality. 67 void assertEquals(const QString &strCase, int n1, int n2); 68 void assertEquals(const QString &strCase, const QString &s1, const QString &s2); 69 void assertEquals(const QString &strCase, const Diff &d1, const Diff &d2); 70 void assertEquals(const QString &strCase, const QList<Diff> &list1, const QList<Diff> &list2); 71 void assertEquals(const QString &strCase, const QList<QVariant> &list1, const QList<QVariant> &list2); 72 void assertEquals(const QString &strCase, const QVariant &var1, const QVariant &var2); 73 void assertEquals(const QString &strCase, const QMap<QChar, int> &m1, const QMap<QChar, int> &m2); 74 void assertEquals(const QString &strCase, const QStringList &list1, const QStringList &list2); 75 void assertTrue(const QString &strCase, bool value); 76 void assertFalse(const QString &strCase, bool value); 77 void assertNull(const QString &strCase, const QStringList &list); 78 void assertNull(const QString &strCase, const QList<Diff> &list); 79 80 // Construct the two texts which made up the diff originally. 81 QStringList diff_rebuildtexts(QList<Diff> diffs); 82 // Private function for quickly building lists of diffs. 83 QList<Diff> diffList( 84 Diff d1 = Diff(EQUAL, NULL), Diff d2 = Diff(EQUAL, NULL), 85 Diff d3 = Diff(EQUAL, NULL), Diff d4 = Diff(EQUAL, NULL), 86 Diff d5 = Diff(EQUAL, NULL), Diff d6 = Diff(EQUAL, NULL), 87 Diff d7 = Diff(EQUAL, NULL), Diff d8 = Diff(EQUAL, NULL), 88 Diff d9 = Diff(EQUAL, NULL), Diff d10 = Diff(EQUAL, NULL)); 89 }; 90 91 #endif // DIFF_MATCH_PATCH_TEST_H 92