1 /*
2  * Copyright 2020 The Chromium Authors. All Rights Reserved.
3  *
4  * This software is provided 'as-is', without any express or implied
5  * warranty.  In no event will the authors be held liable for any damages
6  * arising from the use of this software.
7  *
8  * Permission is granted to anyone to use this software for any purpose,
9  * including commercial applications, and to alter it and redistribute it
10  * freely, subject to the following restrictions:
11  *
12  * 1. The origin of this software must not be misrepresented; you must not
13  *    claim that you wrote the original software. If you use this software
14  *    in a product, an acknowledgment in the product documentation would be
15  *    appreciated but is not required.
16  * 2. Altered source versions must be plainly marked as such, and must not be
17  *    misrepresented as being the original software.
18  * 3. This notice may not be removed or altered from any source distribution.
19  */
20 
21 #ifndef THIRD_PARTY_LIBJPEG_TURBO_GTEST_UTILS_H_
22 #define THIRD_PARTY_LIBJPEG_TURBO_GTEST_UTILS_H_
23 
24 #include "base/files/file.h"
25 #include "base/files/file_util.h"
26 #include "base/hash/md5.h"
27 #include "base/path_service.h"
28 #include "gtest-utils.h"
29 
30 #include <gtest/gtest.h>
31 #include <string>
32 
33 // Returns the absolute path of the test output directory as a string.
34 // On Android this path is /sdcard; on all other platforms it is the current
35 // directory.
36 #if defined(OS_WIN)
37 std::wstring GetTargetDirectory();
38 #else
39 std::string GetTargetDirectory();
40 #endif
41 
42 // Files used as input for libjpeg-turbo unit tests are stored in
43 // <chromium>/src/third_party/libjpeg_turbo/testimages.
44 // Given a test file |filename|, this function will set |path| to
45 // <chromium>/src/third_party/libjpeg_turbo/testimages/filename
46 // If the file does not exit an assertion will fail.
47 void GetTestFilePath(base::FilePath* path,
48                      const std::string filename);
49 
50 // Returns true if the MD5 sum of the file at the given |path| matches that of
51 // the |expected_md5|, false otherwise.
52 bool CompareFileAndMD5(const base::FilePath& path,
53                        const std::string expected_md5);
54 
55 #endif // THIRD_PARTY_LIBJPEG_TURBO_GTEST_UTILS_H_
56