| Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015, 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 | #include <string> |
| 18 | |
| 19 | #include <gtest/gtest.h> |
| 20 | |
| 21 | #include "ast_cpp.h" |
| 22 | #include "code_writer.h" |
| 23 | |
| 24 | using std::string; |
| 25 | |
| 26 | namespace android { |
| 27 | namespace aidl { |
| 28 | namespace { |
| 29 | |
| 30 | const char kExpectedHeaderOutput[] = |
| 31 | R"(#ifndef HEADER_INCLUDE_GUARD_H_ |
| 32 | #define HEADER_INCLUDE_GUARD_H_ |
| 33 | |
| 34 | #include <string> |
| 35 | #include <memory> |
| 36 | |
| 37 | namespace android { |
| Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame^] | 38 | |
| Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 39 | namespace test { |
| 40 | |
| Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame^] | 41 | |
| Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 42 | } // namespace test |
| Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame^] | 43 | |
| Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 44 | } // namespace android |
| 45 | |
| 46 | #endif // HEADER_INCLUDE_GUARD_H_)"; |
| 47 | |
| 48 | } // namespace |
| 49 | |
| 50 | TEST(AstCppTests, GeneratesHeader) { |
| Casey Dahlin | 34b8610 | 2015-09-16 16:03:06 -0700 | [diff] [blame^] | 51 | CppHeader cpp_header{"HEADER_INCLUDE_GUARD_H_", |
| 52 | {"string", "memory"}, |
| 53 | new CppNamespace {"android", { |
| 54 | new CppNamespace {"test", { |
| 55 | }} |
| 56 | }} |
| 57 | }; |
| Christopher Wiley | f600a55 | 2015-09-12 14:07:44 -0700 | [diff] [blame] | 58 | string actual_output; |
| 59 | CodeWriterPtr writer = get_string_writer(&actual_output); |
| 60 | cpp_header.Write(writer.get()); |
| 61 | EXPECT_EQ(string(kExpectedHeaderOutput), actual_output); |
| 62 | } |
| 63 | |
| 64 | } // namespace aidl |
| 65 | } // namespace android |