• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "base/strings/utf_string_conversions.h"
22 #include "gtest-utils.h"
23 
24 #if defined(OS_WIN)
GetTargetDirectory()25 std::wstring GetTargetDirectory() {
26   base::FilePath path;
27   base::PathService::Get(base::DIR_CURRENT, &path);
28   return base::UTF8ToWide(path.MaybeAsASCII());
29 }
30 #else
GetTargetDirectory()31 std::string GetTargetDirectory() {
32 #if defined(ANDROID)
33   return "/sdcard";
34 #else
35   base::FilePath path;
36   base::PathService::Get(base::DIR_CURRENT, &path);
37   return path.MaybeAsASCII();
38 #endif
39 }
40 #endif
41 
GetTestFilePath(base::FilePath * path,const std::string filename)42 void GetTestFilePath(base::FilePath* path, const std::string filename) {
43   ASSERT_TRUE(base::PathService::Get(base::DIR_SOURCE_ROOT, path));
44   *path = path->AppendASCII("third_party");
45   *path = path->AppendASCII("libjpeg_turbo");
46   *path = path->AppendASCII("testimages");
47   *path = path->AppendASCII(filename);
48   ASSERT_TRUE(base::PathExists(*path));
49 }
50 
CompareFileAndMD5(const base::FilePath & path,const std::string expected_md5)51 bool CompareFileAndMD5(const base::FilePath& path,
52                        const std::string expected_md5) {
53   // Read the output file and compute the MD5.
54   std::string output;
55   if (!base::ReadFileToString(path, &output)) {
56     return false;
57   }
58   const std::string md5 = base::MD5String(output);
59   return expected_md5 == md5;
60 }
61