TensorFlow Serving C++ API Documentation
test_util.cc
1 /* Copyright 2016 Google Inc. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7  http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #include "tensorflow_serving/test_util/test_util.h"
17 
18 #include <string>
19 
20 #include "tensorflow/core/lib/io/path.h"
21 #include "tensorflow/core/platform/env.h"
22 #include "tensorflow/core/platform/test.h"
23 #include "tsl/platform/protobuf.h"
24 
25 namespace tensorflow {
26 namespace serving {
27 namespace test_util {
28 
29 string TensorflowTestSrcDirPath(const string& relative_path) {
30  const string base_path = tensorflow::io::JoinPath( //
31  getenv("TEST_SRCDIR"), //
32  "tf_serving/external/org_tensorflow/tensorflow/");
33  return tensorflow::io::JoinPath(base_path, relative_path);
34 }
35 
36 string TestSrcDirPath(const string& relative_path) {
37  const string base_path = tensorflow::io::JoinPath(
38  getenv("TEST_SRCDIR"), "tf_serving/tensorflow_serving");
39  return tensorflow::io::JoinPath(base_path, relative_path);
40 }
41 
42 ProtoStringMatcher::ProtoStringMatcher(const string& expected)
43  : expected_(expected) {}
44 ProtoStringMatcher::ProtoStringMatcher(const google::protobuf::Message& expected)
45  : expected_([&]() -> std::string {
46  std::string result;
47  tsl::protobuf::TextFormat::PrintToString(expected, &result);
48  return result;
49  }()) {}
50 
51 } // namespace test_util
52 } // namespace serving
53 } // namespace tensorflow