golden_file_test.cc
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2016 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 #include <fstream>
20 #include <sstream>
21 
22 #include <gtest/gtest.h>
23 
24 #include "absl/flags/flag.h"
25 
28 
29 ABSL_FLAG(
30  std::string, generated_file_path, "",
31  "path to the directory containing generated files compiler_test.grpc.pb.h "
32  "and compiler_test_mock.grpc.pb.h");
33 
34 const char kGoldenFilePath[] = "test/cpp/codegen/compiler_test_golden";
35 const char kMockGoldenFilePath[] = "test/cpp/codegen/compiler_test_mock_golden";
36 
37 void run_test(const std::basic_string<char>& generated_file,
38  const std::basic_string<char>& golden_file) {
39  std::ifstream generated(generated_file);
40  std::ifstream golden(golden_file);
41 
42  ASSERT_TRUE(generated.good());
43  ASSERT_TRUE(golden.good());
44 
45  std::ostringstream gen_oss;
46  std::ostringstream gold_oss;
47  gen_oss << generated.rdbuf();
48  gold_oss << golden.rdbuf();
49  EXPECT_EQ(gold_oss.str(), gen_oss.str());
50 
51  generated.close();
52  golden.close();
53 }
54 
55 TEST(GoldenFileTest, TestGeneratedFile) {
56  run_test(absl::GetFlag(FLAGS_generated_file_path) + "compiler_test.grpc.pb.h",
58 }
59 
60 TEST(GoldenMockFileTest, TestGeneratedMockFile) {
61  run_test(
62  absl::GetFlag(FLAGS_generated_file_path) + "compiler_test_mock.grpc.pb.h",
64 }
65 
66 int main(int argc, char** argv) {
68  ::testing::InitGoogleTest(&argc, argv);
69  grpc::testing::InitTest(&argc, &argv, true);
70  if (absl::GetFlag(FLAGS_generated_file_path).empty()) {
71  absl::SetFlag(&FLAGS_generated_file_path, "gens/src/proto/grpc/testing/");
72  }
73  if (absl::GetFlag(FLAGS_generated_file_path).back() != '/') {
74  absl::SetFlag(&FLAGS_generated_file_path,
75  absl::GetFlag(FLAGS_generated_file_path).append("/"));
76  }
77  return RUN_ALL_TESTS();
78 }
TEST
TEST(GoldenFileTest, TestGeneratedFile)
Definition: golden_file_test.cc:55
grpc::testing::InitTest
void InitTest(int *argc, char ***argv, bool remove_flags)
Definition: test_config_cc.cc:28
absl::SetFlag
void SetFlag(absl::Flag< T > *flag, const T &v)
Definition: abseil-cpp/absl/flags/flag.h:110
generate.env
env
Definition: generate.py:37
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
ABSL_FLAG
ABSL_FLAG(std::string, generated_file_path, "", "path to the directory containing generated files compiler_test.grpc.pb.h " "and compiler_test_mock.grpc.pb.h")
kGoldenFilePath
const char kGoldenFilePath[]
Definition: golden_file_test.cc:34
EXPECT_EQ
#define EXPECT_EQ(a, b)
Definition: iomgr/time_averaged_stats_test.cc:27
absl::GetFlag
ABSL_MUST_USE_RESULT T GetFlag(const absl::Flag< T > &flag)
Definition: abseil-cpp/absl/flags/flag.h:98
RUN_ALL_TESTS
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:2471
google_benchmark.example.empty
def empty(state)
Definition: example.py:31
test_config.h
testing::InitGoogleTest
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: bloaty/third_party/googletest/googletest/src/gtest.cc:6106
kMockGoldenFilePath
const char kMockGoldenFilePath[]
Definition: golden_file_test.cc:35
main
int main(int argc, char **argv)
Definition: golden_file_test.cc:66
grpc::testing::TestEnvironment
Definition: test/core/util/test_config.h:54
ASSERT_TRUE
#define ASSERT_TRUE(condition)
Definition: bloaty/third_party/googletest/googletest/include/gtest/gtest.h:1973
test_config.h
run_test
void run_test(const std::basic_string< char > &generated_file, const std::basic_string< char > &golden_file)
Definition: golden_file_test.cc:37
gmock_output_test.golden_file
golden_file
Definition: bloaty/third_party/googletest/googlemock/test/gmock_output_test.py:176


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:39