3 * Copyright 2016 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <gtest/gtest.h>
24 #include "absl/flags/flag.h"
25 #include "test/core/util/test_config.h"
26 #include "test/cpp/util/test_config.h"
29 std::string, generated_file_path, "",
30 "path to the directory containing generated files compiler_test.grpc.pb.h "
31 "and compiler_test_mock.grpc.pb.h");
33 const char kGoldenFilePath[] = "test/cpp/codegen/compiler_test_golden";
34 const char kMockGoldenFilePath[] = "test/cpp/codegen/compiler_test_mock_golden";
36 void run_test(const std::basic_string<char>& generated_file,
37 const std::basic_string<char>& golden_file) {
38 std::ifstream generated(generated_file);
39 std::ifstream golden(golden_file);
41 ASSERT_TRUE(generated.good());
42 ASSERT_TRUE(golden.good());
44 std::ostringstream gen_oss;
45 std::ostringstream gold_oss;
46 gen_oss << generated.rdbuf();
47 gold_oss << golden.rdbuf();
48 EXPECT_EQ(gold_oss.str(), gen_oss.str());
54 TEST(GoldenFileTest, TestGeneratedFile) {
55 run_test(absl::GetFlag(FLAGS_generated_file_path) + "compiler_test.grpc.pb.h",
59 TEST(GoldenMockFileTest, TestGeneratedMockFile) {
61 absl::GetFlag(FLAGS_generated_file_path) + "compiler_test_mock.grpc.pb.h",
65 int main(int argc, char** argv) {
66 grpc::testing::TestEnvironment env(argc, argv);
67 ::testing::InitGoogleTest(&argc, argv);
68 grpc::testing::InitTest(&argc, &argv, true);
69 if (absl::GetFlag(FLAGS_generated_file_path).empty()) {
70 absl::SetFlag(&FLAGS_generated_file_path, "gens/src/proto/grpc/testing/");
72 if (absl::GetFlag(FLAGS_generated_file_path).back() != '/') {
73 absl::SetFlag(&FLAGS_generated_file_path,
74 absl::GetFlag(FLAGS_generated_file_path).append("/"));
76 return RUN_ALL_TESTS();