blob: ce1981d53d1ed07da3997ad6ce61273714247314 [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 {
Casey Dahlin88924d62015-09-17 16:28:24 -070042public:
43void NormalMethod(int normalarg, float normal2);
44virtual void SubMethod(int subarg) const;
45}; // class TestClass
Casey Dahlin60a49162015-09-17 14:23:10 -070046
47class TestSubClass : public TestClass {
Casey Dahlin88924d62015-09-17 16:28:24 -070048public:
49virtual void SubMethod(int subarg) const;
50}; // class TestSubClass
Casey Dahlin34b86102015-09-16 16:03:06 -070051
Christopher Wileyf600a552015-09-12 14:07:44 -070052} // namespace test
Casey Dahlin34b86102015-09-16 16:03:06 -070053
Christopher Wileyf600a552015-09-12 14:07:44 -070054} // namespace android
55
56#endif // HEADER_INCLUDE_GUARD_H_)";
57
58} // namespace
59
60TEST(AstCppTests, GeneratesHeader) {
Casey Dahlin34b86102015-09-16 16:03:06 -070061 CppHeader cpp_header{"HEADER_INCLUDE_GUARD_H_",
62 {"string", "memory"},
63 new CppNamespace {"android", {
64 new CppNamespace {"test", {
Casey Dahlin60a49162015-09-17 14:23:10 -070065 new CppClassDeclaration { "TestClass", "",
Casey Dahlin88924d62015-09-17 16:28:24 -070066 {
67 new CppMethodDeclaration("void", "NormalMethod", { "int normalarg", "float normal2" }),
68 new CppMethodDeclaration("void", "SubMethod", { "int subarg" }, true, true)
69 },
Casey Dahlin60a49162015-09-17 14:23:10 -070070 {}
71 },
72 new CppClassDeclaration { "TestSubClass", "TestClass",
Casey Dahlin88924d62015-09-17 16:28:24 -070073 {
74 new CppMethodDeclaration("void", "SubMethod", { "int subarg" }, true, true)
75 },
Casey Dahlin60a49162015-09-17 14:23:10 -070076 {}
77 }
Casey Dahlin34b86102015-09-16 16:03:06 -070078 }}
79 }}
80 };
Christopher Wileyf600a552015-09-12 14:07:44 -070081 string actual_output;
82 CodeWriterPtr writer = get_string_writer(&actual_output);
83 cpp_header.Write(writer.get());
84 EXPECT_EQ(string(kExpectedHeaderOutput), actual_output);
85}
86
87} // namespace aidl
88} // namespace android