blob: 9cb8a7a193fbbd1064e02d7221088a64dd7517da [file] [log] [blame]
Christopher Wileyf600a552015-09-12 14:07:44 -07001/*
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
24using std::string;
25
26namespace android {
27namespace aidl {
28namespace {
29
30const char kExpectedHeaderOutput[] =
31R"(#ifndef HEADER_INCLUDE_GUARD_H_
32#define HEADER_INCLUDE_GUARD_H_
33
34#include <string>
35#include <memory>
36
37namespace android {
Casey Dahlin34b86102015-09-16 16:03:06 -070038
Christopher Wileyf600a552015-09-12 14:07:44 -070039namespace test {
40
Casey Dahlin60a49162015-09-17 14:23:10 -070041class TestClass {
42
43
44} // class TestClass
45
46class TestSubClass : public TestClass {
47
48
49} // class TestSubClass
Casey Dahlin34b86102015-09-16 16:03:06 -070050
Christopher Wileyf600a552015-09-12 14:07:44 -070051} // namespace test
Casey Dahlin34b86102015-09-16 16:03:06 -070052
Christopher Wileyf600a552015-09-12 14:07:44 -070053} // namespace android
54
55#endif // HEADER_INCLUDE_GUARD_H_)";
56
57} // namespace
58
59TEST(AstCppTests, GeneratesHeader) {
Casey Dahlin34b86102015-09-16 16:03:06 -070060 CppHeader cpp_header{"HEADER_INCLUDE_GUARD_H_",
61 {"string", "memory"},
62 new CppNamespace {"android", {
63 new CppNamespace {"test", {
Casey Dahlin60a49162015-09-17 14:23:10 -070064 new CppClassDeclaration { "TestClass", "",
65 {},
66 {}
67 },
68 new CppClassDeclaration { "TestSubClass", "TestClass",
69 {},
70 {}
71 }
Casey Dahlin34b86102015-09-16 16:03:06 -070072 }}
73 }}
74 };
Christopher Wileyf600a552015-09-12 14:07:44 -070075 string actual_output;
76 CodeWriterPtr writer = get_string_writer(&actual_output);
77 cpp_header.Write(writer.get());
78 EXPECT_EQ(string(kExpectedHeaderOutput), actual_output);
79}
80
81} // namespace aidl
82} // namespace android