• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 // Utilities for accessing test data.
18 
19 #ifndef LIBTEXTCLASSIFIER_UTILS_TEST_DATA_TEST_UTILS_H_
20 #define LIBTEXTCLASSIFIER_UTILS_TEST_DATA_TEST_UTILS_H_
21 #include <fstream>
22 
23 #include "gtest/gtest.h"
24 
25 namespace libtextclassifier3 {
26 
27 // Get the file path to the test data.
GetTestDataPath(const std::string & relative_path)28 inline std::string GetTestDataPath(const std::string& relative_path) {
29   return "/data/local/tmp/" + relative_path;
30 }
31 
GetTestFileContent(const std::string & relative_path)32 inline std::string GetTestFileContent(const std::string& relative_path) {
33   const std::string full_path = GetTestDataPath(relative_path);
34   std::ifstream file_stream(full_path);
35   return std::string(std::istreambuf_iterator<char>(file_stream), {});
36 }
37 
38 }  // namespace  libtextclassifier3
39 
40 #endif  // LIBTEXTCLASSIFIER_UTILS_TEST_DATA_TEST_UTILS_H_
41