Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2810)

Unified Diff: build/android/gyp/util/md5_check_test.py

Issue 14263006: [Android] Refactor md5_check + add tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@java_toc
Patch Set: Rebase Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/gyp/util/md5_check.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/gyp/util/md5_check_test.py
diff --git a/build/android/gyp/util/md5_check_test.py b/build/android/gyp/util/md5_check_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..a18942e292585b0a12135abb00cc4cf6cdb7e409
--- /dev/null
+++ b/build/android/gyp/util/md5_check_test.py
@@ -0,0 +1,67 @@
+# Copyright 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import tempfile
+import unittest
+
+import md5_check
+
+
+class TestMd5Check(unittest.TestCase):
+ def testCallAndRecordIfStale(self):
+ input_strings = ['string1', 'string2']
+ input_file1 = tempfile.NamedTemporaryFile()
+ input_file2 = tempfile.NamedTemporaryFile()
+ file1_contents = 'input file 1'
+ file2_contents = 'input file 2'
+ input_file1.write(file1_contents)
+ input_file1.flush()
+ input_file2.write(file2_contents)
+ input_file2.flush()
+ input_files = [input_file1.name, input_file2.name]
+
+ record_path = tempfile.NamedTemporaryFile(suffix='.stamp')
+
+ def CheckCallAndRecord(should_call, message):
+ self.called = False
+ def MarkCalled():
+ self.called = True
+ md5_check.CallAndRecordIfStale(
+ MarkCalled,
+ record_path=record_path.name,
+ input_paths=input_files,
+ input_strings=input_strings)
+ self.failUnlessEqual(should_call, self.called, message)
+
+ CheckCallAndRecord(True, 'should call when record doesn\'t exist')
+ CheckCallAndRecord(False, 'should not call when nothing changed')
+
+ input_file1.write('some more input')
+ input_file1.flush()
+ CheckCallAndRecord(True, 'changed input file should trigger call')
+
+ input_files = input_files[::-1]
+ CheckCallAndRecord(False, 'reordering of inputs shouldn\'t trigger call')
+
+ input_files = input_files[:1]
+ CheckCallAndRecord(True, 'removing file should trigger call')
+
+ input_files.append(input_file2.name)
+ CheckCallAndRecord(True, 'added input file should trigger call')
+
+ input_strings[0] = input_strings[0] + ' a bit longer'
+ CheckCallAndRecord(True, 'changed input string should trigger call')
+
+ input_strings = input_strings[::-1]
+ CheckCallAndRecord(True, 'reordering of string inputs should trigger call')
+
+ input_strings = input_strings[:1]
+ CheckCallAndRecord(True, 'removing a string should trigger call')
+
+ input_strings.append('a brand new string')
+ CheckCallAndRecord(True, 'added input string should trigger call')
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « build/android/gyp/util/md5_check.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698